All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Andi Kleen <ak@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@redhat.com>,
	Stephane Eranian <eranian@google.com>,
	mathieu.poirier@linaro.org, Pawel Moll <pawel.moll@arm.com>
Subject: [PATCH V3 4/4] perf script: Add option --show-switch-events
Date: Tue,  7 Jul 2015 11:36:42 +0300	[thread overview]
Message-ID: <1436258202-6540-5-git-send-email-adrian.hunter@intel.com> (raw)
In-Reply-To: <1436258202-6540-1-git-send-email-adrian.hunter@intel.com>

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 <adrian.hunter@intel.com>
---
 tools/perf/Documentation/perf-script.txt |  3 +++
 tools/perf/builtin-script.c              | 31 +++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index c82df572fac2..beca47ae9dbf 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -222,6 +222,9 @@ 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.
+
 --header
 	Show perf.data header.
 
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 24809787369f..b3a00c93bfa1 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__first(session->evlist);
+
+	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",
-- 
1.9.1


  parent reply	other threads:[~2015-07-07  8:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-07  8:36 [PATCH V3 0/4] perf: Add PERF_RECORD_SWITCH to indicate context switches Adrian Hunter
2015-07-07  8:36 ` [PATCH V3 1/4] " Adrian Hunter
2015-07-07 13:25   ` Arnaldo Carvalho de Melo
2015-07-07 13:44     ` Arnaldo Carvalho de Melo
2015-07-07 15:36       ` Peter Zijlstra
2015-07-07 16:13         ` Arnaldo Carvalho de Melo
2015-07-07 22:52           ` Peter Zijlstra
2015-07-08 13:28             ` Arnaldo Carvalho de Melo
2015-07-08 13:42               ` Adrian Hunter
2015-07-08 14:56                 ` Arnaldo Carvalho de Melo
2015-07-07  8:36 ` [PATCH V3 2/4] perf tools: Add new PERF_RECORD_SWITCH event Adrian Hunter
2015-07-07 13:50   ` Arnaldo Carvalho de Melo
2015-07-07  8:36 ` [PATCH V3 3/4] perf record: Add option --switch-events to select PERF_RECORD_SWITCH events Adrian Hunter
2015-07-07 13:53   ` Arnaldo Carvalho de Melo
2015-07-07  8:36 ` Adrian Hunter [this message]
2015-07-07 13:54   ` [PATCH V3 4/4] perf script: Add option --show-switch-events Arnaldo Carvalho de Melo
2015-07-07  9:06 ` [PATCH V3 0/4] perf: Add PERF_RECORD_SWITCH to indicate context switches Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1436258202-6540-5-git-send-email-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=mingo@kernel.org \
    --cc=pawel.moll@arm.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.