How can I measure CPU time of a specific set of threads?

前端 未结 1 1957

I run C++ program in Linux.

There are several threads pool (for computation, for io, for ... such things).

The system call clock() gives me a way to measure

相关标签:
1条回答
  • 2021-01-11 17:37

    To get CPU clock ID of every thread you can use: pthread_getcpuclockid and using this CPU clock ID you can retrieve the current thread CPU time using: clock_gettime.

    Following is the sample code to demonstrate the same:

    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);
    
    0 讨论(0)
提交回复
热议问题