tools: perf: Expose sample ID / stream ID to python scripts
authorBen Gainey <ben.gainey@arm.com>
Tue, 23 Jan 2024 10:31:37 +0000 (10:31 +0000)
committerNamhyung Kim <namhyung@kernel.org>
Sat, 3 Feb 2024 02:05:40 +0000 (18:05 -0800)
perf script exposes the evsel_name to python scripts as part of the data
passed to the sample or tracepoint handler function, and it passes the id and
stream_id to the throttled/unthrottled handler functions. This makes matching
throttle events and samples difficult.

To make this possible, this change exposes the sample id and stream_id values
to the script.

Signed-off-by: Ben Gainey <ben.gainey@arm.com>
Reviewed-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: will@kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Link: https://lore.kernel.org/r/20240123103137.1890779-2-ben.gainey@arm.com
tools/perf/Documentation/perf-script-python.txt
tools/perf/util/scripting-engines/trace-event-python.c

index 6a8581012e1620f6fb709b83bcf5307c6b43588f..13e37e9385ee421fe89427420932f8f1f6d61d3f 100644 (file)
@@ -642,8 +642,8 @@ SUPPORTED FIELDS
 
 Currently supported fields:
 
-ev_name, comm, pid, tid, cpu, ip, time, period, phys_addr, addr,
-symbol, symoff, dso, time_enabled, time_running, values, callchain,
+ev_name, comm, id, stream_id, pid, tid, cpu, ip, time, period, phys_addr,
+addr, symbol, symoff, dso, time_enabled, time_running, values, callchain,
 brstack, brstacksym, datasrc, datasrc_decode, iregs, uregs,
 weight, transaction, raw_buf, attr, cpumode.
 
index 860e1837ba9693eb437a9ae68d762f5a89cf1d2d..b4f0f60e60a63f34b04464543e36cab71eac3ec5 100644 (file)
@@ -858,6 +858,10 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample,
        pydict_set_item_string_decref(dict, "ev_name", _PyUnicode_FromString(evsel__name(evsel)));
        pydict_set_item_string_decref(dict, "attr", _PyBytes_FromStringAndSize((const char *)&evsel->core.attr, sizeof(evsel->core.attr)));
 
+       pydict_set_item_string_decref(dict_sample, "id",
+                       PyLong_FromUnsignedLongLong(sample->id));
+       pydict_set_item_string_decref(dict_sample, "stream_id",
+                       PyLong_FromUnsignedLongLong(sample->stream_id));
        pydict_set_item_string_decref(dict_sample, "pid",
                        _PyLong_FromLong(sample->pid));
        pydict_set_item_string_decref(dict_sample, "tid",
@@ -1306,7 +1310,7 @@ static void python_export_sample_table(struct db_export *dbe,
        struct tables *tables = container_of(dbe, struct tables, dbe);
        PyObject *t;
 
-       t = tuple_new(25);
+       t = tuple_new(27);
 
        tuple_set_d64(t, 0, es->db_id);
        tuple_set_d64(t, 1, es->evsel->db_id);
@@ -1333,6 +1337,8 @@ static void python_export_sample_table(struct db_export *dbe,
        tuple_set_d64(t, 22, es->sample->insn_cnt);
        tuple_set_d64(t, 23, es->sample->cyc_cnt);
        tuple_set_s32(t, 24, es->sample->flags);
+       tuple_set_d64(t, 25, es->sample->id);
+       tuple_set_d64(t, 26, es->sample->stream_id);
 
        call_object(tables->sample_handler, t, "sample_table");