aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2019-08-15 15:03:26 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-08-15 15:03:26 -0400
commit2f53ae347f597842683c4bde5b9ce76f5efae247 (patch)
tree7137a52231c58a003f5aa1430167a9d851dbd15a
parent22ac4318ad95847797de99dccaf059c76cd74efe (diff)
perf top: Add --switch-on/--switch-off events
Just like 'perf trace' and 'perf script', should be useful for instance to only consider samples after the initialization phase of some workload. The man page has some examples and considerations about its current interface, that still doesn't handle the on/off events in a special way, behaving just like when multiple events are specified, i.e.: - In non-group mode (when the event list is not enclosed in {}) show a a menu to allow choosing which event the user wants to see in the histograms browser - In group mode, be it using {} or asking for --group, show one column per event. Try for instance: # perf top -e '{cycles,instructions,probe:icmp_rcv}' --switch-on=probe:icmp_rcv Replace probe:icmp_rcv, that I put in place using: # perf probe icmp_rcv:59 To hit when broadcast packets arrive, with a probe installed after an initialization phase is over or after some other point of interest, some garbage collection, etc, and also use --switch-off, for instance, on a probe installed after said garbage collection is over. 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-c7q7qjeqtyvc9mkeipxza6ne@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/Documentation/perf-top.txt38
-rw-r--r--tools/perf/builtin-top.c10
-rw-r--r--tools/perf/util/top.h2
3 files changed, 49 insertions, 1 deletions
diff --git a/tools/perf/Documentation/perf-top.txt b/tools/perf/Documentation/perf-top.txt
index cfea87c6f38e..5596129a71cf 100644
--- a/tools/perf/Documentation/perf-top.txt
+++ b/tools/perf/Documentation/perf-top.txt
@@ -266,6 +266,44 @@ Default is to monitor all CPUS.
266 Record events of type PERF_RECORD_NAMESPACES and display it with the 266 Record events of type PERF_RECORD_NAMESPACES and display it with the
267 'cgroup_id' sort key. 267 'cgroup_id' sort key.
268 268
269--switch-on EVENT_NAME::
270 Only consider events after this event is found.
271
272 E.g.:
273
274 Find out where broadcast packets are handled
275
276 perf probe -L icmp_rcv
277
278 Insert a probe there:
279
280 perf probe icmp_rcv:59
281
282 Start perf top and ask it to only consider the cycles events when a
283 broadcast packet arrives This will show a menu with two entries and
284 will start counting when a broadcast packet arrives:
285
286 perf top -e cycles,probe:icmp_rcv --switch-on=probe:icmp_rcv
287
288 Alternatively one can ask for --group and then two overhead columns
289 will appear, the first for cycles and the second for the switch-on event.
290
291 perf top --group -e cycles,probe:icmp_rcv --switch-on=probe:icmp_rcv
292
293 This may be interesting to measure a workload only after some initialization
294 phase is over, i.e. insert a perf probe at that point and use the above
295 examples replacing probe:icmp_rcv with the just-after-init probe.
296
297--switch-off EVENT_NAME::
298 Stop considering events after this event is found.
299
300--show-on-off-events::
301 Show the --switch-on/off events too. This has no effect in 'perf top' now
302 but probably we'll make the default not to show the switch-on/off events
303 on the --group mode and if there is only one event besides the off/on ones,
304 go straight to the histogram browser, just like 'perf top' with no events
305 explicitely specified does.
306
269 307
270INTERACTIVE PROMPTING KEYS 308INTERACTIVE PROMPTING KEYS
271-------------------------- 309--------------------------
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 78e7efc597a6..5970723cd55a 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1148,8 +1148,11 @@ static int deliver_event(struct ordered_events *qe,
1148 evsel = perf_evlist__id2evsel(session->evlist, sample.id); 1148 evsel = perf_evlist__id2evsel(session->evlist, sample.id);
1149 assert(evsel != NULL); 1149 assert(evsel != NULL);
1150 1150
1151 if (event->header.type == PERF_RECORD_SAMPLE) 1151 if (event->header.type == PERF_RECORD_SAMPLE) {
1152 if (evswitch__discard(&top->evswitch, evsel))
1153 return 0;
1152 ++top->samples; 1154 ++top->samples;
1155 }
1153 1156
1154 switch (sample.cpumode) { 1157 switch (sample.cpumode) {
1155 case PERF_RECORD_MISC_USER: 1158 case PERF_RECORD_MISC_USER:
@@ -1534,6 +1537,7 @@ int cmd_top(int argc, const char **argv)
1534 "number of thread to run event synthesize"), 1537 "number of thread to run event synthesize"),
1535 OPT_BOOLEAN(0, "namespaces", &opts->record_namespaces, 1538 OPT_BOOLEAN(0, "namespaces", &opts->record_namespaces,
1536 "Record namespaces events"), 1539 "Record namespaces events"),
1540 OPTS_EVSWITCH(&top.evswitch),
1537 OPT_END() 1541 OPT_END()
1538 }; 1542 };
1539 struct evlist *sb_evlist = NULL; 1543 struct evlist *sb_evlist = NULL;
@@ -1567,6 +1571,10 @@ int cmd_top(int argc, const char **argv)
1567 goto out_delete_evlist; 1571 goto out_delete_evlist;
1568 } 1572 }
1569 1573
1574 status = evswitch__init(&top.evswitch, top.evlist, stderr);
1575 if (status)
1576 goto out_delete_evlist;
1577
1570 if (symbol_conf.report_hierarchy) { 1578 if (symbol_conf.report_hierarchy) {
1571 /* disable incompatible options */ 1579 /* disable incompatible options */
1572 symbol_conf.event_group = false; 1580 symbol_conf.event_group = false;
diff --git a/tools/perf/util/top.h b/tools/perf/util/top.h
index 2023e0bf6165..dc4bb6e52a83 100644
--- a/tools/perf/util/top.h
+++ b/tools/perf/util/top.h
@@ -3,6 +3,7 @@
3#define __PERF_TOP_H 1 3#define __PERF_TOP_H 1
4 4
5#include "tool.h" 5#include "tool.h"
6#include "evswitch.h"
6#include "annotate.h" 7#include "annotate.h"
7#include <linux/types.h> 8#include <linux/types.h>
8#include <stddef.h> 9#include <stddef.h>
@@ -18,6 +19,7 @@ struct perf_top {
18 struct evlist *evlist; 19 struct evlist *evlist;
19 struct record_opts record_opts; 20 struct record_opts record_opts;
20 struct annotation_options annotation_opts; 21 struct annotation_options annotation_opts;
22 struct evswitch evswitch;
21 /* 23 /*
22 * Symbols will be added here in perf_event__process_sample and will 24 * Symbols will be added here in perf_event__process_sample and will
23 * get out after decayed. 25 * get out after decayed.