In C, Linux 3.2: Is there a way to programmatically gather stats on the state of each pthread created thread on some program? For instance, I’d like to get the time each thread spent running, and in the idle state.
In C, Linux 3.2: Is there a way to programmatically gather stats on the
Share
clock_gettime()can return the thread-specific CPU time. Simply do:But from my understanding this is the sum of user and system time of this thread. Also you should consider the Warning message regarding SMP systems at the end of the man page.
Also, if you don’t want timing information on the current thread, but on some pthread, you could get the
clockid_tto use withclock_gettime()usingint pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id).