diff options
author | Jiri Olsa <jolsa@kernel.org> | 2015-11-05 09:40:58 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-12-17 14:28:43 -0500 |
commit | 68d702f7a1202dd39d9fa01b7bea92ba9e5785d9 (patch) | |
tree | d1ea4de2349568c9a27271be36dcf14ddd2b98eb /tools/perf | |
parent | 62ba18ba938a8740ab18e02342b282d7378986f7 (diff) |
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 <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-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 <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r-- | tools/perf/builtin-stat.c | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 1e5db50dab9e..c78052580023 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) | |||
1326 | cpus_aggr_map = NULL; | 1326 | cpus_aggr_map = NULL; |
1327 | } | 1327 | } |
1328 | 1328 | ||
1329 | static inline int perf_env__get_cpu(struct perf_env *env, struct cpu_map *map, int idx) | ||
1330 | { | ||
1331 | int cpu; | ||
1332 | |||
1333 | if (idx > map->nr) | ||
1334 | return -1; | ||
1335 | |||
1336 | cpu = map->map[idx]; | ||
1337 | |||
1338 | if (cpu >= env->nr_cpus_online) | ||
1339 | return -1; | ||
1340 | |||
1341 | return cpu; | ||
1342 | } | ||
1343 | |||
1344 | static int perf_env__get_socket(struct cpu_map *map, int idx, void *data) | ||
1345 | { | ||
1346 | struct perf_env *env = data; | ||
1347 | int cpu = perf_env__get_cpu(env, map, idx); | ||
1348 | |||
1349 | return cpu == -1 ? -1 : env->cpu[cpu].socket_id; | ||
1350 | } | ||
1351 | |||
1352 | static int perf_env__get_core(struct cpu_map *map, int idx, void *data) | ||
1353 | { | ||
1354 | struct perf_env *env = data; | ||
1355 | int core = -1, cpu = perf_env__get_cpu(env, map, idx); | ||
1356 | |||
1357 | if (cpu != -1) { | ||
1358 | int socket_id = env->cpu[cpu].socket_id; | ||
1359 | |||
1360 | /* | ||
1361 | * Encode socket in upper 16 bits | ||
1362 | * core_id is relative to socket, and | ||
1363 | * we need a global id. So we combine | ||
1364 | * socket + core id. | ||
1365 | */ | ||
1366 | core = (socket_id << 16) | (env->cpu[cpu].core_id & 0xffff); | ||
1367 | } | ||
1368 | |||
1369 | return core; | ||
1370 | } | ||
1371 | |||
1372 | static int perf_env__build_socket_map(struct perf_env *env, struct cpu_map *cpus, | ||
1373 | struct cpu_map **sockp) | ||
1374 | { | ||
1375 | return cpu_map__build_map(cpus, sockp, perf_env__get_socket, env); | ||
1376 | } | ||
1377 | |||
1378 | static int perf_env__build_core_map(struct perf_env *env, struct cpu_map *cpus, | ||
1379 | struct cpu_map **corep) | ||
1380 | { | ||
1381 | return cpu_map__build_map(cpus, corep, perf_env__get_core, env); | ||
1382 | } | ||
1383 | |||
1384 | static int perf_stat__get_socket_file(struct cpu_map *map, int idx) | ||
1385 | { | ||
1386 | return perf_env__get_socket(map, idx, &perf_stat.session->header.env); | ||
1387 | } | ||
1388 | |||
1389 | static int perf_stat__get_core_file(struct cpu_map *map, int idx) | ||
1390 | { | ||
1391 | return perf_env__get_core(map, idx, &perf_stat.session->header.env); | ||
1392 | } | ||
1393 | |||
1394 | static int perf_stat_init_aggr_mode_file(struct perf_stat *st) | ||
1395 | { | ||
1396 | struct perf_env *env = &st->session->header.env; | ||
1397 | |||
1398 | switch (stat_config.aggr_mode) { | ||
1399 | case AGGR_SOCKET: | ||
1400 | if (perf_env__build_socket_map(env, evsel_list->cpus, &aggr_map)) { | ||
1401 | perror("cannot build socket map"); | ||
1402 | return -1; | ||
1403 | } | ||
1404 | aggr_get_id = perf_stat__get_socket_file; | ||
1405 | break; | ||
1406 | case AGGR_CORE: | ||
1407 | if (perf_env__build_core_map(env, evsel_list->cpus, &aggr_map)) { | ||
1408 | perror("cannot build core map"); | ||
1409 | return -1; | ||
1410 | } | ||
1411 | aggr_get_id = perf_stat__get_core_file; | ||
1412 | break; | ||
1413 | case AGGR_NONE: | ||
1414 | case AGGR_GLOBAL: | ||
1415 | case AGGR_THREAD: | ||
1416 | case AGGR_UNSET: | ||
1417 | default: | ||
1418 | break; | ||
1419 | } | ||
1420 | |||
1421 | return 0; | ||
1422 | } | ||
1423 | |||
1329 | /* | 1424 | /* |
1330 | * Add default attributes, if there were no attributes specified or | 1425 | * Add default attributes, if there were no attributes specified or |
1331 | * if -d/--detailed, -d -d or -d -d -d is used: | 1426 | * 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, | |||
1538 | union perf_event *event, | 1633 | union perf_event *event, |
1539 | struct perf_session *session __maybe_unused) | 1634 | struct perf_session *session __maybe_unused) |
1540 | { | 1635 | { |
1636 | struct perf_stat *st = container_of(tool, struct perf_stat, tool); | ||
1637 | |||
1541 | perf_event__read_stat_config(&stat_config, &event->stat_config); | 1638 | perf_event__read_stat_config(&stat_config, &event->stat_config); |
1639 | |||
1640 | if (perf_stat.file.is_pipe) | ||
1641 | perf_stat_init_aggr_mode(); | ||
1642 | else | ||
1643 | perf_stat_init_aggr_mode_file(st); | ||
1644 | |||
1542 | return 0; | 1645 | return 0; |
1543 | } | 1646 | } |
1544 | 1647 | ||