diff options
author | Jiri Olsa <jolsa@kernel.org> | 2015-06-26 05:29:26 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-06-26 11:00:50 -0400 |
commit | d4f63a4741a808c0bf25d92884713008706fca16 (patch) | |
tree | ab7344ddf4149181e82fae0fe5127ee4bf2a9b27 | |
parent | 5835e2286583e4fa6c2a609446e1320e7da2b161 (diff) |
perf stat: Introduce print_counters function
Centralize counters print code into single print_counters function.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1435310967-14570-22-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/builtin-stat.c | 127 |
1 files changed, 64 insertions, 63 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c index 39a97ade2cf3..56dc8881cb05 100644 --- a/tools/perf/builtin-stat.c +++ b/tools/perf/builtin-stat.c | |||
@@ -67,10 +67,7 @@ | |||
67 | #define CNTR_NOT_SUPPORTED "<not supported>" | 67 | #define CNTR_NOT_SUPPORTED "<not supported>" |
68 | #define CNTR_NOT_COUNTED "<not counted>" | 68 | #define CNTR_NOT_COUNTED "<not counted>" |
69 | 69 | ||
70 | static void print_stat(int argc, const char **argv); | 70 | static void print_counters(struct timespec *ts, int argc, const char **argv); |
71 | static void print_counter_aggr(struct perf_evsel *counter, char *prefix); | ||
72 | static void print_counter(struct perf_evsel *counter, char *prefix); | ||
73 | static void print_aggr(char *prefix); | ||
74 | 71 | ||
75 | /* Default events used for perf stat -T */ | 72 | /* Default events used for perf stat -T */ |
76 | static const char *transaction_attrs = { | 73 | static const char *transaction_attrs = { |
@@ -365,53 +362,14 @@ static void read_counters(bool close) | |||
365 | 362 | ||
366 | static void process_interval(void) | 363 | static void process_interval(void) |
367 | { | 364 | { |
368 | static int num_print_interval; | ||
369 | struct perf_evsel *counter; | ||
370 | struct timespec ts, rs; | 365 | struct timespec ts, rs; |
371 | char prefix[64]; | ||
372 | 366 | ||
373 | read_counters(false); | 367 | read_counters(false); |
374 | 368 | ||
375 | clock_gettime(CLOCK_MONOTONIC, &ts); | 369 | clock_gettime(CLOCK_MONOTONIC, &ts); |
376 | diff_timespec(&rs, &ts, &ref_time); | 370 | diff_timespec(&rs, &ts, &ref_time); |
377 | sprintf(prefix, "%6lu.%09lu%s", rs.tv_sec, rs.tv_nsec, csv_sep); | ||
378 | |||
379 | if (num_print_interval == 0 && !csv_output) { | ||
380 | switch (aggr_mode) { | ||
381 | case AGGR_SOCKET: | ||
382 | fprintf(output, "# time socket cpus counts %*s events\n", unit_width, "unit"); | ||
383 | break; | ||
384 | case AGGR_CORE: | ||
385 | fprintf(output, "# time core cpus counts %*s events\n", unit_width, "unit"); | ||
386 | break; | ||
387 | case AGGR_NONE: | ||
388 | fprintf(output, "# time CPU counts %*s events\n", unit_width, "unit"); | ||
389 | break; | ||
390 | case AGGR_GLOBAL: | ||
391 | default: | ||
392 | fprintf(output, "# time counts %*s events\n", unit_width, "unit"); | ||
393 | } | ||
394 | } | ||
395 | |||
396 | if (++num_print_interval == 25) | ||
397 | num_print_interval = 0; | ||
398 | 371 | ||
399 | switch (aggr_mode) { | 372 | print_counters(&rs, 0, NULL); |
400 | case AGGR_CORE: | ||
401 | case AGGR_SOCKET: | ||
402 | print_aggr(prefix); | ||
403 | break; | ||
404 | case AGGR_NONE: | ||
405 | evlist__for_each(evsel_list, counter) | ||
406 | print_counter(counter, prefix); | ||
407 | break; | ||
408 | case AGGR_GLOBAL: | ||
409 | default: | ||
410 | evlist__for_each(evsel_list, counter) | ||
411 | print_counter_aggr(counter, prefix); | ||
412 | } | ||
413 | |||
414 | fflush(output); | ||
415 | } | 373 | } |
416 | 374 | ||
417 | static void handle_initial_delay(void) | 375 | static void handle_initial_delay(void) |
@@ -901,9 +859,35 @@ static void print_counter(struct perf_evsel *counter, char *prefix) | |||
901 | } | 859 | } |
902 | } | 860 | } |
903 | 861 | ||
904 | static void print_stat(int argc, const char **argv) | 862 | static void print_interval(char *prefix, struct timespec *ts) |
863 | { | ||
864 | static int num_print_interval; | ||
865 | |||
866 | sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep); | ||
867 | |||
868 | if (num_print_interval == 0 && !csv_output) { | ||
869 | switch (aggr_mode) { | ||
870 | case AGGR_SOCKET: | ||
871 | fprintf(output, "# time socket cpus counts %*s events\n", unit_width, "unit"); | ||
872 | break; | ||
873 | case AGGR_CORE: | ||
874 | fprintf(output, "# time core cpus counts %*s events\n", unit_width, "unit"); | ||
875 | break; | ||
876 | case AGGR_NONE: | ||
877 | fprintf(output, "# time CPU counts %*s events\n", unit_width, "unit"); | ||
878 | break; | ||
879 | case AGGR_GLOBAL: | ||
880 | default: | ||
881 | fprintf(output, "# time counts %*s events\n", unit_width, "unit"); | ||
882 | } | ||
883 | } | ||
884 | |||
885 | if (++num_print_interval == 25) | ||
886 | num_print_interval = 0; | ||
887 | } | ||
888 | |||
889 | static void print_header(int argc, const char **argv) | ||
905 | { | 890 | { |
906 | struct perf_evsel *counter; | ||
907 | int i; | 891 | int i; |
908 | 892 | ||
909 | fflush(stdout); | 893 | fflush(stdout); |
@@ -929,36 +913,53 @@ static void print_stat(int argc, const char **argv) | |||
929 | fprintf(output, " (%d runs)", run_count); | 913 | fprintf(output, " (%d runs)", run_count); |
930 | fprintf(output, ":\n\n"); | 914 | fprintf(output, ":\n\n"); |
931 | } | 915 | } |
916 | } | ||
917 | |||
918 | static void print_footer(void) | ||
919 | { | ||
920 | if (!null_run) | ||
921 | fprintf(output, "\n"); | ||
922 | fprintf(output, " %17.9f seconds time elapsed", | ||
923 | avg_stats(&walltime_nsecs_stats)/1e9); | ||
924 | if (run_count > 1) { | ||
925 | fprintf(output, " "); | ||
926 | print_noise_pct(stddev_stats(&walltime_nsecs_stats), | ||
927 | avg_stats(&walltime_nsecs_stats)); | ||
928 | } | ||
929 | fprintf(output, "\n\n"); | ||
930 | } | ||
931 | |||
932 | static void print_counters(struct timespec *ts, int argc, const char **argv) | ||
933 | { | ||
934 | struct perf_evsel *counter; | ||
935 | char buf[64], *prefix = NULL; | ||
936 | |||
937 | if (interval) | ||
938 | print_interval(prefix = buf, ts); | ||
939 | else | ||
940 | print_header(argc, argv); | ||
932 | 941 | ||
933 | switch (aggr_mode) { | 942 | switch (aggr_mode) { |
934 | case AGGR_CORE: | 943 | case AGGR_CORE: |
935 | case AGGR_SOCKET: | 944 | case AGGR_SOCKET: |
936 | print_aggr(NULL); | 945 | print_aggr(prefix); |
937 | break; | 946 | break; |
938 | case AGGR_GLOBAL: | 947 | case AGGR_GLOBAL: |
939 | evlist__for_each(evsel_list, counter) | 948 | evlist__for_each(evsel_list, counter) |
940 | print_counter_aggr(counter, NULL); | 949 | print_counter_aggr(counter, prefix); |
941 | break; | 950 | break; |
942 | case AGGR_NONE: | 951 | case AGGR_NONE: |
943 | evlist__for_each(evsel_list, counter) | 952 | evlist__for_each(evsel_list, counter) |
944 | print_counter(counter, NULL); | 953 | print_counter(counter, prefix); |
945 | break; | 954 | break; |
946 | default: | 955 | default: |
947 | break; | 956 | break; |
948 | } | 957 | } |
949 | 958 | ||
950 | if (!csv_output) { | 959 | if (!interval && !csv_output) |
951 | if (!null_run) | 960 | print_footer(); |
952 | fprintf(output, "\n"); | 961 | |
953 | fprintf(output, " %17.9f seconds time elapsed", | 962 | fflush(output); |
954 | avg_stats(&walltime_nsecs_stats)/1e9); | ||
955 | if (run_count > 1) { | ||
956 | fprintf(output, " "); | ||
957 | print_noise_pct(stddev_stats(&walltime_nsecs_stats), | ||
958 | avg_stats(&walltime_nsecs_stats)); | ||
959 | } | ||
960 | fprintf(output, "\n\n"); | ||
961 | } | ||
962 | } | 963 | } |
963 | 964 | ||
964 | static volatile int signr = -1; | 965 | static volatile int signr = -1; |
@@ -1407,13 +1408,13 @@ int cmd_stat(int argc, const char **argv, const char *prefix __maybe_unused) | |||
1407 | 1408 | ||
1408 | status = run_perf_stat(argc, argv); | 1409 | status = run_perf_stat(argc, argv); |
1409 | if (forever && status != -1) { | 1410 | if (forever && status != -1) { |
1410 | print_stat(argc, argv); | 1411 | print_counters(NULL, argc, argv); |
1411 | perf_stat__reset_stats(); | 1412 | perf_stat__reset_stats(); |
1412 | } | 1413 | } |
1413 | } | 1414 | } |
1414 | 1415 | ||
1415 | if (!forever && status != -1 && !interval) | 1416 | if (!forever && status != -1 && !interval) |
1416 | print_stat(argc, argv); | 1417 | print_counters(NULL, argc, argv); |
1417 | 1418 | ||
1418 | perf_evlist__free_stats(evsel_list); | 1419 | perf_evlist__free_stats(evsel_list); |
1419 | out: | 1420 | out: |