Messages in this thread Patch in this message | | | From | Kan Liang <> | Subject | [PATCH V2 3/6] perf,tools: get real cpu id for print_aggr | Date | Wed, 15 Apr 2015 03:56:13 -0400 |
| |
From: Kan Liang <kan.liang@intel.com>
Events don't share the same evlist->cpus anymore. So same cpu id may have different index in different evsel_list->cpus. In print_aggr, aggr_get_id needs index to get core/pkg id. perf_evsel__get_cpumap_index is introduced to get the index by cpu id.
Signed-off-by: Kan Liang <kan.liang@intel.com> ---
Changes since V1 - Rebase to Arnaldo's code
For pure invalid context event group, using leader's pmu as event members pmu.
tools/perf/builtin-stat.c | 1 + tools/perf/util/cpumap.c | 4 ++-- tools/perf/util/evsel.c | 14 ++++++++++++++ tools/perf/util/evsel.h | 3 +++ 4 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 2c1456e..c4f8fd2 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c @@ -1231,6 +1231,7 @@ static void print_aggr(char *prefix) nr = 0; for (cpu = 0; cpu < cpu_map__nr(counter->cpus); cpu++) { cpu2 = counter->cpus->map[cpu]; + cpu2 = perf_evsel__get_cpumap_index(cpu2, evsel_list->cpus); s2 = aggr_get_id(evsel_list->cpus, cpu2); if (s2 != id) continue; diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index c4e55b7..82f3ea8 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -211,7 +211,7 @@ int cpu_map__get_socket(struct cpu_map *map, int idx) char path[PATH_MAX]; int cpu, ret; - if (idx > map->nr) + if ((idx > map->nr) || (idx < 0)) return -1; cpu = map->map[idx]; @@ -274,7 +274,7 @@ int cpu_map__get_core(struct cpu_map *map, int idx) char path[PATH_MAX]; int cpu, ret, s; - if (idx > map->nr) + if ((idx > map->nr) || (idx < 0)) return -1; cpu = map->map[idx]; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 33e3fd8..e177f43 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -991,6 +991,20 @@ int __perf_evsel__read_on_cpu(struct perf_evsel *evsel, return 0; } +int perf_evsel__get_cpumap_index(int cpu, struct cpu_map *evsel_cpus) +{ + int i; + + if (evsel_cpus == NULL) + return -1; + + for (i = 0; i < evsel_cpus->nr; i++) { + if (cpu == evsel_cpus->map[i]) + return i; + } + return -1; +} + static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread) { struct perf_evsel *leader = evsel->leader; diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index e486151..5e9d347 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -8,6 +8,7 @@ #include <linux/types.h> #include "xyarray.h" #include "symbol.h" +#include "cpumap.h" struct perf_counts_values { union { @@ -366,4 +367,6 @@ typedef int (*attr__fprintf_f)(FILE *, const char *, const char *, void *); int perf_event_attr__fprintf(FILE *fp, struct perf_event_attr *attr, attr__fprintf_f attr__fprintf, void *priv); +int perf_evsel__get_cpumap_index(int cpu, struct cpu_map *evsel_cpus); + #endif /* __PERF_EVSEL_H */ -- 1.8.3.1
| |