Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Per thread CPU statistics in Linux

Tags:

c

linux

I want to report the amount of CPU time used per thread in a server process (written in C/C++ on Linux). I can't find the equivalent of GetThreadTimes() on Windows, but that's what I'm looking for.

Can anyone point me in the right direction?

like image 758
Pete Smoot Avatar asked Sep 23 '09 20:09

Pete Smoot


1 Answers

getrusage(2) with RUSAGE_THREAD. From the man page:

int getrusage(int who, struct rusage *usage);

getrusage() returns resource usage measures for who, which can be one of the following:

[...]

        RUSAGE_THREAD (since Linux 2.6.26)
          Return resource usage statistics for the calling thread.
like image 194
tsg Avatar answered Oct 11 '22 03:10

tsg