aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2015-07-21 05:44:06 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-07-23 21:51:14 -0400
commit7c14898ba9386ee5c939bb418643ac6baff52840 (patch)
treeebac2c2525d9747d6220ae1319e37a7d2af13b6f /tools/perf
parent06b234ec26fde8d0fce54030fe0858e218636410 (diff)
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 <adrian.hunter@intel.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Jiri Olsa <jolsa@redhat.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Mathieu Poirier <mathieu.poirier@linaro.org> Cc: Pawel Moll <pawel.moll@arm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1437471846-26995-6-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/Documentation/perf-script.txt4
-rw-r--r--tools/perf/builtin-script.c31
2 files changed, 35 insertions, 0 deletions
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index c82df572fac2..e2fec5fc21e7 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -222,6 +222,10 @@ OPTIONS
222--show-mmap-events 222--show-mmap-events
223 Display mmap related events (e.g. MMAP, MMAP2). 223 Display mmap related events (e.g. MMAP, MMAP2).
224 224
225--show-switch-events
226 Display context switch events i.e. events of type PERF_RECORD_SWITCH or
227 PERF_RECORD_SWITCH_CPU_WIDE.
228
225--header 229--header
226 Show perf.data header. 230 Show perf.data header.
227 231
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 8a8e2ead6382..bd31380122f9 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -623,6 +623,7 @@ struct perf_script {
623 struct perf_session *session; 623 struct perf_session *session;
624 bool show_task_events; 624 bool show_task_events;
625 bool show_mmap_events; 625 bool show_mmap_events;
626 bool show_switch_events;
626}; 627};
627 628
628static int process_attr(struct perf_tool *tool, union perf_event *event, 629static int process_attr(struct perf_tool *tool, union perf_event *event,
@@ -813,6 +814,32 @@ static int process_mmap2_event(struct perf_tool *tool,
813 return 0; 814 return 0;
814} 815}
815 816
817static int process_switch_event(struct perf_tool *tool,
818 union perf_event *event,
819 struct perf_sample *sample,
820 struct machine *machine)
821{
822 struct thread *thread;
823 struct perf_script *script = container_of(tool, struct perf_script, tool);
824 struct perf_session *session = script->session;
825 struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
826
827 if (perf_event__process_switch(tool, event, sample, machine) < 0)
828 return -1;
829
830 thread = machine__findnew_thread(machine, sample->pid,
831 sample->tid);
832 if (thread == NULL) {
833 pr_debug("problem processing SWITCH event, skipping it.\n");
834 return -1;
835 }
836
837 print_sample_start(sample, thread, evsel);
838 perf_event__fprintf(event, stdout);
839 thread__put(thread);
840 return 0;
841}
842
816static void sig_handler(int sig __maybe_unused) 843static void sig_handler(int sig __maybe_unused)
817{ 844{
818 session_done = 1; 845 session_done = 1;
@@ -834,6 +861,8 @@ static int __cmd_script(struct perf_script *script)
834 script->tool.mmap = process_mmap_event; 861 script->tool.mmap = process_mmap_event;
835 script->tool.mmap2 = process_mmap2_event; 862 script->tool.mmap2 = process_mmap2_event;
836 } 863 }
864 if (script->show_switch_events)
865 script->tool.context_switch = process_switch_event;
837 866
838 ret = perf_session__process_events(script->session); 867 ret = perf_session__process_events(script->session);
839 868
@@ -1618,6 +1647,8 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
1618 "Show the fork/comm/exit events"), 1647 "Show the fork/comm/exit events"),
1619 OPT_BOOLEAN('\0', "show-mmap-events", &script.show_mmap_events, 1648 OPT_BOOLEAN('\0', "show-mmap-events", &script.show_mmap_events,
1620 "Show the mmap events"), 1649 "Show the mmap events"),
1650 OPT_BOOLEAN('\0', "show-switch-events", &script.show_switch_events,
1651 "Show context switch events (if recorded)"),
1621 OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"), 1652 OPT_BOOLEAN('f', "force", &file.force, "don't complain, do it"),
1622 OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts", 1653 OPT_CALLBACK_OPTARG(0, "itrace", &itrace_synth_opts, NULL, "opts",
1623 "Instruction Tracing options", 1654 "Instruction Tracing options",