[LLVMdev] Rounding error in llvm-prof output

César divcesar at gmail.com
Fri Feb 1 15:20:05 PST 2013


Hello.

I've used these commands to compile the code below with
edge-profiling-instrumentation:

$> clang -emit-llvm -c rnd.c -o rnd.bc
$> opt -insert-edge-profiling rnd.bc -o rnd-prof.bc
$> clang rnd-prof.bc -lprofile_rt -L/paths/lib -o rnd

this is the source:

#include <stdio.h>

void hello() { printf("hello\n"); }

int main() {
	int i=0;
	for (i=0; i<149; i++) hello();
	return 0;
}

and use these commands to see the profile information:

$> llvm-prof rnd.bc

and this is the output:

......
===-------------------------------------------------------------------------===
Function execution frequencies:

 ##   Frequency
  1. 1.5e+02/150 hello
  2.     1/150 main

.....

Notice that the total execution count for all functions is "/150",
however if you look
carefully the sum of the execution frequency of these two functions is
151. The problem
is that in some cases the function execution frequency is being
rounded due the "5.2g"
formatter used by llvm-prof (note that the rounding may be even
greater!). The same
problem happen with BB frequency output. To correct the problem I
suggest changing
the formatter to "%.0f".


César.




More information about the llvm-dev mailing list