Re: how to get thread CPU time
Re: how to get thread CPU time
- Subject: Re: how to get thread CPU time
- From: Terry Lambert <email@hidden>
- Date: Fri, 17 Mar 2006 13:56:15 -0800
On Mar 17, 2006, at 7:53 AM, email@hidden wrote:
Hello,
is there any way to get time which particular thread is being executed
on CPU. In other words how many milliseconds (or nonoseconds) of CPU
time was consumed by thread since it has been started.
IAIK, in Linux there is a clock_gettime(CLOCK_THREAD_CPUTIME_ID)
system
call (and Windows has similar API) but I cannot find any analog for
Darwin.
I'm writing CPU profiler for Mac OS X and thread CPU times is very
important for me. Please advise.
The best way is to do it by observation. This is what chud and shark
do. Formal resource utilization accounting is only ever done on a per
process or per task basis, not a per thread basis.
If you want absolute values, there are two timers that are started for
system and user time when threads are started that will provide this
information from the scheduler. However, in order to access them, you
will need to write a kext, and you will need to explicitly link
against the mach_kernel instead of against one of the symbol sets,
which will require that you recompile your application for each point
release of the OS (e.g. 10.4.3->10.4.4, etc.). The closest hint I'm
willing to give you is "look at the implementation of task_info()".
How you link in such a way as to make your application not run except
on a specific OS version has been discussed before (you will need to
look at the list archives, or combine the results of two knowledge
base articles from developer.apple.com) and for the identity of the
timers themselves and how they are accessed, you will need to look at
the source code on opendarwin.org.
Basically, if you do this, you are on your own, since it touches on
details of the microarchitecture, such as the relationship between
tasks and processes, threads and uthreads, and how the scheduler works
at the lowest level. We neither document nor guarantee not to change
these things from point release to point release of the OS, and we
steer internal tools developers away from doing this sort of thing as
well.
-- Terry
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden