Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966852AbbLRJUd (ORCPT ); Fri, 18 Dec 2015 04:20:33 -0500 Received: from terminus.zytor.com ([198.137.202.10]:52572 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934782AbbLRJNF (ORCPT ); Fri, 18 Dec 2015 04:13:05 -0500 Date: Fri, 18 Dec 2015 01:12:48 -0800 From: tip-bot for Jiri Olsa Message-ID: Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@kernel.org, acme@redhat.com, jolsa@kernel.org, hpa@zytor.com, dsahern@gmail.com, a.p.zijlstra@chello.nl, kan.liang@intel.com, namhyung@kernel.org Reply-To: namhyung@kernel.org, kan.liang@intel.com, a.p.zijlstra@chello.nl, dsahern@gmail.com, hpa@zytor.com, jolsa@kernel.org, acme@redhat.com, tglx@linutronix.de, mingo@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <1446734469-11352-15-git-send-email-jolsa@kernel.org> References: <1446734469-11352-15-git-send-email-jolsa@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf stat report: Add support to initialize aggr_map from file Git-Commit-ID: 68d702f7a1202dd39d9fa01b7bea92ba9e5785d9 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4382 Lines: 150 Commit-ID: 68d702f7a1202dd39d9fa01b7bea92ba9e5785d9 Gitweb: http://git.kernel.org/tip/68d702f7a1202dd39d9fa01b7bea92ba9e5785d9 Author: Jiri Olsa AuthorDate: Thu, 5 Nov 2015 15:40:58 +0100 Committer: Arnaldo Carvalho de Melo CommitDate: Thu, 17 Dec 2015 16:28:43 -0300 perf stat report: Add support to initialize aggr_map from file Using perf.data's perf_env data to initialize aggregate config. Reported-by: Kan Liang Signed-off-by: Jiri Olsa Cc: David Ahern Cc: Namhyung Kim Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1446734469-11352-15-git-send-email-jolsa@kernel.org [ s/stat/st/g, s/socket/socket_id/g to fix 'already defined' build error with older distros (e.g. RHEL6.7) ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-stat.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 1e5db50..c780525 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1326,6 +1326,101 @@ static void perf_stat__exit_aggr_mode(void) cpus_aggr_map = NULL; } +static inline int perf_env__get_cpu(struct perf_env *env, struct cpu_map *map, int idx) +{ + int cpu; + + if (idx > map->nr) + return -1; + + cpu = map->map[idx]; + + if (cpu >= env->nr_cpus_online) + return -1; + + return cpu; +} + +static int perf_env__get_socket(struct cpu_map *map, int idx, void *data) +{ + struct perf_env *env = data; + int cpu = perf_env__get_cpu(env, map, idx); + + return cpu == -1 ? -1 : env->cpu[cpu].socket_id; +} + +static int perf_env__get_core(struct cpu_map *map, int idx, void *data) +{ + struct perf_env *env = data; + int core = -1, cpu = perf_env__get_cpu(env, map, idx); + + if (cpu != -1) { + int socket_id = env->cpu[cpu].socket_id; + + /* + * Encode socket in upper 16 bits + * core_id is relative to socket, and + * we need a global id. So we combine + * socket + core id. + */ + core = (socket_id << 16) | (env->cpu[cpu].core_id & 0xffff); + } + + return core; +} + +static int perf_env__build_socket_map(struct perf_env *env, struct cpu_map *cpus, + struct cpu_map **sockp) +{ + return cpu_map__build_map(cpus, sockp, perf_env__get_socket, env); +} + +static int perf_env__build_core_map(struct perf_env *env, struct cpu_map *cpus, + struct cpu_map **corep) +{ + return cpu_map__build_map(cpus, corep, perf_env__get_core, env); +} + +static int perf_stat__get_socket_file(struct cpu_map *map, int idx) +{ + return perf_env__get_socket(map, idx, &perf_stat.session->header.env); +} + +static int perf_stat__get_core_file(struct cpu_map *map, int idx) +{ + return perf_env__get_core(map, idx, &perf_stat.session->header.env); +} + +static int perf_stat_init_aggr_mode_file(struct perf_stat *st) +{ + struct perf_env *env = &st->session->header.env; + + switch (stat_config.aggr_mode) { + case AGGR_SOCKET: + if (perf_env__build_socket_map(env, evsel_list->cpus, &aggr_map)) { + perror("cannot build socket map"); + return -1; + } + aggr_get_id = perf_stat__get_socket_file; + break; + case AGGR_CORE: + if (perf_env__build_core_map(env, evsel_list->cpus, &aggr_map)) { + perror("cannot build core map"); + return -1; + } + aggr_get_id = perf_stat__get_core_file; + break; + case AGGR_NONE: + case AGGR_GLOBAL: + case AGGR_THREAD: + case AGGR_UNSET: + default: + break; + } + + return 0; +} + /* * Add default attributes, if there were no attributes specified or * if -d/--detailed, -d -d or -d -d -d is used: @@ -1538,7 +1633,15 @@ int process_stat_config_event(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_session *session __maybe_unused) { + struct perf_stat *st = container_of(tool, struct perf_stat, tool); + perf_event__read_stat_config(&stat_config, &event->stat_config); + + if (perf_stat.file.is_pipe) + perf_stat_init_aggr_mode(); + else + perf_stat_init_aggr_mode_file(st); + return 0; } -- 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/