Skip to content

Commit

Permalink
perf stat: Do not print ratio when task-clock event is not counted
Browse files Browse the repository at this point in the history
The ratio between the number of events and the time elapsed makes
sense only if task-clock event is counted. Otherwise it will be
simply a (confusing)

	#      0.000 M/sec

This patch outputs the ratio only if task-clock event is counted.
Some test examples of before and after:

Before:

 [lucas@skywalker linux.trees.git]$ sudo perf stat -e branch-misses -a -- sleep 1

	 Performance counter stats for 'sleep 1':

		1367818  branch-misses            #      0.000 M/sec

	    1.001494325  seconds time elapsed

After (without task-clock):

 [lucas@skywalker perf]$ sudo ./perf stat -e branch-misses -a -- sleep 1

	 Performance counter stats for 'sleep 1':

		1135044  branch-misses

	    1.001370775  seconds time elapsed

After (with task-clock):

 [lucas@skywalker perf]$ sudo ./perf stat -e branch-misses -e task-clock -a -- sleep 1

	 Performance counter stats for 'sleep 1':

		1070111  branch-misses            #      0.534 M/sec
	    2002.730893  task-clock-msecs         #      1.999 CPUs

	    1.001640292  seconds time elapsed

Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
LKML-Reference: <20091115140507.GB21561@skywalker.lan>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Lucas De Marchi authored and Ingo Molnar committed Nov 15, 2009
1 parent d2fb8b4 commit 7255fe2
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,16 @@ static void abs_printout(int counter, double avg)
ratio = avg / total;

fprintf(stderr, " # %10.3f IPC ", ratio);
} else if (MATCH_EVENT(HARDWARE, HW_BRANCH_MISSES, counter)) {
} else if (MATCH_EVENT(HARDWARE, HW_BRANCH_MISSES, counter) &&
runtime_branches_stats.n != 0) {
total = avg_stats(&runtime_branches_stats);

if (total)
ratio = avg * 100 / total;

fprintf(stderr, " # %10.3f %% ", ratio);

} else {
} else if (runtime_nsecs_stats.n != 0) {
total = avg_stats(&runtime_nsecs_stats);

if (total)
Expand Down

0 comments on commit 7255fe2

Please sign in to comment.