Skip to content
Advertisement

Any equivalent function to pthread_getcpuclockid since i have tid of Thread

To get perf statistics of parallel running threads –

To get list of threads I use thread list in /proc/self/task

Now I want to get ID of a thread’s CPU time clock. But clock_getcpuclockid only works with PIDs.

pthread_getcpuclockid requires the pthread id of thread and I did not find any way to get pthread id from TId of thread so I am looking for any alternative solution to this problem. CLOCK_THREAD_CPUTIME_ID will return information of current only and I need information of all parallel threads. Any suggestions are welcome.

Is there any alternative to pthread_getcpuclockid? I wonder what pthread implementation does inside ?

Advertisement

Answer

Read time(7) & clock_gettime(2). You probably want to use CLOCK_THREAD_CPUTIME_ID

See also proc(5)

Is there any alternative to pthread_getcpuclockid? I wonder what pthread implementation does inside ?

This is simple, and implementation specific (probably varies between GNU libc & musl-libc). Most (AFAIK, all) C standard libraries on Linux are free software, so you can study their source code.

For musl-libc src/threads/pthread_getcpuclockid.c is fetching the clock id from the data related to the thread_t

For GNU libc, I leave the diving into its source code to you.

Advertisement