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

perf scripting python: Add 'addr_location' for 'addr'

If sample addr correlates to a symbol, add "addr_dso", "addr_symbol", and
"addr_symoff" to 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-4-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
3f8e009e 8271b509

+41 -23
+12 -3
tools/perf/builtin-script.c
··· 2189 2189 if (filter_cpu(sample)) 2190 2190 goto out_put; 2191 2191 2192 - if (scripting_ops) 2193 - scripting_ops->process_event(event, sample, evsel, &al); 2194 - else 2192 + if (scripting_ops) { 2193 + struct addr_location *addr_al_ptr = NULL; 2194 + struct addr_location addr_al; 2195 + 2196 + if ((evsel->core.attr.sample_type & PERF_SAMPLE_ADDR) && 2197 + sample_addr_correlates_sym(&evsel->core.attr)) { 2198 + thread__resolve(al.thread, &addr_al, sample); 2199 + addr_al_ptr = &addr_al; 2200 + } 2201 + scripting_ops->process_event(event, sample, evsel, &al, addr_al_ptr); 2202 + } else { 2195 2203 process_event(scr, sample, evsel, &al, machine); 2204 + } 2196 2205 2197 2206 out_put: 2198 2207 addr_location__put(&al);
+4 -8
tools/perf/util/db-export.c
··· 343 343 344 344 int db_export__sample(struct db_export *dbe, union perf_event *event, 345 345 struct perf_sample *sample, struct evsel *evsel, 346 - struct addr_location *al) 346 + struct addr_location *al, struct addr_location *addr_al) 347 347 { 348 348 struct thread *thread = al->thread; 349 349 struct export_sample es = { ··· 389 389 } 390 390 } 391 391 392 - if ((evsel->core.attr.sample_type & PERF_SAMPLE_ADDR) && 393 - sample_addr_correlates_sym(&evsel->core.attr)) { 394 - struct addr_location addr_al; 395 - 396 - thread__resolve(thread, &addr_al, sample); 397 - err = db_ids_from_al(dbe, &addr_al, &es.addr_dso_db_id, 392 + if (addr_al) { 393 + err = db_ids_from_al(dbe, addr_al, &es.addr_dso_db_id, 398 394 &es.addr_sym_db_id, &es.addr_offset); 399 395 if (err) 400 396 goto out_put; 401 397 if (dbe->crp) { 402 398 err = thread_stack__process(thread, comm, sample, al, 403 - &addr_al, es.db_id, 399 + addr_al, es.db_id, 404 400 dbe->crp); 405 401 if (err) 406 402 goto out_put;
+1 -1
tools/perf/util/db-export.h
··· 97 97 const char *name); 98 98 int db_export__sample(struct db_export *dbe, union perf_event *event, 99 99 struct perf_sample *sample, struct evsel *evsel, 100 - struct addr_location *al); 100 + struct addr_location *al, struct addr_location *addr_al); 101 101 102 102 int db_export__branch_types(struct db_export *dbe); 103 103
+2 -1
tools/perf/util/scripting-engines/trace-event-perl.c
··· 456 456 static void perl_process_event(union perf_event *event, 457 457 struct perf_sample *sample, 458 458 struct evsel *evsel, 459 - struct addr_location *al) 459 + struct addr_location *al, 460 + struct addr_location *addr_al __maybe_unused) 460 461 { 461 462 perl_process_tracepoint(sample, evsel, al); 462 463 perl_process_event_generic(event, sample, evsel);
+18 -8
tools/perf/util/scripting-engines/trace-event-python.c
··· 745 745 static PyObject *get_perf_sample_dict(struct perf_sample *sample, 746 746 struct evsel *evsel, 747 747 struct addr_location *al, 748 + struct addr_location *addr_al, 748 749 PyObject *callchain) 749 750 { 750 751 PyObject *dict, *dict_sample, *brstack, *brstacksym; ··· 799 798 brstacksym = python_process_brstacksym(sample, al->thread); 800 799 pydict_set_item_string_decref(dict, "brstacksym", brstacksym); 801 800 801 + if (addr_al) { 802 + pydict_set_item_string_decref(dict_sample, "addr_correlates_sym", 803 + PyBool_FromLong(1)); 804 + set_sym_in_dict(dict_sample, addr_al, "addr_dso", "addr_symbol", "addr_symoff"); 805 + } 806 + 802 807 set_regs_in_dict(dict, sample, evsel); 803 808 804 809 return dict; ··· 812 805 813 806 static void python_process_tracepoint(struct perf_sample *sample, 814 807 struct evsel *evsel, 815 - struct addr_location *al) 808 + struct addr_location *al, 809 + struct addr_location *addr_al) 816 810 { 817 811 struct tep_event *event = evsel->tp_format; 818 812 PyObject *handler, *context, *t, *obj = NULL, *callchain; ··· 923 915 PyTuple_SetItem(t, n++, dict); 924 916 925 917 if (get_argument_count(handler) == (int) n + 1) { 926 - all_entries_dict = get_perf_sample_dict(sample, evsel, al, 918 + all_entries_dict = get_perf_sample_dict(sample, evsel, al, addr_al, 927 919 callchain); 928 920 PyTuple_SetItem(t, n++, all_entries_dict); 929 921 } else { ··· 1314 1306 1315 1307 static void python_process_general_event(struct perf_sample *sample, 1316 1308 struct evsel *evsel, 1317 - struct addr_location *al) 1309 + struct addr_location *al, 1310 + struct addr_location *addr_al) 1318 1311 { 1319 1312 PyObject *handler, *t, *dict, *callchain; 1320 1313 static char handler_name[64]; ··· 1337 1328 1338 1329 /* ip unwinding */ 1339 1330 callchain = python_process_callchain(sample, evsel, al); 1340 - dict = get_perf_sample_dict(sample, evsel, al, callchain); 1331 + dict = get_perf_sample_dict(sample, evsel, al, addr_al, callchain); 1341 1332 1342 1333 PyTuple_SetItem(t, n++, dict); 1343 1334 if (_PyTuple_Resize(&t, n) == -1) ··· 1351 1342 static void python_process_event(union perf_event *event, 1352 1343 struct perf_sample *sample, 1353 1344 struct evsel *evsel, 1354 - struct addr_location *al) 1345 + struct addr_location *al, 1346 + struct addr_location *addr_al) 1355 1347 { 1356 1348 struct tables *tables = &tables_global; 1357 1349 1358 1350 switch (evsel->core.attr.type) { 1359 1351 case PERF_TYPE_TRACEPOINT: 1360 - python_process_tracepoint(sample, evsel, al); 1352 + python_process_tracepoint(sample, evsel, al, addr_al); 1361 1353 break; 1362 1354 /* Reserve for future process_hw/sw/raw APIs */ 1363 1355 default: 1364 1356 if (tables->db_export_mode) 1365 - db_export__sample(&tables->dbe, event, sample, evsel, al); 1357 + db_export__sample(&tables->dbe, event, sample, evsel, al, addr_al); 1366 1358 else 1367 - python_process_general_event(sample, evsel, al); 1359 + python_process_general_event(sample, evsel, al, addr_al); 1368 1360 } 1369 1361 } 1370 1362
+2 -1
tools/perf/util/trace-event-scripting.c
··· 29 29 static void process_event_unsupported(union perf_event *event __maybe_unused, 30 30 struct perf_sample *sample __maybe_unused, 31 31 struct evsel *evsel __maybe_unused, 32 - struct addr_location *al __maybe_unused) 32 + struct addr_location *al __maybe_unused, 33 + struct addr_location *addr_al __maybe_unused) 33 34 { 34 35 } 35 36
+2 -1
tools/perf/util/trace-event.h
··· 78 78 void (*process_event) (union perf_event *event, 79 79 struct perf_sample *sample, 80 80 struct evsel *evsel, 81 - struct addr_location *al); 81 + struct addr_location *al, 82 + struct addr_location *addr_al); 82 83 void (*process_switch)(union perf_event *event, 83 84 struct perf_sample *sample, 84 85 struct machine *machine);