clock_gettime()
can return the processor time, depending on the thread. Just do:
struct timespec ts; clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
But, in my opinion, this is the sum of the user and system time of this stream. You should also consider the Warning message regarding SMP systems at the end of the man page.
Also, if you do not want to get time information in the current thread, but on some kind of pthread, you can use clockid_t
to use with clock_gettime()
using int pthread_getcpuclockid(pthread_t thread, clockid_t *clock_id)
.
source share