|
Home > Archive > Unix Programming > May 2006 > timing threads
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
|
| davids@webmaster.com 2006-05-23, 7:17 pm |
| 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
| |
| Maxim Yegorushkin 2006-05-24, 7:16 am |
|
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
| |
| Sam Steingold 2006-05-24, 1: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 (Bordeaux)
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
| |
| Rick Jones 2006-05-24, 1: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...
| |
| davids@webmaster.com 2006-05-24, 7:16 pm |
| You can get the system thread ID on modern Linux systems with:
long int tid=syscall(224);
DS
|
|
|
|
|