aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorStephane Eranian <eranian@google.com>2010-05-18 09:00:01 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-05-18 22:03:22 -0400
commit5af52b51f76d8f8dce0e5b2a33c20b2231c8046d (patch)
treeca343ead7bb18f7ad69da2fb4fd4c5e1dcd5d3b1 /tools
parenta13c3afd9b62b6dace80654964cc4ca7d2db8092 (diff)
perf stat: add perf stat -B to pretty print large numbers
It is hard to read very large numbers so provide an option to perf stat to separate thousands using a separator. The patch leverages the locale support of stdio. You need to set your LC_NUMERIC appropriately, for instance LC_NUMERIC=en_US.UTF8. You need to pass -B to activate this feature. This way existing scripts parsing the output do not need to be changed. Here is an example. $ perf stat noploop 2 noploop for 2 seconds Performance counter stats for 'noploop 2': 1998.347031 task-clock-msecs # 0.998 CPUs 61 context-switches # 0.000 M/sec 0 CPU-migrations # 0.000 M/sec 118 page-faults # 0.000 M/sec 4,138,410,900 cycles # 2070.917 M/sec (scaled from 70.01%) 2,062,650,268 instructions # 0.498 IPC (scaled from 70.01%) 2,057,653,466 branches # 1029.678 M/sec (scaled from 70.01%) 40,267 branch-misses # 0.002 % (scaled from 30.04%) 2,055,961,348 cache-references # 1028.831 M/sec (scaled from 30.03%) 53,725 cache-misses # 0.027 M/sec (scaled from 30.02%) 2.001393933 seconds time elapsed $ perf stat -B noploop 2 noploop for 2 seconds Performance counter stats for 'noploop 2': 1998.297883 task-clock-msecs # 0.998 CPUs 59 context-switches # 0.000 M/sec 0 CPU-migrations # 0.000 M/sec 119 page-faults # 0.000 M/sec 4,131,380,160 cycles # 2067.450 M/sec (scaled from 70.01%) 2,059,096,507 instructions # 0.498 IPC (scaled from 70.01%) 2,054,681,303 branches # 1028.216 M/sec (scaled from 70.01%) 25,650 branch-misses # 0.001 % (scaled from 30.05%) 2,056,283,014 cache-references # 1029.017 M/sec (scaled from 30.03%) 47,097 cache-misses # 0.024 M/sec (scaled from 30.02%) 2.001391016 seconds time elapsed Cc: David S. Miller <davem@davemloft.net> Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Tom Zanussi <tzanussi@gmail.com> LKML-Reference: <4bf28fe8.914ed80a.01ca.fffff5f5@mx.google.com> Signed-off-by: Stephane Eranian <eranian@google.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/Documentation/perf-stat.txt3
-rw-r--r--tools/perf/builtin-stat.c18
2 files changed, 17 insertions, 4 deletions
diff --git a/tools/perf/Documentation/perf-stat.txt b/tools/perf/Documentation/perf-stat.txt
index 2cab8e8c33d0..909fa766fa1c 100644
--- a/tools/perf/Documentation/perf-stat.txt
+++ b/tools/perf/Documentation/perf-stat.txt
@@ -43,6 +43,9 @@ OPTIONS
43-c:: 43-c::
44 scale counter values 44 scale counter values
45 45
46-B::
47 print large numbers with thousands' separators according to locale
48
46EXAMPLES 49EXAMPLES
47-------- 50--------
48 51
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index ff8c413b7e73..9a39ca3c3ac4 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -50,6 +50,7 @@
50 50
51#include <sys/prctl.h> 51#include <sys/prctl.h>
52#include <math.h> 52#include <math.h>
53#include <locale.h>
53 54
54static struct perf_event_attr default_attrs[] = { 55static struct perf_event_attr default_attrs[] = {
55 56
@@ -80,6 +81,8 @@ static pid_t *all_tids = NULL;
80static int thread_num = 0; 81static int thread_num = 0;
81static pid_t child_pid = -1; 82static pid_t child_pid = -1;
82static bool null_run = false; 83static bool null_run = false;
84static bool big_num = false;
85
83 86
84static int *fd[MAX_NR_CPUS][MAX_COUNTERS]; 87static int *fd[MAX_NR_CPUS][MAX_COUNTERS];
85 88
@@ -377,7 +380,7 @@ static void nsec_printout(int counter, double avg)
377{ 380{
378 double msecs = avg / 1e6; 381 double msecs = avg / 1e6;
379 382
380 fprintf(stderr, " %14.6f %-24s", msecs, event_name(counter)); 383 fprintf(stderr, " %18.6f %-24s", msecs, event_name(counter));
381 384
382 if (MATCH_EVENT(SOFTWARE, SW_TASK_CLOCK, counter)) { 385 if (MATCH_EVENT(SOFTWARE, SW_TASK_CLOCK, counter)) {
383 fprintf(stderr, " # %10.3f CPUs ", 386 fprintf(stderr, " # %10.3f CPUs ",
@@ -389,7 +392,10 @@ static void abs_printout(int counter, double avg)
389{ 392{
390 double total, ratio = 0.0; 393 double total, ratio = 0.0;
391 394
392 fprintf(stderr, " %14.0f %-24s", avg, event_name(counter)); 395 if (big_num)
396 fprintf(stderr, " %'18.0f %-24s", avg, event_name(counter));
397 else
398 fprintf(stderr, " %18.0f %-24s", avg, event_name(counter));
393 399
394 if (MATCH_EVENT(HARDWARE, HW_INSTRUCTIONS, counter)) { 400 if (MATCH_EVENT(HARDWARE, HW_INSTRUCTIONS, counter)) {
395 total = avg_stats(&runtime_cycles_stats); 401 total = avg_stats(&runtime_cycles_stats);
@@ -426,7 +432,7 @@ static void print_counter(int counter)
426 int scaled = event_scaled[counter]; 432 int scaled = event_scaled[counter];
427 433
428 if (scaled == -1) { 434 if (scaled == -1) {
429 fprintf(stderr, " %14s %-24s\n", 435 fprintf(stderr, " %18s %-24s\n",
430 "<not counted>", event_name(counter)); 436 "<not counted>", event_name(counter));
431 return; 437 return;
432 } 438 }
@@ -477,7 +483,7 @@ static void print_stat(int argc, const char **argv)
477 print_counter(counter); 483 print_counter(counter);
478 484
479 fprintf(stderr, "\n"); 485 fprintf(stderr, "\n");
480 fprintf(stderr, " %14.9f seconds time elapsed", 486 fprintf(stderr, " %18.9f seconds time elapsed",
481 avg_stats(&walltime_nsecs_stats)/1e9); 487 avg_stats(&walltime_nsecs_stats)/1e9);
482 if (run_count > 1) { 488 if (run_count > 1) {
483 fprintf(stderr, " ( +- %7.3f%% )", 489 fprintf(stderr, " ( +- %7.3f%% )",
@@ -534,6 +540,8 @@ static const struct option options[] = {
534 "repeat command and print average + stddev (max: 100)"), 540 "repeat command and print average + stddev (max: 100)"),
535 OPT_BOOLEAN('n', "null", &null_run, 541 OPT_BOOLEAN('n', "null", &null_run,
536 "null run - dont start any counters"), 542 "null run - dont start any counters"),
543 OPT_BOOLEAN('B', "big-num", &big_num,
544 "print large numbers with thousands\' separators"),
537 OPT_END() 545 OPT_END()
538}; 546};
539 547
@@ -542,6 +550,8 @@ int cmd_stat(int argc, const char **argv, const char *prefix __used)
542 int status; 550 int status;
543 int i,j; 551 int i,j;
544 552
553 setlocale(LC_ALL, "");
554
545 argc = parse_options(argc, argv, options, stat_usage, 555 argc = parse_options(argc, argv, options, stat_usage,
546 PARSE_OPT_STOP_AT_NON_OPTION); 556 PARSE_OPT_STOP_AT_NON_OPTION);
547 if (!argc && target_pid == -1 && target_tid == -1) 557 if (!argc && target_pid == -1 && target_tid == -1)