diff options
author | Jiri Olsa <jolsa@kernel.org> | 2015-07-21 08:31:22 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-08-06 15:02:29 -0400 |
commit | 421a50f3fafaf271bb3293378eaafca71337dfec (patch) | |
tree | ccd7ad591cd039b4e31115515013ba8e45b23c46 | |
parent | 5a023b57a8e96327925a39312bccc443a7c540b6 (diff) |
perf stat: Introduce struct perf_stat_config
Moving 'aggr_mode' into new struct. The point is to centralize the base
stat config so it could be used localy together with other stat routines
in other parts of perf code.
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/1437481927-29538-3-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-stat.c | 39 | ||||
-rw-r--r-- | tools/perf/util/stat.h | 4 |
2 files changed, 26 insertions, 17 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index d99d850e1444..bafb830b1bd9 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -102,7 +102,6 @@ static struct target target = { | |||
102 | static int run_count = 1; | 102 | static int run_count = 1; |
103 | static bool no_inherit = false; | 103 | static bool no_inherit = false; |
104 | static bool scale = true; | 104 | static bool scale = true; |
105 | static enum aggr_mode aggr_mode = AGGR_GLOBAL; | ||
106 | static volatile pid_t child_pid = -1; | 105 | static volatile pid_t child_pid = -1; |
107 | static bool null_run = false; | 106 | static bool null_run = false; |
108 | static int detailed_run = 0; | 107 | static int detailed_run = 0; |
@@ -126,6 +125,10 @@ static int (*aggr_get_id)(struct cpu_map *m, int cpu); | |||
126 | 125 | ||
127 | static volatile int done = 0; | 126 | static volatile int done = 0; |
128 | 127 | ||
128 | static struct perf_stat_config stat_config = { | ||
129 | .aggr_mode = AGGR_GLOBAL, | ||
130 | }; | ||
131 | |||
129 | static inline void diff_timespec(struct timespec *r, struct timespec *a, | 132 | static inline void diff_timespec(struct timespec *r, struct timespec *a, |
130 | struct timespec *b) | 133 | struct timespec *b) |
131 | { | 134 | { |
@@ -230,7 +233,7 @@ process_counter_values(struct perf_evsel *evsel, int cpu, int thread, | |||
230 | if (skip) | 233 | if (skip) |
231 | count = &zero; | 234 | count = &zero; |
232 | 235 | ||
233 | switch (aggr_mode) { | 236 | switch (stat_config.aggr_mode) { |
234 | case AGGR_THREAD: | 237 | case AGGR_THREAD: |
235 | case AGGR_CORE: | 238 | case AGGR_CORE: |
236 | case AGGR_SOCKET: | 239 | case AGGR_SOCKET: |
@@ -238,7 +241,7 @@ process_counter_values(struct perf_evsel *evsel, int cpu, int thread, | |||
238 | if (!evsel->snapshot) | 241 | if (!evsel->snapshot) |
239 | perf_evsel__compute_deltas(evsel, cpu, thread, count); | 242 | perf_evsel__compute_deltas(evsel, cpu, thread, count); |
240 | perf_counts_values__scale(count, scale, NULL); | 243 | perf_counts_values__scale(count, scale, NULL); |
241 | if (aggr_mode == AGGR_NONE) | 244 | if (stat_config.aggr_mode == AGGR_NONE) |
242 | perf_stat__update_shadow_stats(evsel, count->values, cpu); | 245 | perf_stat__update_shadow_stats(evsel, count->values, cpu); |
243 | break; | 246 | break; |
244 | case AGGR_GLOBAL: | 247 | case AGGR_GLOBAL: |
@@ -291,7 +294,7 @@ static int process_counter(struct perf_evsel *counter) | |||
291 | if (ret) | 294 | if (ret) |
292 | return ret; | 295 | return ret; |
293 | 296 | ||
294 | if (aggr_mode != AGGR_GLOBAL) | 297 | if (stat_config.aggr_mode != AGGR_GLOBAL) |
295 | return 0; | 298 | return 0; |
296 | 299 | ||
297 | if (!counter->snapshot) | 300 | if (!counter->snapshot) |
@@ -578,7 +581,7 @@ static void print_noise(struct perf_evsel *evsel, double avg) | |||
578 | 581 | ||
579 | static void aggr_printout(struct perf_evsel *evsel, int id, int nr) | 582 | static void aggr_printout(struct perf_evsel *evsel, int id, int nr) |
580 | { | 583 | { |
581 | switch (aggr_mode) { | 584 | switch (stat_config.aggr_mode) { |
582 | case AGGR_CORE: | 585 | case AGGR_CORE: |
583 | fprintf(output, "S%d-C%*d%s%*d%s", | 586 | fprintf(output, "S%d-C%*d%s%*d%s", |
584 | cpu_map__id_to_socket(id), | 587 | cpu_map__id_to_socket(id), |
@@ -670,7 +673,7 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) | |||
670 | 673 | ||
671 | aggr_printout(evsel, id, nr); | 674 | aggr_printout(evsel, id, nr); |
672 | 675 | ||
673 | if (aggr_mode == AGGR_GLOBAL) | 676 | if (stat_config.aggr_mode == AGGR_GLOBAL) |
674 | cpu = 0; | 677 | cpu = 0; |
675 | 678 | ||
676 | fprintf(output, fmt, avg, csv_sep); | 679 | fprintf(output, fmt, avg, csv_sep); |
@@ -688,7 +691,8 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) | |||
688 | if (csv_output || interval) | 691 | if (csv_output || interval) |
689 | return; | 692 | return; |
690 | 693 | ||
691 | perf_stat__print_shadow_stats(output, evsel, avg, cpu, aggr_mode); | 694 | perf_stat__print_shadow_stats(output, evsel, avg, cpu, |
695 | stat_config.aggr_mode); | ||
692 | } | 696 | } |
693 | 697 | ||
694 | static void print_aggr(char *prefix) | 698 | static void print_aggr(char *prefix) |
@@ -909,7 +913,7 @@ static void print_interval(char *prefix, struct timespec *ts) | |||
909 | sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep); | 913 | sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep); |
910 | 914 | ||
911 | if (num_print_interval == 0 && !csv_output) { | 915 | if (num_print_interval == 0 && !csv_output) { |
912 | switch (aggr_mode) { | 916 | switch (stat_config.aggr_mode) { |
913 | case AGGR_SOCKET: | 917 | case AGGR_SOCKET: |
914 | fprintf(output, "# time socket cpus counts %*s events\n", unit_width, "unit"); | 918 | fprintf(output, "# time socket cpus counts %*s events\n", unit_width, "unit"); |
915 | break; | 919 | break; |
@@ -985,7 +989,7 @@ static void print_counters(struct timespec *ts, int argc, const char **argv) | |||
985 | else | 989 | else |
986 | print_header(argc, argv); | 990 | print_header(argc, argv); |
987 | 991 | ||
988 | switch (aggr_mode) { | 992 | switch (stat_config.aggr_mode) { |
989 | case AGGR_CORE: | 993 | case AGGR_CORE: |
990 | case AGGR_SOCKET: | 994 | case AGGR_SOCKET: |
991 | print_aggr(prefix); | 995 | print_aggr(prefix); |
@@ -1064,7 +1068,7 @@ static int stat__set_big_num(const struct option *opt __maybe_unused, | |||
1064 | 1068 | ||
1065 | static int perf_stat_init_aggr_mode(void) | 1069 | static int perf_stat_init_aggr_mode(void) |
1066 | { | 1070 | { |
1067 | switch (aggr_mode) { | 1071 | switch (stat_config.aggr_mode) { |
1068 | case AGGR_SOCKET: | 1072 | case AGGR_SOCKET: |
1069 | if (cpu_map__build_socket_map(evsel_list->cpus, &aggr_map)) { | 1073 | if (cpu_map__build_socket_map(evsel_list->cpus, &aggr_map)) { |
1070 | perror("cannot build socket map"); | 1074 | perror("cannot build socket map"); |
@@ -1286,7 +1290,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1286 | stat__set_big_num), | 1290 | stat__set_big_num), |
1287 | OPT_STRING('C', "cpu", &target.cpu_list, "cpu", | 1291 | OPT_STRING('C', "cpu", &target.cpu_list, "cpu", |
1288 | "list of cpus to monitor in system-wide"), | 1292 | "list of cpus to monitor in system-wide"), |
1289 | OPT_SET_UINT('A', "no-aggr", &aggr_mode, | 1293 | OPT_SET_UINT('A', "no-aggr", &stat_config.aggr_mode, |
1290 | "disable CPU count aggregation", AGGR_NONE), | 1294 | "disable CPU count aggregation", AGGR_NONE), |
1291 | OPT_STRING('x', "field-separator", &csv_sep, "separator", | 1295 | OPT_STRING('x', "field-separator", &csv_sep, "separator", |
1292 | "print counts with custom separator"), | 1296 | "print counts with custom separator"), |
@@ -1302,11 +1306,11 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1302 | "command to run after to the measured command"), | 1306 | "command to run after to the measured command"), |
1303 | OPT_UINTEGER('I', "interval-print", &interval, | 1307 | OPT_UINTEGER('I', "interval-print", &interval, |
1304 | "print counts at regular interval in ms (>= 100)"), | 1308 | "print counts at regular interval in ms (>= 100)"), |
1305 | OPT_SET_UINT(0, "per-socket", &aggr_mode, | 1309 | OPT_SET_UINT(0, "per-socket", &stat_config.aggr_mode, |
1306 | "aggregate counts per processor socket", AGGR_SOCKET), | 1310 | "aggregate counts per processor socket", AGGR_SOCKET), |
1307 | OPT_SET_UINT(0, "per-core", &aggr_mode, | 1311 | OPT_SET_UINT(0, "per-core", &stat_config.aggr_mode, |
1308 | "aggregate counts per physical processor core", AGGR_CORE), | 1312 | "aggregate counts per physical processor core", AGGR_CORE), |
1309 | OPT_SET_UINT(0, "per-thread", &aggr_mode, | 1313 | OPT_SET_UINT(0, "per-thread", &stat_config.aggr_mode, |
1310 | "aggregate counts per thread", AGGR_THREAD), | 1314 | "aggregate counts per thread", AGGR_THREAD), |
1311 | OPT_UINTEGER('D', "delay", &initial_delay, | 1315 | OPT_UINTEGER('D', "delay", &initial_delay, |
1312 | "ms to wait before starting measurement after program start"), | 1316 | "ms to wait before starting measurement after program start"), |
@@ -1399,7 +1403,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1399 | run_count = 1; | 1403 | run_count = 1; |
1400 | } | 1404 | } |
1401 | 1405 | ||
1402 | if ((aggr_mode == AGGR_THREAD) && !target__has_task(&target)) { | 1406 | if ((stat_config.aggr_mode == AGGR_THREAD) && !target__has_task(&target)) { |
1403 | fprintf(stderr, "The --per-thread option is only available " | 1407 | fprintf(stderr, "The --per-thread option is only available " |
1404 | "when monitoring via -p -t options.\n"); | 1408 | "when monitoring via -p -t options.\n"); |
1405 | parse_options_usage(NULL, options, "p", 1); | 1409 | parse_options_usage(NULL, options, "p", 1); |
@@ -1411,7 +1415,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1411 | * no_aggr, cgroup are for system-wide only | 1415 | * no_aggr, cgroup are for system-wide only |
1412 | * --per-thread is aggregated per thread, we dont mix it with cpu mode | 1416 | * --per-thread is aggregated per thread, we dont mix it with cpu mode |
1413 | */ | 1417 | */ |
1414 | if (((aggr_mode != AGGR_GLOBAL && aggr_mode != AGGR_THREAD) || nr_cgroups) && | 1418 | if (((stat_config.aggr_mode != AGGR_GLOBAL && |
1419 | stat_config.aggr_mode != AGGR_THREAD) || nr_cgroups) && | ||
1415 | !target__has_cpu(&target)) { | 1420 | !target__has_cpu(&target)) { |
1416 | fprintf(stderr, "both cgroup and no-aggregation " | 1421 | fprintf(stderr, "both cgroup and no-aggregation " |
1417 | "modes only available in system-wide mode\n"); | 1422 | "modes only available in system-wide mode\n"); |
@@ -1444,7 +1449,7 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1444 | * Initialize thread_map with comm names, | 1449 | * Initialize thread_map with comm names, |
1445 | * so we could print it out on output. | 1450 | * so we could print it out on output. |
1446 | */ | 1451 | */ |
1447 | if (aggr_mode == AGGR_THREAD) | 1452 | if (stat_config.aggr_mode == AGGR_THREAD) |
1448 | thread_map__read_comms(evsel_list->threads); | 1453 | thread_map__read_comms(evsel_list->threads); |
1449 | 1454 | ||
1450 | if (interval && interval < 100) { | 1455 | if (interval && interval < 100) { |
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h index 1cfbe0a980ac..078bee49ccad 100644 --- a/tools/perf/util/stat.h +++ b/tools/perf/util/stat.h | |||
@@ -50,6 +50,10 @@ struct perf_counts { | |||
50 | struct xyarray *values; | 50 | struct xyarray *values; |
51 | }; | 51 | }; |
52 | 52 | ||
53 | struct perf_stat_config { | ||
54 | enum aggr_mode aggr_mode; | ||
55 | }; | ||
56 | |||
53 | static inline struct perf_counts_values* | 57 | static inline struct perf_counts_values* |
54 | perf_counts(struct perf_counts *counts, int cpu, int thread) | 58 | perf_counts(struct perf_counts *counts, int cpu, int thread) |
55 | { | 59 | { |