I'm trying to monitor performance stats during a particular function using linux perf tool.
I was following the instructions given at https://perf.wiki.kernel.org/index.php/Jolsa_Features_Togle_Event#Example_-_using_u.28ret.29probes
I tried to get instruction count of a simple C program. (As shown below)
1) My simple C code
#include<stdio.h>
int sum=0;
int i=0;
void func(void)
{
for(i=0;i<100;i++)
{
sum=sum+i;
}
}
int main(void)
{
func();
return 0;
}
2) Compiling and adding probes
root@sunimal-laptop:/home/sunimal/temp# gcc -o ex source.c
root@sunimal-laptop:/home/sunimal/temp# perf probe -x ./ex entry=func
Added new event:
probe_ex:entry (on 0x4ed)
You can now use it in all perf tools, such as:
perf record -e probe_ex:entry -aR sleep 1
root@sunimal-laptop:/home/sunimal/temp# perf probe -x ./ex exit=func%return
Added new event:
probe_ex:exit (on 0x4ed%return)
You can now use it in all perf tools, such as:
perf record -e probe_ex:exit -aR sleep 1
3) Trying to use perf stat to measure the instruction count within the func() function. This leads to an error.
root@sunimal-laptop:/home/sunimal/temp# perf stat -e instructions:u,probe_ex:entry/on=instructions/,probe_ex:exit/off=instructions/ ./ex
invalid or unsupported event: 'instructions:u,probe_ex:entry/on=instructions/,probe_ex:exit/off=instructions/'
Run 'perf list' for a list of valid events
Could someone point me where I did wrong?
[I'm using linux kernel 3.11.0-12-generic]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…