diff options
author | Anton Blanchard <anton@samba.org> | 2011-07-04 21:57:50 +1000 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2011-07-05 10:44:44 +0200 |
commit | 5d67be97f8903d05ce53597fb5f3bc25a45e8026 (patch) | |
tree | 5ce8c2407d50570d7fee79b9c7f24e8eb89384b4 /tools/perf/util | |
parent | 9f8b6a6cf0ee78de87ebe1e87f54bec1c1741ef7 (diff) |
perf report/annotate/script: Add option to specify a CPU range
Add an option to perf report/annotate/script to specify which
CPUs to operate on. This enables us to take a single system wide
profile and analyse each CPU (or group of CPUs) in isolation.
This was useful when profiling a multiprocess workload where the
bottleneck was on one CPU but this was hidden in the overall
profile. Per process and per thread breakdowns didn't help
because multiple processes were running on each CPU and no
single process consumed an entire CPU.
The patch converts the list of CPUs returned by cpu_map__new
into a bitmap for fast lookup. I wanted to use -C to be
consistent with perf top/record/stat, but unfortunately perf
report already uses -C <comms>.
v2: Incorporate suggestions from David Ahern:
- Added -c to perf script
- Check that SAMPLE_CPU is set when -c is used
- Update documentation
v3: Create perf_session__cpu_bitmap()
Signed-off-by: Anton Blanchard <anton@samba.org>
Acked-by: David Ahern <dsahern@gmail.com>
Cc: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Link: http://lkml.kernel.org/r/20110704215750.11647eb9@kryten
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/session.c | 38 | ||||
-rw-r--r-- | tools/perf/util/session.h | 3 |
2 files changed, 41 insertions, 0 deletions
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 558bcf99694..080e5336d89 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -12,6 +12,7 @@ #include "session.h" #include "sort.h" #include "util.h" +#include "cpumap.h" static int perf_session__open(struct perf_session *self, bool force) { @@ -1282,3 +1283,40 @@ void perf_session__print_ip(union perf_event *event, } } } + +int perf_session__cpu_bitmap(struct perf_session *session, + const char *cpu_list, unsigned long *cpu_bitmap) +{ + int i; + struct cpu_map *map; + + for (i = 0; i < PERF_TYPE_MAX; ++i) { + struct perf_evsel *evsel; + + evsel = perf_session__find_first_evtype(session, i); + if (!evsel) + continue; + + if (!(evsel->attr.sample_type & PERF_SAMPLE_CPU)) { + pr_err("File does not contain CPU events. " + "Remove -c option to proceed.\n"); + return -1; + } + } + + map = cpu_map__new(cpu_list); + + for (i = 0; i < map->nr; i++) { + int cpu = map->map[i]; + + if (cpu >= MAX_NR_CPUS) { + pr_err("Requested CPU %d too large. " + "Consider raising MAX_NR_CPUS\n", cpu); + return -1; + } + + set_bit(cpu, cpu_bitmap); + } + + return 0; +} diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index de4178d7bb7..5de754f4b7f 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -172,4 +172,7 @@ void perf_session__print_ip(union perf_event *event, struct perf_session *session, int print_sym, int print_dso); +int perf_session__cpu_bitmap(struct perf_session *session, + const char *cpu_list, unsigned long *cpu_bitmap); + #endif /* __PERF_SESSION_H */ |