diff options
-rw-r--r-- | tools/perf/Documentation/perf-script.txt | 3 | ||||
-rw-r--r-- | tools/perf/builtin-script.c | 26 |
2 files changed, 29 insertions, 0 deletions
diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt index caaab28f8400..9936819aae1c 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt | |||
@@ -417,6 +417,9 @@ include::itrace.txt[] | |||
417 | For itrace only show specified functions and their callees for | 417 | For itrace only show specified functions and their callees for |
418 | itrace. Multiple functions can be separated by comma. | 418 | itrace. Multiple functions can be separated by comma. |
419 | 419 | ||
420 | --switch-on EVENT_NAME:: | ||
421 | Only consider events after this event is found. | ||
422 | |||
420 | SEE ALSO | 423 | SEE ALSO |
421 | -------- | 424 | -------- |
422 | linkperf:perf-record[1], linkperf:perf-script-perl[1], | 425 | linkperf:perf-record[1], linkperf:perf-script-perl[1], |
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 31a529ec139f..d0bc7ccaf7bf 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, | |||
1616 | return 0; | 1616 | return 0; |
1617 | } | 1617 | } |
1618 | 1618 | ||
1619 | struct evswitch { | ||
1620 | struct evsel *on; | ||
1621 | bool discarding; | ||
1622 | }; | ||
1623 | |||
1619 | struct perf_script { | 1624 | struct perf_script { |
1620 | struct perf_tool tool; | 1625 | struct perf_tool tool; |
1621 | struct perf_session *session; | 1626 | struct perf_session *session; |
@@ -1628,6 +1633,7 @@ struct perf_script { | |||
1628 | bool show_bpf_events; | 1633 | bool show_bpf_events; |
1629 | bool allocated; | 1634 | bool allocated; |
1630 | bool per_event_dump; | 1635 | bool per_event_dump; |
1636 | struct evswitch evswitch; | ||
1631 | struct perf_cpu_map *cpus; | 1637 | struct perf_cpu_map *cpus; |
1632 | struct perf_thread_map *threads; | 1638 | struct perf_thread_map *threads; |
1633 | int name_width; | 1639 | int name_width; |
@@ -1805,6 +1811,13 @@ static void process_event(struct perf_script *script, | |||
1805 | if (!show_event(sample, evsel, thread, al)) | 1811 | if (!show_event(sample, evsel, thread, al)) |
1806 | return; | 1812 | return; |
1807 | 1813 | ||
1814 | if (script->evswitch.on && script->evswitch.discarding) { | ||
1815 | if (script->evswitch.on != evsel) | ||
1816 | return; | ||
1817 | |||
1818 | script->evswitch.discarding = false; | ||
1819 | } | ||
1820 | |||
1808 | ++es->samples; | 1821 | ++es->samples; |
1809 | 1822 | ||
1810 | perf_sample__fprintf_start(sample, thread, evsel, | 1823 | perf_sample__fprintf_start(sample, thread, evsel, |
@@ -3395,6 +3408,7 @@ int cmd_script(int argc, const char **argv) | |||
3395 | struct utsname uts; | 3408 | struct utsname uts; |
3396 | char *script_path = NULL; | 3409 | char *script_path = NULL; |
3397 | const char **__argv; | 3410 | const char **__argv; |
3411 | const char *event_switch_on = NULL; | ||
3398 | int i, j, err = 0; | 3412 | int i, j, err = 0; |
3399 | struct perf_script script = { | 3413 | struct perf_script script = { |
3400 | .tool = { | 3414 | .tool = { |
@@ -3538,6 +3552,8 @@ int cmd_script(int argc, const char **argv) | |||
3538 | "file", "file saving guest os /proc/kallsyms"), | 3552 | "file", "file saving guest os /proc/kallsyms"), |
3539 | OPT_STRING(0, "guestmodules", &symbol_conf.default_guest_modules, | 3553 | OPT_STRING(0, "guestmodules", &symbol_conf.default_guest_modules, |
3540 | "file", "file saving guest os /proc/modules"), | 3554 | "file", "file saving guest os /proc/modules"), |
3555 | OPT_STRING(0, "switch-on", &event_switch_on, | ||
3556 | "event", "Consider events from the first ocurrence of this event"), | ||
3541 | OPT_END() | 3557 | OPT_END() |
3542 | }; | 3558 | }; |
3543 | const char * const script_subcommands[] = { "record", "report", NULL }; | 3559 | const char * const script_subcommands[] = { "record", "report", NULL }; |
@@ -3862,6 +3878,16 @@ int cmd_script(int argc, const char **argv) | |||
3862 | script.range_num); | 3878 | script.range_num); |
3863 | } | 3879 | } |
3864 | 3880 | ||
3881 | if (event_switch_on) { | ||
3882 | script.evswitch.on = perf_evlist__find_evsel_by_str(session->evlist, event_switch_on); | ||
3883 | if (script.evswitch.on == NULL) { | ||
3884 | fprintf(stderr, "switch-on event not found (%s)\n", event_switch_on); | ||
3885 | err = -ENOENT; | ||
3886 | goto out_delete; | ||
3887 | } | ||
3888 | script.evswitch.discarding = true; | ||
3889 | } | ||
3890 | |||
3865 | err = __cmd_script(&script); | 3891 | err = __cmd_script(&script); |
3866 | 3892 | ||
3867 | flush_scripting(); | 3893 | flush_scripting(); |