diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt index caaab28f8400fe3ddb57661abfc08ec2bd8cbb93..9936819aae1cb18fb966bbe690739cfe9804d752 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt @@ -417,6 +417,9 @@ include::itrace.txt[] For itrace only show specified functions and their callees for itrace. Multiple functions can be separated by comma. +--switch-on EVENT_NAME:: + Only consider events after this event is found. + SEE ALSO -------- linkperf:perf-record[1], linkperf:perf-script-perl[1], diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 31a529ec139f39c68f5168c461597c09b1800b00..d0bc7ccaf7bf21a457b848388a742587341f8d24 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -1616,6 +1616,11 @@ static int perf_sample__fprintf_synth(struct perf_sample *sample, return 0; } +struct evswitch { + struct evsel *on; + bool discarding; +}; + struct perf_script { struct perf_tool tool; struct perf_session *session; @@ -1628,6 +1633,7 @@ struct perf_script { bool show_bpf_events; bool allocated; bool per_event_dump; + struct evswitch evswitch; struct perf_cpu_map *cpus; struct perf_thread_map *threads; int name_width; @@ -1805,6 +1811,13 @@ static void process_event(struct perf_script *script, if (!show_event(sample, evsel, thread, al)) return; + if (script->evswitch.on && script->evswitch.discarding) { + if (script->evswitch.on != evsel) + return; + + script->evswitch.discarding = false; + } + ++es->samples; perf_sample__fprintf_start(sample, thread, evsel, @@ -3395,6 +3408,7 @@ int cmd_script(int argc, const char **argv) struct utsname uts; char *script_path = NULL; const char **__argv; + const char *event_switch_on = NULL; int i, j, err = 0; struct perf_script script = { .tool = { @@ -3538,6 +3552,8 @@ int cmd_script(int argc, const char **argv) "file", "file saving guest os /proc/kallsyms"), OPT_STRING(0, "guestmodules", &symbol_conf.default_guest_modules, "file", "file saving guest os /proc/modules"), + OPT_STRING(0, "switch-on", &event_switch_on, + "event", "Consider events from the first ocurrence of this event"), OPT_END() }; const char * const script_subcommands[] = { "record", "report", NULL }; @@ -3862,6 +3878,16 @@ int cmd_script(int argc, const char **argv) script.range_num); } + if (event_switch_on) { + script.evswitch.on = perf_evlist__find_evsel_by_str(session->evlist, event_switch_on); + if (script.evswitch.on == NULL) { + fprintf(stderr, "switch-on event not found (%s)\n", event_switch_on); + err = -ENOENT; + goto out_delete; + } + script.evswitch.discarding = true; + } + err = __cmd_script(&script); flush_scripting();