perf stat: Don't print bogus data on -e cycles
authorRamkumar Ramachandra <artagnon@gmail.com>
Mon, 30 Sep 2013 11:13:05 +0000 (16:43 +0530)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 11 Oct 2013 15:17:33 +0000 (12:17 -0300)
When only the cycles event is requested:

$ perf stat -e cycles dd if=/dev/zero of=/dev/null count=1000000
1000000+0 records in
1000000+0 records out
512000000 bytes (512 MB) copied, 0.26123 s, 2.0 GB/s

 Performance counter stats for 'dd if=/dev/zero of=/dev/null count=1000000':

       911,626,453 cycles                    #    0.000 GHz

       0.262113350 seconds time elapsed

The 0.000 GHz comment in the output is totally bogus and misleading. It
happens because update_shadow_stats() doesn't touch runtime_nsecs_stats;
it is only written when a requested counter matches a SW_TASK_CLOCK. In
our case, since we have only requested HW_CPU_CYCLES,
runtime_nsecs_stats is unavailable. So, omit printing the comment
altogether.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
Acked-by: Ingo Molnar <mingo@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1380539585-23859-3-git-send-email-artagnon@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-stat.c

index 700b478491015b6bcfff40f3f299316cc1d4f492..ce2266c5cd52b70179ace9f9df4da5f518e28d1d 100644 (file)
@@ -997,10 +997,10 @@ static void abs_printout(int cpu, int nr, struct perf_evsel *evsel, double avg)
        } else if (perf_evsel__match(evsel, HARDWARE, HW_CPU_CYCLES)) {
                total = avg_stats(&runtime_nsecs_stats[cpu]);
 
-               if (total)
-                       ratio = 1.0 * avg / total;
-
-               fprintf(output, " # %8.3f GHz                    ", ratio);
+               if (total) {
+                       ratio = avg / total;
+                       fprintf(output, " # %8.3f GHz                    ", ratio);
+               }
        } else if (transaction_run &&
                   perf_evsel__cmp(evsel, nth_evsel(T_CYCLES_IN_TX))) {
                total = avg_stats(&runtime_cycles_stats[cpu]);