Page 1 of 1

I need help! how to use PAPI to read performance counters?

PostPosted: Fri Sep 18, 2009 7:41 am
by kakagou
i want to use PAPI to read CORE2 CPU performance counters, when the cpu is runing programs
i want to read the counters one time each second,i write program to read the counters, but i doesn't work
the basic structure of the program is following:

main()
{
...
while(1){
PAPI_start(eventset);//start counters
sleep(1);
PAPI_stop(eventset, values)//read counters
}
}

i find that if the program go to sleep, the value of the counter will not increase. why ?

Re: I need help! how to use PAPI to read performance counters?

PostPosted: Sat Sep 19, 2009 2:59 am
by cjashfor
kakagou wrote:i find that if the program go to sleep, the value of the counter will not increase. why ?


PAPI keeps track of events counts on a per-thread basis. If the thread is sleeping, no (or very few) counts will be attributed to that thread.

If you want to see counts, give the processor something to do, like 10 million loops where you are multiplying two floating point numbers together and summing the result.

Re: I need help! how to use PAPI to read performance counters?

PostPosted: Sun Sep 20, 2009 4:47 am
by kakagou
thank you!

now I am going to write a program to read counter values periodically, for example one time per second,
the program is used to get the counter values of bechmarks
Since PAPI is based on per-thread, how I get the values of the bechmark ?

Re: I need help! how to use PAPI to read performance counters?

PostPosted: Tue Sep 22, 2009 3:57 pm
by cjashfor
kakagou wrote:thank you!

now I am going to write a program to read counter values periodically, for example one time per second,
the program is used to get the counter values of bechmarks
Since PAPI is based on per-thread, how I get the values of the bechmark ?


So you are going to monitor the benchmark using a separate thread (or process) ?

If so, you will need to use the PAPI_attach() call. I don't have much experience using it, though, so I'd just refer you to the documentation on PAPI_attach().

Re: I need help! how to use PAPI to read performance counters?

PostPosted: Sun Nov 15, 2009 2:17 am
by yuzhibin
Hi
I also want to do the same thing. Ouptut the performance counters every seconds when a benchmark is running.
I use fork and exec to call the benchmark on the command line. in code, i use PAPI_attach to attach an event set to the called process. It can work correctly as long as the called process terminated normally. However, i always get 0 values if i want to output the counters every second or kill the called process.

Best regards,
Zhibin :roll: