timing threads
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > timing threads




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    timing threads  
Sam Steingold


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-24-06 12:17 AM

Is it possible to figure out how much CPU time each thread consumes?
times(2) returns this information per-process, not per-thread.

thanks.

(I am using linux 2.6)

--
Sam Steingold (http://www.podval.org/~sds) on Fedora Core release 5 (Bordeau
x)
http://jihadwatch.org http://dhimmi.com http://iris.org.il http://memri.org
http://mideasttruth.com http://truepeace.org http://palestinefacts.org
The only guy who got all his work done by Friday was Robinson Crusoe.





[ Post a follow-up to this message ]



    Re: timing threads  
davids@webmaster.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-24-06 12:17 AM

If you look in /proc/<pid>/task, you will find one entry for each
thread. In the sub-directory are files 'stat', 'statm', and 'status'.
These are not very well documented, but they contain the information
you seek.

You can also use 'ps'  with options like '-L'. Your man page should
have details.

DS






[ Post a follow-up to this message ]



    Re: timing threads  
Maxim Yegorushkin


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-24-06 12:16 PM


Sam Steingold wrote:
> Is it possible to figure out how much CPU time each thread consumes?
> times(2) returns this information per-process, not per-thread.

You can obtain a per-thread clock by pthread_getcpuclockid(). Then you
can use then that clock_id or CLOCK_THREAD_CPUTIME_ID for the current
thread in clock_gettime() call.

<q>
If _POSIX_THREAD_CPUTIME is defined, implementations shall support
clock ID values obtained by invoking pthread_getcpuclockid(), which
represent the CPU-time clock of a given thread. Implementations shall
also support the special clockid_t value CLOCK_THREAD_CPUTIME_ID, which
represents the CPU-time clock of the calling thread when invoking one
of the clock_*() or timer_*() functions. For these clock IDs, the
values returned by clock_gettime() and specified by clock_settime()
shall represent the amount of execution time of the thread associated
with the clock. Changing the value of a CPU-time clock via
clock_settime() shall have no effect on the behavior of the sporadic
server scheduling policy (see Scheduling Policies ).
</q>

http://www.opengroup.org/onlinepubs...ock_getres.html






[ Post a follow-up to this message ]



    Re: timing threads  
Sam Steingold


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-24-06 06:16 PM

> *  <qnivqf@jroznfgre.pbz> [2006-05-23 17:07:45 -0700]:
>
> If you look in /proc/<pid>/task, you will find one entry for each
> thread. In the sub-directory are files 'stat', 'statm', and 'status'.

hmmm...
there are 16 subdirectories in task (and I thought that I was only using
6 threads - although I rely on outside libraries that probably use some
threads too).
how do I determine which of my threads correspond to which subdirectory?
Alas, I use ocaml, so my thread ids are 1 through 6, not 15553 through 15571
.
Maybe TID=PID+(ocaml tid)? (looks plausible for my values...)

> These are not very well documented, but they contain the information
> you seek.
indeed - where are they documented?
the only load-related parameter in status appears to be "SleepAVG".
anything else?

> You can also use 'ps'  with options like '-L'. Your man page should
> have details.

same problem - cannot figure out what thread is what.

thanks.

--
Sam Steingold (http://www.podval.org/~sds) on Fedora Core release 5 (Bordeau
x)
http://truepeace.org http://camera.org http://ffii.org http://dhimmi.com
http://jihadwatch.org http://pmw.org.il http://palestinefacts.org
There are two kinds of egotists: 1) Those who admit it  2) The rest of us





[ Post a follow-up to this message ]



    Re: timing threads  
Rick Jones


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-24-06 06:16 PM

It has been my experience with netperf that while there may (or may
not) be API's/means to get per[process|thread] CPU consumption, that
will not always include all the CPU time consumed on behalf of that
thread|process.  In particular, "networking" CPU time may not be
charged to the thread|process.

YMMV.

rick jones
--
No need to believe in either side, or any side. There is no cause.
There's only yourself. The belief is in your own precision.  - Jobert
these opinions are mine, all mine; HP might not want them anyway... 
feel free to post, OR email to rick.jones2 in hp.com but NOT BOTH...





[ Post a follow-up to this message ]



    Re: timing threads  
davids@webmaster.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-25-06 12:16 AM

You can get the system thread ID on modern Linux systems with:

long int tid=syscall(224);

DS






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 10:26 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register