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

perf scripting python: Add auxtrace error

Add auxtrace_error 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-10-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
2ede9217 0db21340

+57
+13
tools/perf/builtin-script.c
··· 2432 2432 sample->tid); 2433 2433 } 2434 2434 2435 + static int process_auxtrace_error(struct perf_session *session, 2436 + union perf_event *event) 2437 + { 2438 + if (scripting_ops && scripting_ops->process_auxtrace_error) { 2439 + scripting_ops->process_auxtrace_error(session, event); 2440 + return 0; 2441 + } 2442 + 2443 + return perf_event__process_auxtrace_error(session, event); 2444 + } 2445 + 2435 2446 static int 2436 2447 process_lost_event(struct perf_tool *tool, 2437 2448 union perf_event *event, ··· 2582 2571 } 2583 2572 if (script->show_switch_events || (scripting_ops && scripting_ops->process_switch)) 2584 2573 script->tool.context_switch = process_switch_event; 2574 + if (scripting_ops && scripting_ops->process_auxtrace_error) 2575 + script->tool.auxtrace_error = process_auxtrace_error; 2585 2576 if (script->show_namespace_events) 2586 2577 script->tool.namespaces = process_namespaces_event; 2587 2578 if (script->show_cgroup_events)
+42
tools/perf/util/scripting-engines/trace-event-python.c
··· 1014 1014 #endif 1015 1015 } 1016 1016 1017 + static int tuple_set_u32(PyObject *t, unsigned int pos, u32 val) 1018 + { 1019 + return PyTuple_SetItem(t, pos, PyLong_FromUnsignedLong(val)); 1020 + } 1021 + 1017 1022 static int tuple_set_s32(PyObject *t, unsigned int pos, s32 val) 1018 1023 { 1019 1024 return PyTuple_SetItem(t, pos, _PyLong_FromLong(val)); ··· 1464 1459 db_export__switch(&tables->dbe, event, sample, machine); 1465 1460 else 1466 1461 python_do_process_switch(event, sample, machine); 1462 + } 1463 + 1464 + static void python_process_auxtrace_error(struct perf_session *session __maybe_unused, 1465 + union perf_event *event) 1466 + { 1467 + struct perf_record_auxtrace_error *e = &event->auxtrace_error; 1468 + u8 cpumode = e->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; 1469 + const char *handler_name = "auxtrace_error"; 1470 + unsigned long long tm = e->time; 1471 + const char *msg = e->msg; 1472 + PyObject *handler, *t; 1473 + 1474 + handler = get_handler(handler_name); 1475 + if (!handler) 1476 + return; 1477 + 1478 + if (!e->fmt) { 1479 + tm = 0; 1480 + msg = (const char *)&e->time; 1481 + } 1482 + 1483 + t = tuple_new(9); 1484 + 1485 + tuple_set_u32(t, 0, e->type); 1486 + tuple_set_u32(t, 1, e->code); 1487 + tuple_set_s32(t, 2, e->cpu); 1488 + tuple_set_s32(t, 3, e->pid); 1489 + tuple_set_s32(t, 4, e->tid); 1490 + tuple_set_u64(t, 5, e->ip); 1491 + tuple_set_u64(t, 6, tm); 1492 + tuple_set_string(t, 7, msg); 1493 + tuple_set_u32(t, 8, cpumode); 1494 + 1495 + call_object(handler, t, handler_name); 1496 + 1497 + Py_DECREF(t); 1467 1498 } 1468 1499 1469 1500 static void get_handler_name(char *str, size_t size, ··· 2040 1999 .stop_script = python_stop_script, 2041 2000 .process_event = python_process_event, 2042 2001 .process_switch = python_process_switch, 2002 + .process_auxtrace_error = python_process_auxtrace_error, 2043 2003 .process_stat = python_process_stat, 2044 2004 .process_stat_interval = python_process_stat_interval, 2045 2005 .generate_script = python_generate_script,
+2
tools/perf/util/trace-event.h
··· 83 83 void (*process_switch)(union perf_event *event, 84 84 struct perf_sample *sample, 85 85 struct machine *machine); 86 + void (*process_auxtrace_error)(struct perf_session *session, 87 + union perf_event *event); 86 88 void (*process_stat)(struct perf_stat_config *config, 87 89 struct evsel *evsel, u64 tstamp); 88 90 void (*process_stat_interval)(u64 tstamp);