Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932279AbbGUMd2 (ORCPT ); Tue, 21 Jul 2015 08:33:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51203 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932201AbbGUMdQ (ORCPT ); Tue, 21 Jul 2015 08:33:16 -0400 From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , David Ahern , Ingo Molnar , Namhyung Kim , Peter Zijlstra Subject: [PATCH 36/47] perf stat report: Process cpu/threads maps Date: Tue, 21 Jul 2015 14:31:56 +0200 Message-Id: <1437481927-29538-37-git-send-email-jolsa@kernel.org> In-Reply-To: <1437481927-29538-1-git-send-email-jolsa@kernel.org> References: <1437481927-29538-1-git-send-email-jolsa@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2774 Lines: 101 Adding processing of cpu/threads maps. Configuring session's evlist with these maps. Link: http://lkml.kernel.org/n/tip-f2bo5wm0cw76zc5qsjm4pztx@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/builtin-stat.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index aa2352f92878..a1a5e5b2b69c 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -142,6 +142,9 @@ static struct perf_stat_config stat_config = { struct perf_stat_cmd { struct perf_tool tool; + bool allocated; + struct cpu_map *cpus; + struct thread_map *threads; }; static inline void diff_timespec(struct timespec *r, struct timespec *a, @@ -1328,6 +1331,60 @@ static int __cmd_record(int argc, const char **argv) return argc; } +static int set_maps(struct perf_stat_cmd *stat) +{ + if (!stat->cpus || !stat->threads) + return 0; + + if (WARN_ONCE(stat->allocated, "stats double allocation\n")) + return -EINVAL; + + if (perf_evlist__set_maps(evsel_list, stat->cpus, stat->threads) || + perf_evlist__alloc_stats(evsel_list, true)) + return -ENOMEM; + + stat->allocated = true; + return 0; +} + +static +int process_thread_map_event(struct perf_tool *tool __maybe_unused, + union perf_event *event, + struct perf_session *session __maybe_unused) +{ + struct perf_stat_cmd *stat = container_of(tool, struct perf_stat_cmd, tool); + + if (stat->threads) { + pr_warning("Extra thread map event, ignoring.\n"); + return 0; + } + + stat->threads = thread_map__new_event(&event->thread_map); + if (!stat->threads) + return -ENOMEM; + + return set_maps(stat); +} + +static +int process_cpu_map_event(struct perf_tool *tool __maybe_unused, + union perf_event *event, + struct perf_session *session __maybe_unused) +{ + struct perf_stat_cmd *stat = container_of(tool, struct perf_stat_cmd, tool); + + if (stat->cpus) { + pr_warning("Extra cpu map event, ignoring.\n"); + return 0; + } + + stat->cpus = cpu_map__new_event(&event->cpu_map); + if (!stat->cpus) + return -ENOMEM; + + return set_maps(stat); +} + static const char * const report_usage[] = { "perf stat report []", NULL, @@ -1346,6 +1403,8 @@ static int __cmd_report(int argc, const char **argv) struct perf_stat_cmd stat = { .tool = { .attr = perf_event__process_attr, + .thread_map = process_thread_map_event, + .cpu_map = process_cpu_map_event, }, }; int ret; -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/