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);
1 回答
一旦获得线程id(使用PAPI_thread_id或其他函数),就可以使用本文所述的 PAPI_attach 和 PAPI_detach 包装函数:
http://icl.cs.utk.edu/projects/papi/wiki/PAPI3:PAPI_attach.3
例如: