Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf scripting python: Add context switch

Add context_switch to general python scripting.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: https://lore.kernel.org/r/20210525095112.1399-9-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Adrian Hunter and committed by
Arnaldo Carvalho de Melo
0db21340 22cc2f74

+45
+45
tools/perf/util/scripting-engines/trace-event-python.c
··· 1019 1019 return PyTuple_SetItem(t, pos, _PyLong_FromLong(val)); 1020 1020 } 1021 1021 1022 + static int tuple_set_bool(PyObject *t, unsigned int pos, bool val) 1023 + { 1024 + return PyTuple_SetItem(t, pos, PyBool_FromLong(val)); 1025 + } 1026 + 1022 1027 static int tuple_set_string(PyObject *t, unsigned int pos, const char *s) 1023 1028 { 1024 1029 return PyTuple_SetItem(t, pos, _PyUnicode_FromString(s)); ··· 1411 1406 } 1412 1407 } 1413 1408 1409 + static void python_do_process_switch(union perf_event *event, 1410 + struct perf_sample *sample, 1411 + struct machine *machine) 1412 + { 1413 + const char *handler_name = "context_switch"; 1414 + bool out = event->header.misc & PERF_RECORD_MISC_SWITCH_OUT; 1415 + bool out_preempt = out && (event->header.misc & PERF_RECORD_MISC_SWITCH_OUT_PREEMPT); 1416 + pid_t np_pid = -1, np_tid = -1; 1417 + PyObject *handler, *t; 1418 + 1419 + handler = get_handler(handler_name); 1420 + if (!handler) 1421 + return; 1422 + 1423 + if (event->header.type == PERF_RECORD_SWITCH_CPU_WIDE) { 1424 + np_pid = event->context_switch.next_prev_pid; 1425 + np_tid = event->context_switch.next_prev_tid; 1426 + } 1427 + 1428 + t = tuple_new(9); 1429 + if (!t) 1430 + return; 1431 + 1432 + tuple_set_u64(t, 0, sample->time); 1433 + tuple_set_s32(t, 1, sample->cpu); 1434 + tuple_set_s32(t, 2, sample->pid); 1435 + tuple_set_s32(t, 3, sample->tid); 1436 + tuple_set_s32(t, 4, np_pid); 1437 + tuple_set_s32(t, 5, np_tid); 1438 + tuple_set_s32(t, 6, machine->pid); 1439 + tuple_set_bool(t, 7, out); 1440 + tuple_set_bool(t, 8, out_preempt); 1441 + 1442 + call_object(handler, t, handler_name); 1443 + 1444 + Py_DECREF(t); 1445 + } 1446 + 1414 1447 static void python_process_switch(union perf_event *event, 1415 1448 struct perf_sample *sample, 1416 1449 struct machine *machine) ··· 1457 1414 1458 1415 if (tables->db_export_mode) 1459 1416 db_export__switch(&tables->dbe, event, sample, machine); 1417 + else 1418 + python_do_process_switch(event, sample, machine); 1460 1419 } 1461 1420 1462 1421 static void get_handler_name(char *str, size_t size,