From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751846AbdGQWLC (ORCPT ); Mon, 17 Jul 2017 18:11:02 -0400 Received: from mail-pg0-f51.google.com ([74.125.83.51]:35383 "EHLO mail-pg0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751318AbdGQWK6 (ORCPT ); Mon, 17 Jul 2017 18:10:58 -0400 From: Arun Kalyanasundaram To: Arnaldo Carvalho de Melo , linux-kernel@vger.kernel.org Cc: Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Arun Kalyanasundaram , Jiri Olsa , Daniel Borkmann , "David S . Miller" , SeongJae Park , davidcc@google.com, Stephane Eranian Subject: [RFC 4/4] perf script python: Generate hooks with additional argument Date: Mon, 17 Jul 2017 15:10:40 -0700 Message-Id: <20170717221040.88148-5-arunkaly@google.com> X-Mailer: git-send-email 2.13.2.932.g7449e964c-goog In-Reply-To: <20170717221040.88148-1-arunkaly@google.com> References: <20170717221040.88148-1-arunkaly@google.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- .../perf/util/scripting-engines/trace-event-python.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index a23f5940f826..2fef0cb0383c 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1312,6 +1312,12 @@ static int python_generate_script(struct pevent *pevent, const char *outfile) fprintf(ofp, "%s", f->name); } + if (not_first++) + fprintf(ofp, ", "); + if (++count % 5 == 0) + fprintf(ofp, "\n\t\t"); + fprintf(ofp, "perf_sample_dict"); + fprintf(ofp, "):\n"); fprintf(ofp, "\t\tprint_header(event_name, common_cpu, " @@ -1381,6 +1387,9 @@ static int python_generate_script(struct pevent *pevent, const char *outfile) fprintf(ofp, ")\n\n"); + fprintf(ofp, "\t\tprint 'Sample: {'+" + "get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'\n\n"); + fprintf(ofp, "\t\tfor node in common_callchain:"); fprintf(ofp, "\n\t\t\tif 'sym' in node:"); fprintf(ofp, "\n\t\t\t\tprint \"\\t[%%x] %%s\" %% (node['ip'], node['sym']['name'])"); @@ -1391,16 +1400,21 @@ static int python_generate_script(struct pevent *pevent, const char *outfile) } fprintf(ofp, "def trace_unhandled(event_name, context, " - "event_fields_dict):\n"); + "event_fields_dict, perf_sample_dict):\n"); - fprintf(ofp, "\t\tprint ' '.join(['%%s=%%s'%%(k,str(v))" - "for k,v in sorted(event_fields_dict.items())])\n\n"); + fprintf(ofp, "\t\tprint get_dict_as_string(event_fields_dict)\n"); + fprintf(ofp, "\t\tprint 'Sample: {'+" + "get_dict_as_string(perf_sample_dict['sample'], ', ')+'}'\n\n"); fprintf(ofp, "def print_header(" "event_name, cpu, secs, nsecs, pid, comm):\n" "\tprint \"%%-20s %%5u %%05u.%%09u %%8u %%-20s \" %% \\\n\t" "(event_name, cpu, secs, nsecs, pid, comm),\n"); + fprintf(ofp, "def get_dict_as_string(a_dict, delimiter=' '):\n" + "\treturn delimiter.join" + "(['%%s=%%s'%%(k,str(v))for k,v in sorted(a_dict.items())])"); + fclose(ofp); fprintf(stderr, "generated Python script: %s\n", fname); -- 2.13.2.932.g7449e964c-goog