2
votes

How I can monitor the hardware counters of already running process using PAPI?

Any help will be highly appreciated.

Thanks Shuja

1
Try this icl.cs.utk.edu/papiMad

1 Answers

2
votes

Once you obtain the thread id (using PAPI_thread_id or other functions), you can use the PAPI_attach and PAPI_detach wrapper functions as described in this article:

http://icl.cs.utk.edu/projects/papi/wiki/PAPI3:PAPI_attach.3

For example:

int EventSet = PAPI_NULL;
unsigned long pid;
pid = fork();
if (pid <= 0)
exit(1);
if (PAPI_create_eventset(&EventSet) != PAPI_OK)
exit(1);
/* Add Total Instructions Executed to our EventSet */
if (PAPI_add_event(EventSet, PAPI_TOT_INS) != PAPI_OK)
exit(1);
/* Attach this EventSet to the forked process */
if (PAPI_attach(EventSet, pid) != PAPI_OK)
exit(1);