Open nh2 opened 6 years ago
There is a flag inherit on the perf_event_attr structure where you specify if is going to count for all threads or only the main thread
From the perf docs inherit: The inherit bit specifies that this counter should count events of child tasks as well as the task specified. This applies only to new children, not to any existing children at the time the counter is created (nor to any new children of existing children).
Inherit does not work for some combinations of read_format
values, such as PERF_FORMAT_GROUP.
@VitorRamos Awesome, thanks for providing this info!
Now we just have to ensure that we use it appropriately.
From the man page:
So what now, is it the calling process or thread? How do I control that?
Quite likely, if I run
perf_event_open()
from a forked pthread, it's going to count only for that pthread. But what if I run it from the process's (only) main thread, and afterwards create a new pthread? Does the perf FD then record the events only for the main thread, or the whole process?That would be important to know, so that we don't accidentally give wrong numbers when running in the threaded runtime.