How to measure cpu time to ~ 1 millisecond?
Jay Goldberg
vendijag at aix.aix.kingston.ibm.com
Sat Sep 29 04:49:57 AEST 1990
In article <237 at locke.water.ca.gov> rfinch at caldwr.water.ca.gov (Ralph Finch) writes:
>
>Setup: Sun 4/330, SunOS 4.1
>
>We need to measure cpu time in a program down to about a 1 millisecond
>resolution. The clock call says it can only measure to 16.7 ms. Any
>other ideas on how cpu time can be measured?
My best guess here is that your machine runs at 60 clock ticks per second.
There's a symbol in the kernel (at leat BSD derivatives) called "hz" which
contains the number of clock ticks per second on your machine.
This would mean that every clock tick, when your machine has its clock
interrupt, the kernel takes note of what he's doing, thus giving you a
granularity of (1 sec)/(60 ticks) = 0.016666... which is a resolution
of 16.7 milliseconds. So given that it's the kernel's responsibility
to maintain the count of CPU time per process, and he only wakes up every
16.7 milliseconds, you may be out of luck.
Your system might, however, provide a getrusage() system call (resource.h).
If you have it, that gives the "best estimation" for your system of CPU
utilization (system and user modes) with a granularity of microseconds
(see struct timeval in time.h)
Hope this helps!
-----
Jay A. Goldberg | Email inside IBM: KGNAIX(VENDIJAG)
Software Contractor | or vendijag at aix.aix.kingston.ibm.com
Resource One Inc. | Email outside IBM: uunet!ibmsupt!jag
Phone: (914) 336 7207 | Phone: (914) 385 3384 or 8+695 3384
I am not now, nor have I ever been, an employee of IBM.
Had an opinion been requested, a purchase order would have
been received by Resource One. Who is John Galt?
More information about the Comp.unix.programmer
mailing list