summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2019-08-14 15:51:28 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-08-15 11:24:16 -0400
commitdd41f660c03a6d8f2c2f3b2cccf50d8c4e06dd42 (patch)
tree56bfe26e46a559004c547b3870f4e7db6f10bc75
parent6469eb6dffeb44edfa3d4ca496b044b4a9c643b9 (diff)
perf script: Allow specifying event to switch off processing of other events
Counterpart of --switch-on: # perf record -e sched:*,syscalls:sys_*_nanosleep sleep 1 [ perf record: Woken up 36 times to write data ] [ perf record: Captured and wrote 0.032 MB perf.data (10 samples) ] # # perf script :20918 20918 [002] 109866.143696: sched:sched_waking: comm=perf pid=20919 prio=120 target_cpu=001 :20918 20918 [002] 109866.143702: sched:sched_wakeup: perf:20919 [120] success=1 CPU:001 sleep 20919 [001] 109866.144081: sched:sched_process_exec: filename=/usr/bin/sleep pid=20919 old_pid=20919 sleep 20919 [001] 109866.144408: syscalls:sys_enter_nanosleep: rqtp: 0x7ffc2384fef0, rmtp: 0x00000000 sleep 20919 [001] 109866.144411: sched:sched_stat_runtime: comm=sleep pid=20919 runtime=521249 [ns] vruntime=202919398131 [n> sleep 20919 [001] 109866.144412: sched:sched_switch: sleep:20919 [120] S ==> swapper/1:0 [120] swapper 0 [001] 109867.144568: sched:sched_waking: comm=sleep pid=20919 prio=120 target_cpu=001 swapper 0 [001] 109867.144586: sched:sched_wakeup: sleep:20919 [120] success=1 CPU:001 sleep 20919 [001] 109867.144614: syscalls:sys_exit_nanosleep: 0x0 sleep 20919 [001] 109867.144753: sched:sched_process_exit: comm=sleep pid=20919 prio=120 # # perf script --switch-off syscalls:sys_exit_nanosleep :20918 20918 [002] 109866.143696: sched:sched_waking: comm=perf pid=20919 prio=120 target_cpu=001 :20918 20918 [002] 109866.143702: sched:sched_wakeup: perf:20919 [120] success=1 CPU:001 sleep 20919 [001] 109866.144081: sched:sched_process_exec: filename=/usr/bin/sleep pid=20919 old_pid=20919 sleep 20919 [001] 109866.144408: syscalls:sys_enter_nanosleep: rqtp: 0x7ffc2384fef0, rmtp: 0x00000000 sleep 20919 [001] 109866.144411: sched:sched_stat_runtime: comm=sleep pid=20919 runtime=521249 [ns] vruntime=202919398131 [n> sleep 20919 [001] 109866.144412: sched:sched_switch: sleep:20919 [120] S ==> swapper/1:0 [120] swapper 0 [001] 109867.144568: sched:sched_waking: comm=sleep pid=20919 prio=120 target_cpu=001 swapper 0 [001] 109867.144586: sched:sched_wakeup: sleep:20919 [120] success=1 CPU:001 sleep 20919 [001] 109867.144753: sched:sched_process_exit: comm=sleep pid=20919 prio=120 # # perf script --switch-on syscalls:sys_enter_nanosleep --switch-off syscalls:sys_exit_nanosleep sleep 20919 [001] 109866.144411: sched:sched_stat_runtime: comm=sleep pid=20919 runtime=521249 [ns] vruntime=202919398131 [n> sleep 20919 [001] 109866.144412: sched:sched_switch: sleep:20919 [120] S ==> swapper/1:0 [120] swapper 0 [001] 109867.144568: sched:sched_waking: comm=sleep pid=20919 prio=120 target_cpu=001 swapper 0 [001] 109867.144586: sched:sched_wakeup: sleep:20919 [120] success=1 CPU:001 # # perf script --switch-on syscalls:sys_enter_nanosleep --switch-off syscalls:sys_exit_nanosleep --show-on-off sleep 20919 [001] 109866.144408: syscalls:sys_enter_nanosleep: rqtp: 0x7ffc2384fef0, rmtp: 0x00000000 sleep 20919 [001] 109866.144411: sched:sched_stat_runtime: comm=sleep pid=20919 runtime=521249 [ns] vruntime=202919398131 [n> sleep 20919 [001] 109866.144412: sched:sched_switch: sleep:20919 [120] S ==> swapper/1:0 [120] swapper 0 [001] 109867.144568: sched:sched_waking: comm=sleep pid=20919 prio=120 target_cpu=001 swapper 0 [001] 109867.144586: sched:sched_wakeup: sleep:20919 [120] success=1 CPU:001 sleep 20919 [001] 109867.144614: syscalls:sys_exit_nanosleep: 0x0 # Now think about using this together with 'perf probe' to create custom on/off events in your app :-) Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Florian Weimer <fweimer@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: William Cohen <wcohen@redhat.com> Link: https://lkml.kernel.org/n/tip-li3j01c4tmj9kw6ydsl8swej@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/Documentation/perf-script.txt5
-rw-r--r--tools/perf/builtin-script.c31
2 files changed, 32 insertions, 4 deletions
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 24eea68ee829..2599b057e47b 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -420,8 +420,11 @@ include::itrace.txt[]
420--switch-on EVENT_NAME:: 420--switch-on EVENT_NAME::
421 Only consider events after this event is found. 421 Only consider events after this event is found.
422 422
423--switch-off EVENT_NAME::
424 Stop considering events after this event is found.
425
423--show-on-off-events:: 426--show-on-off-events::
424 Show the --switch-on event too. 427 Show the --switch-on/off events too.
425 428
426SEE ALSO 429SEE ALSO
427-------- 430--------
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index fa0cc8b0eccc..b6eed0f7e835 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1617,7 +1617,8 @@ static int perf_sample__fprintf_synth(struct perf_sample *sample,
1617} 1617}
1618 1618
1619struct evswitch { 1619struct evswitch {
1620 struct evsel *on; 1620 struct evsel *on,
1621 *off;
1621 bool discarding; 1622 bool discarding;
1622 bool show_on_off_events; 1623 bool show_on_off_events;
1623}; 1624};
@@ -1820,8 +1821,20 @@ static void process_event(struct perf_script *script,
1820 1821
1821 if (!script->evswitch.show_on_off_events) 1822 if (!script->evswitch.show_on_off_events)
1822 return; 1823 return;
1824
1825 goto print_it;
1823 } 1826 }
1824 1827
1828 if (script->evswitch.off && !script->evswitch.discarding) {
1829 if (script->evswitch.off != evsel)
1830 goto print_it;
1831
1832 script->evswitch.discarding = true;
1833
1834 if (!script->evswitch.show_on_off_events)
1835 return;
1836 }
1837print_it:
1825 ++es->samples; 1838 ++es->samples;
1826 1839
1827 perf_sample__fprintf_start(sample, thread, evsel, 1840 perf_sample__fprintf_start(sample, thread, evsel,
@@ -3412,7 +3425,8 @@ int cmd_script(int argc, const char **argv)
3412 struct utsname uts; 3425 struct utsname uts;
3413 char *script_path = NULL; 3426 char *script_path = NULL;
3414 const char **__argv; 3427 const char **__argv;
3415 const char *event_switch_on = NULL; 3428 const char *event_switch_on = NULL,
3429 *event_switch_off = NULL;
3416 int i, j, err = 0; 3430 int i, j, err = 0;
3417 struct perf_script script = { 3431 struct perf_script script = {
3418 .tool = { 3432 .tool = {
@@ -3557,7 +3571,9 @@ int cmd_script(int argc, const char **argv)
3557 OPT_STRING(0, "guestmodules", &symbol_conf.default_guest_modules, 3571 OPT_STRING(0, "guestmodules", &symbol_conf.default_guest_modules,
3558 "file", "file saving guest os /proc/modules"), 3572 "file", "file saving guest os /proc/modules"),
3559 OPT_STRING(0, "switch-on", &event_switch_on, 3573 OPT_STRING(0, "switch-on", &event_switch_on,
3560 "event", "Consider events from the first ocurrence of this event"), 3574 "event", "Consider events after the ocurrence of this event"),
3575 OPT_STRING(0, "switch-off", &event_switch_off,
3576 "event", "Stop considering events after the ocurrence of this event"),
3561 OPT_BOOLEAN(0, "show-on-off-events", &script.evswitch.show_on_off_events, 3577 OPT_BOOLEAN(0, "show-on-off-events", &script.evswitch.show_on_off_events,
3562 "Show the on/off switch events, used with --switch-on"), 3578 "Show the on/off switch events, used with --switch-on"),
3563 OPT_END() 3579 OPT_END()
@@ -3894,6 +3910,15 @@ int cmd_script(int argc, const char **argv)
3894 script.evswitch.discarding = true; 3910 script.evswitch.discarding = true;
3895 } 3911 }
3896 3912
3913 if (event_switch_off) {
3914 script.evswitch.off = perf_evlist__find_evsel_by_str(session->evlist, event_switch_off);
3915 if (script.evswitch.off == NULL) {
3916 fprintf(stderr, "switch-off event not found (%s)\n", event_switch_off);
3917 err = -ENOENT;
3918 goto out_delete;
3919 }
3920 }
3921
3897 err = __cmd_script(&script); 3922 err = __cmd_script(&script);
3898 3923
3899 flush_scripting(); 3924 flush_scripting();