diff options
author | Arun Kalyanasundaram <arunkaly@google.com> | 2017-07-21 18:04:22 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2017-07-25 21:43:21 -0400 |
commit | a641860550f05a4b8889dca61aab73c84b2d5e16 (patch) | |
tree | 05f75e875b9096f0e11af068d2341ca6d65f11db | |
parent | f38d281663b011d1d8a1b0119bb8357706d134a8 (diff) |
perf script python: Generate hooks with additional argument
Modify the signature of tracepoint specific and trace_unhandled hooks to
add the perf_sample dict as a new argument.
Create a python helper function to print a dictionary.
Signed-off-by: Arun Kalyanasundaram <arunkaly@google.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Carrillo-Cisneros <davidcc@google.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Seongjae Park <sj38.park@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20170721220422.63962-6-arunkaly@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/scripting-engines/trace-event-python.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 938b39f6ad31..c7187f067d31 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c | |||
@@ -1367,6 +1367,12 @@ static int python_generate_script(struct pevent *pevent, const char *outfile) | |||
1367 | 1367 | ||
1368 | fprintf(ofp, "%s", f->name); | 1368 | fprintf(ofp, "%s", f->name); |
1369 | } | 1369 | } |
1370 | if (not_first++) | ||
1371 | fprintf(ofp, ", "); | ||
1372 | if (++count % 5 == 0) | ||
1373 | fprintf(ofp, "\n\t\t"); | ||
1374 | fprintf(ofp, "perf_sample_dict"); | ||
1375 | |||
1370 | fprintf(ofp, "):\n"); | 1376 | fprintf(ofp, "):\n"); |
1371 | 1377 | ||
1372 | fprintf(ofp, "\t\tprint_header(event_name, common_cpu, " | 1378 | fprintf(ofp, "\t\tprint_header(event_name, common_cpu, " |
@@ -1436,6 +1442,9 @@ static int python_generate_script(struct pevent *pevent, const char *outfile) | |||
1436 | 1442 | ||
1437 | fprintf(ofp, ")\n\n"); | 1443 | fprintf(ofp, ")\n\n"); |
1438 | 1444 | ||
1445 | fprintf(ofp, "\t\tprint 'Sample: {'+" | ||
1446 | "get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'\n\n"); | ||
1447 | |||
1439 | fprintf(ofp, "\t\tfor node in common_callchain:"); | 1448 | fprintf(ofp, "\t\tfor node in common_callchain:"); |
1440 | fprintf(ofp, "\n\t\t\tif 'sym' in node:"); | 1449 | fprintf(ofp, "\n\t\t\tif 'sym' in node:"); |
1441 | fprintf(ofp, "\n\t\t\t\tprint \"\\t[%%x] %%s\" %% (node['ip'], node['sym']['name'])"); | 1450 | fprintf(ofp, "\n\t\t\t\tprint \"\\t[%%x] %%s\" %% (node['ip'], node['sym']['name'])"); |
@@ -1446,15 +1455,20 @@ static int python_generate_script(struct pevent *pevent, const char *outfile) | |||
1446 | } | 1455 | } |
1447 | 1456 | ||
1448 | fprintf(ofp, "def trace_unhandled(event_name, context, " | 1457 | fprintf(ofp, "def trace_unhandled(event_name, context, " |
1449 | "event_fields_dict):\n"); | 1458 | "event_fields_dict, perf_sample_dict):\n"); |
1450 | 1459 | ||
1451 | fprintf(ofp, "\t\tprint ' '.join(['%%s=%%s'%%(k,str(v))" | 1460 | fprintf(ofp, "\t\tprint get_dict_as_string(event_fields_dict)\n"); |
1452 | "for k,v in sorted(event_fields_dict.items())])\n\n"); | 1461 | fprintf(ofp, "\t\tprint 'Sample: {'+" |
1462 | "get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'\n\n"); | ||
1453 | 1463 | ||
1454 | fprintf(ofp, "def print_header(" | 1464 | fprintf(ofp, "def print_header(" |
1455 | "event_name, cpu, secs, nsecs, pid, comm):\n" | 1465 | "event_name, cpu, secs, nsecs, pid, comm):\n" |
1456 | "\tprint \"%%-20s %%5u %%05u.%%09u %%8u %%-20s \" %% \\\n\t" | 1466 | "\tprint \"%%-20s %%5u %%05u.%%09u %%8u %%-20s \" %% \\\n\t" |
1457 | "(event_name, cpu, secs, nsecs, pid, comm),\n"); | 1467 | "(event_name, cpu, secs, nsecs, pid, comm),\n\n"); |
1468 | |||
1469 | fprintf(ofp, "def get_dict_as_string(a_dict, delimiter=' '):\n" | ||
1470 | "\treturn delimiter.join" | ||
1471 | "(['%%s=%%s'%%(k,str(v))for k,v in sorted(a_dict.items())])\n"); | ||
1458 | 1472 | ||
1459 | fclose(ofp); | 1473 | fclose(ofp); |
1460 | 1474 | ||