aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2015-11-05 09:40:56 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-12-17 14:21:03 -0500
commit1975d36e14b3314d1d0c7a428946ec0c27fd6e95 (patch)
tree0026f4fbff863a0d780a274df9462799a8db6d30
parentba6039b6c8fcc24de7d6ab7b0bada4becaf84a2c (diff)
perf stat report: Process cpu/threads maps
Adding processing of cpu/threads maps. Configuring session's evlist with these maps. Reported-by: Kan Liang <kan.liang@intel.com> Signed-off-by: Jiri Olsa <jolsa@kernel.org> Cc: David Ahern <dsahern@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/r/1446734469-11352-13-git-send-email-jolsa@kernel.org [ s/stat/st/g, s/time/tm/g parameters to fix 'already defined' build error with older distros (e.g. RHEL6.7) ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/builtin-stat.c66
1 files changed, 64 insertions, 2 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index abba49b847d2..0a1cfdd70df0 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -135,6 +135,9 @@ struct perf_stat {
135 struct perf_session *session; 135 struct perf_session *session;
136 u64 bytes_written; 136 u64 bytes_written;
137 struct perf_tool tool; 137 struct perf_tool tool;
138 bool maps_allocated;
139 struct cpu_map *cpus;
140 struct thread_map *threads;
138}; 141};
139 142
140static struct perf_stat perf_stat; 143static struct perf_stat perf_stat;
@@ -234,9 +237,9 @@ static int process_synthesized_event(struct perf_tool *tool __maybe_unused,
234 return 0; 237 return 0;
235} 238}
236 239
237static int write_stat_round_event(u64 time, u64 type) 240static int write_stat_round_event(u64 tm, u64 type)
238{ 241{
239 return perf_event__synthesize_stat_round(NULL, time, type, 242 return perf_event__synthesize_stat_round(NULL, tm, type,
240 process_synthesized_event, 243 process_synthesized_event,
241 NULL); 244 NULL);
242} 245}
@@ -1530,6 +1533,63 @@ static int __cmd_record(int argc, const char **argv)
1530 return argc; 1533 return argc;
1531} 1534}
1532 1535
1536static int set_maps(struct perf_stat *st)
1537{
1538 if (!st->cpus || !st->threads)
1539 return 0;
1540
1541 if (WARN_ONCE(st->maps_allocated, "stats double allocation\n"))
1542 return -EINVAL;
1543
1544 perf_evlist__set_maps(evsel_list, st->cpus, st->threads);
1545
1546 if (perf_evlist__alloc_stats(evsel_list, true))
1547 return -ENOMEM;
1548
1549 st->maps_allocated = true;
1550 return 0;
1551}
1552
1553static
1554int process_thread_map_event(struct perf_tool *tool __maybe_unused,
1555 union perf_event *event,
1556 struct perf_session *session __maybe_unused)
1557{
1558 struct perf_stat *st = container_of(tool, struct perf_stat, tool);
1559
1560 if (st->threads) {
1561 pr_warning("Extra thread map event, ignoring.\n");
1562 return 0;
1563 }
1564
1565 st->threads = thread_map__new_event(&event->thread_map);
1566 if (!st->threads)
1567 return -ENOMEM;
1568
1569 return set_maps(st);
1570}
1571
1572static
1573int process_cpu_map_event(struct perf_tool *tool __maybe_unused,
1574 union perf_event *event,
1575 struct perf_session *session __maybe_unused)
1576{
1577 struct perf_stat *st = container_of(tool, struct perf_stat, tool);
1578 struct cpu_map *cpus;
1579
1580 if (st->cpus) {
1581 pr_warning("Extra cpu map event, ignoring.\n");
1582 return 0;
1583 }
1584
1585 cpus = cpu_map__new_data(&event->cpu_map.data);
1586 if (!cpus)
1587 return -ENOMEM;
1588
1589 st->cpus = cpus;
1590 return set_maps(st);
1591}
1592
1533static const char * const report_usage[] = { 1593static const char * const report_usage[] = {
1534 "perf stat report [<options>]", 1594 "perf stat report [<options>]",
1535 NULL, 1595 NULL,
@@ -1538,6 +1598,8 @@ static const char * const report_usage[] = {
1538static struct perf_stat perf_stat = { 1598static struct perf_stat perf_stat = {
1539 .tool = { 1599 .tool = {
1540 .attr = perf_event__process_attr, 1600 .attr = perf_event__process_attr,
1601 .thread_map = process_thread_map_event,
1602 .cpu_map = process_cpu_map_event,
1541 }, 1603 },
1542}; 1604};
1543 1605