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>
used. This interfaces starts by centering on the line with more
samples, TAB/UNTAB cycles through the lines with more samples.
+-c::
+--cpu:: Only report samples for the list of CPUs provided. Multiple CPUs can
+ be provided as a comma-separated list with no space: 0,1. Ranges of
+ CPUs are specified with -: 0-2. Default is to report samples on all
+ CPUs.
+
SEE ALSO
--------
linkperf:perf-record[1], linkperf:perf-report[1]
--symfs=<directory>::
Look for files with symbols relative to this directory.
+-c::
+--cpu:: Only report samples for the list of CPUs provided. Multiple CPUs can
+ be provided as a comma-separated list with no space: 0,1. Ranges of
+ CPUs are specified with -: 0-2. Default is to report samples on all
+ CPUs.
+
SEE ALSO
--------
linkperf:perf-stat[1]
--hide-call-graph::
When printing symbols do not display call chain.
+-c::
+--cpu:: Only report samples for the list of CPUs provided. Multiple CPUs can
+ be provided as a comma-separated list with no space: 0,1. Ranges of
+ CPUs are specified with -: 0-2. Default is to report samples on all
+ CPUs.
+
SEE ALSO
--------
linkperf:perf-record[1], linkperf:perf-script-perl[1],
#include "util/hist.h"
#include "util/session.h"
+#include <linux/bitmap.h>
+
static char const *input_name = "perf.data";
static bool force, use_tui, use_stdio;
static const char *sym_hist_filter;
+static const char *cpu_list;
+static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
+
static int perf_evlist__add_sample(struct perf_evlist *evlist,
struct perf_sample *sample,
struct perf_evsel *evsel,
return -1;
}
+ if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
+ return 0;
+
if (!al.filtered &&
perf_evlist__add_sample(session->evlist, sample, evsel, &al)) {
pr_warning("problem incrementing symbol count, "
if (session == NULL)
return -ENOMEM;
+ if (cpu_list) {
+ ret = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap);
+ if (ret)
+ goto out_delete;
+ }
+
ret = perf_session__process_events(session, &event_ops);
if (ret)
goto out_delete;
"print matching source lines (may be slow)"),
OPT_BOOLEAN('P', "full-paths", &full_paths,
"Don't shorten the displayed pathnames"),
+ OPT_STRING('c', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
OPT_END()
};
#include "util/sort.h"
#include "util/hist.h"
+#include <linux/bitmap.h>
+
static char const *input_name = "perf.data";
static bool force, use_tui, use_stdio;
static bool inverted_callchain;
static symbol_filter_t annotate_init;
+static const char *cpu_list;
+static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
+
static int perf_session__add_hist_entry(struct perf_session *session,
struct addr_location *al,
struct perf_sample *sample,
if (al.filtered || (hide_unresolved && al.sym == NULL))
return 0;
+ if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
+ return 0;
+
if (al.map != NULL)
al.map->dso->hit = 1;
if (session == NULL)
return -ENOMEM;
+ if (cpu_list) {
+ ret = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap);
+ if (ret)
+ goto out_delete;
+ }
+
if (show_threads)
perf_read_values_init(&show_threads_values);
"Only display entries resolved to a symbol"),
OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
"Look for files with symbols relative to this directory"),
+ OPT_STRING('c', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
OPT_END()
};
#include "util/util.h"
#include "util/evlist.h"
#include "util/evsel.h"
+#include <linux/bitmap.h>
static char const *script_name;
static char const *generate_script_lang;
static u64 nr_unordered;
extern const struct option record_options[];
static bool no_callchain;
+static const char *cpu_list;
+static DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
enum perf_output_field {
PERF_OUTPUT_COMM = 1U << 0,
last_timestamp = sample->time;
return 0;
}
+
+ if (cpu_list && !test_bit(sample->cpu, cpu_bitmap))
+ return 0;
+
scripting_ops->process_event(event, sample, evsel, session, thread);
session->hists.stats.total_period += sample->period;
OPT_CALLBACK('f', "fields", NULL, "str",
"comma separated output fields prepend with 'type:'. Valid types: hw,sw,trace,raw. Fields: comm,tid,pid,time,cpu,event,trace,ip,sym,dso,addr",
parse_output_fields),
+ OPT_STRING('c', "cpu", &cpu_list, "cpu", "list of cpus to profile"),
OPT_END()
};
if (session == NULL)
return -ENOMEM;
+ if (cpu_list) {
+ if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap))
+ return -1;
+ }
+
if (!no_callchain)
symbol_conf.use_callchain = true;
else
#include "session.h"
#include "sort.h"
#include "util.h"
+#include "cpumap.h"
static int perf_session__open(struct perf_session *self, bool force)
{
}
}
}
+
+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;
+}
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 */