How to measure processor time for a specific set of threads?

I am running a C ++ program on Linux.

There are several thread pools (for computing, for io, for ... such things).

The clock () system call gives me a way to measure the processor time spent by all the processor cores for a process.

However, I want to measure the processor time spent only by threads in the pool of calculation threads.

How can i achieve this?

Thanks: D

+6
source share
1 answer

CPU clock ID , : pthread_getcpuclockid CPU clock ID, , : clock_gettime.

:

struct timespec currTime;
clockid_t threadClockId;

//! Get thread clock Id
pthread_getcpuclockid(pthread_self(), &threadClockId);
//! Using thread clock Id get the clock time
clock_gettime(threadClockId, &currTime);
+6

All Articles