From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753850AbbG2IQS (ORCPT ); Wed, 29 Jul 2015 04:16:18 -0400 Received: from terminus.zytor.com ([198.137.202.10]:57030 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752817AbbG2IQO (ORCPT ); Wed, 29 Jul 2015 04:16:14 -0400 Date: Wed, 29 Jul 2015 01:15:38 -0700 From: tip-bot for Adrian Hunter Message-ID: Cc: ak@linux.intel.com, jolsa@redhat.com, mingo@kernel.org, acme@redhat.com, mathieu.poirier@linaro.org, hpa@zytor.com, eranian@google.com, pawel.moll@arm.com, tglx@linutronix.de, linux-kernel@vger.kernel.org, peterz@infradead.org, adrian.hunter@intel.com Reply-To: adrian.hunter@intel.com, peterz@infradead.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, pawel.moll@arm.com, eranian@google.com, hpa@zytor.com, acme@redhat.com, mathieu.poirier@linaro.org, mingo@kernel.org, jolsa@redhat.com, ak@linux.intel.com In-Reply-To: <1437471846-26995-6-git-send-email-adrian.hunter@intel.com> References: <1437471846-26995-6-git-send-email-adrian.hunter@intel.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf script: Add option --show-switch-events Git-Commit-ID: 7c14898ba9386ee5c939bb418643ac6baff52840 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: 7c14898ba9386ee5c939bb418643ac6baff52840 Gitweb: http://git.kernel.org/tip/7c14898ba9386ee5c939bb418643ac6baff52840 Author: Adrian Hunter AuthorDate: Tue, 21 Jul 2015 12:44:06 +0300 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 23 Jul 2015 22:51:14 -0300 perf script: Add option --show-switch-events Add option --show-switch-events to show switch events in a similar fashion to --show-task-events and --show-mmap-events. Signed-off-by: Adrian Hunter Acked-by: Peter Zijlstra (Intel) Tested-by: Jiri Olsa Tested-by: Arnaldo Carvalho de Melo Cc: Andi Kleen Cc: Mathieu Poirier Cc: Pawel Moll Cc: Peter Zijlstra Cc: Stephane Eranian Link: http://lkml.kernel.org/r/1437471846-26995-6-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Documentation/perf-script.txt | 4 ++++ tools/perf/builtin-script.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt index c82df57..e2fec5f 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt @@ -222,6 +222,10 @@ OPTIONS --show-mmap-events Display mmap related events (e.g. MMAP, MMAP2). +--show-switch-events + Display context switch events i.e. events of type PERF_RECORD_SWITCH or + PERF_RECORD_SWITCH_CPU_WIDE. + --header Show perf.data header. diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 8a8e2ea..bd31380 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -623,6 +623,7 @@ struct perf_script { struct perf_session *session; bool show_task_events; bool show_mmap_events; + bool show_switch_events; }; static int process_attr(struct perf_tool *tool, union perf_event *event, @@ -813,6 +814,32 @@ static int process_mmap2_event(struct perf_tool *tool, return 0; } +static int process_switch_event(struct perf_tool *tool, + union perf_event *event, + struct perf_sample *sample, + struct machine *machine) +{ + struct thread *thread; + struct perf_script *script = container_of(tool, struct perf_script, tool); + struct perf_session *session = script->session; + struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id); + + if (perf_event__process_switch(tool, event, sample, machine) < 0) + return -1; + + thread = machine__findnew_thread(machine, sample->pid, + sample->tid); + if (thread == NULL) { + pr_debug("problem processing SWITCH event, skipping it.\n"); + return -1; + } + + print_sample_start(sample, thread, evsel); + perf_event__fprintf(event, stdout); + thread__put(thread); + return 0; +} + static void sig_handler(int sig __maybe_unused) { session_done = 1; @@ -834,6 +861,8 @@ static int __cmd_script(struct perf_script *script) script->tool.mmap = process_mmap_event; script->tool.mmap2 = process_mmap2_event; } + if (script->show_switch_events) + script->tool.context_switch = process_switch_event; ret = perf_session__process_events(script->session); @@ -1618,6 +1647,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused) "Show the fork/comm/exit events"), OPT_BOOLEAN('\0', "show-mmap-events", &script.show_mmap_events, "Show the mmap events"), + OPT_BOOLEAN('\0', "show-switch-events", &script.show_switch_events, + "Show context switch events (if recorded)"), OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"), OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts", "Instruction Tracing options",