From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751841AbdGZRan (ORCPT ); Wed, 26 Jul 2017 13:30:43 -0400 Received: from terminus.zytor.com ([65.50.211.136]:39401 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751325AbdGZRal (ORCPT ); Wed, 26 Jul 2017 13:30:41 -0400 Date: Wed, 26 Jul 2017 10:25:51 -0700 From: tip-bot for Arun Kalyanasundaram Message-ID: Cc: hpa@zytor.com, arunkaly@google.com, daniel@iogearbox.net, linux-kernel@vger.kernel.org, peterz@infradead.org, eranian@google.com, davem@davemloft.net, mingo@kernel.org, davidcc@google.com, tglx@linutronix.de, jolsa@kernel.org, acme@redhat.com, sj38.park@gmail.com, alexander.shishkin@linux.intel.com Reply-To: arunkaly@google.com, hpa@zytor.com, linux-kernel@vger.kernel.org, peterz@infradead.org, daniel@iogearbox.net, eranian@google.com, jolsa@kernel.org, sj38.park@gmail.com, acme@redhat.com, alexander.shishkin@linux.intel.com, mingo@kernel.org, davidcc@google.com, davem@davemloft.net, tglx@linutronix.de In-Reply-To: <20170721220422.63962-6-arunkaly@google.com> References: <20170721220422.63962-6-arunkaly@google.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf script python: Generate hooks with additional argument Git-Commit-ID: a641860550f05a4b8889dca61aab73c84b2d5e16 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: a641860550f05a4b8889dca61aab73c84b2d5e16 Gitweb: http://git.kernel.org/tip/a641860550f05a4b8889dca61aab73c84b2d5e16 Author: Arun Kalyanasundaram AuthorDate: Fri, 21 Jul 2017 15:04:22 -0700 Committer: Arnaldo Carvalho de Melo CommitDate: Tue, 25 Jul 2017 22:43:21 -0300 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 Acked-by: Jiri Olsa Cc: Alexander Shishkin Cc: Daniel Borkmann Cc: David Carrillo-Cisneros Cc: David S. Miller Cc: Peter Zijlstra Cc: Seongjae Park Cc: Stephane Eranian Link: http://lkml.kernel.org/r/20170721220422.63962-6-arunkaly@google.com Signed-off-by: Arnaldo Carvalho de Melo --- .../util/scripting-engines/trace-event-python.c | 22 ++++++++++++++++++---- 1 file 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 938b39f..c7187f0 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) 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, " @@ -1436,6 +1442,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'])"); @@ -1446,15 +1455,20 @@ 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"); + "(event_name, cpu, secs, nsecs, pid, comm),\n\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())])\n"); fclose(ofp);