🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.programmer
Article #935

Re: How to measure cpu time to ~ 1 millisecond?

#935
From: Jay Goldberg
Date: Fri, 28 Sep 1990 18:49
34 lines
2022 bytes
In article <237@locke.water.ca.gov> rfinch@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@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?
Technical Details
Message-ID: <3819@aix.aix.kingston.ibm.com>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!ibmps2!aix!vendijag
References: <237@locke.water.ca.gov>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!ibmps2!aix!vendijag
From: vendijag@aix.aix.kingston.ibm.com (Jay Goldberg)
Newsgroups: comp.unix.programmer
Subject: Re: How to measure cpu time to ~ 1 millisecond?
Keywords: time
Message-ID: <3819@aix.aix.kingston.ibm.com>
Date: 28 Sep 90 18:49:57 GMT
References: <237@locke.water.ca.gov>
Organization: IBM Corporation, Kingston NY
Lines: 34