Page 1 of 1

Cumulative Processor Time

Posted: Tue Dec 21, 2010 2:09 pm
by SeeCwriter
From Libc.pdf page 141:

6.2 clock--cumulative processor time
Synopsis
#include <time.h>
clock_t clock(void);

Description
Calculates the best available approximation of the cumulative amount of time used by your
program since it started. To convert the result into seconds, divide by the macro CLOCKS_PER_SEC.

Returns
The amount of processor time used so far by your program, in units de_ned by the machinedependent
macro CLOCKS_PER_SEC. If no measurement is available, the result is -1.

Portability
ANSI C requires clock and CLOCKS_PER_SEC.
Supporting OS subroutine required: times.

The compiler generates an error and goes into an infinite loop trying to compile this. The error message is

times.c: undefined reference to ‘times’

Do I need to include something else??


Steve

Re: Cumulative Processor Time

Posted: Tue Dec 21, 2010 3:13 pm
by rnixon
Just use the global variable, Secs. Its the seconds since boot time.

Re: Cumulative Processor Time

Posted: Thu Mar 10, 2011 9:52 am
by k1mgy
The compiler doesn't crash, but I get this:
c:/nburn/gcc-m68k/bin/../lib/gcc/m68k-elf/4.2.1/../../../../m68k-elf/lib/m5208\libc.a(lib_a-times.o): In function `_times_r':
times.c:(.text+0xe): undefined reference to `times'
Looks like an error in libc.

Who maintains libc for this platform?

Re: Cumulative Processor Time

Posted: Thu Mar 10, 2011 10:20 am
by rnixon
What is the value get? The description you included for clock() appears to say it a way to get seconds since boot. Are you trying to get seconds?

Re: Cumulative Processor Time

Posted: Thu Mar 10, 2011 10:30 am
by k1mgy
rnixon wrote: What is the value get? The description you included for clock() appears to say it a way to get seconds since boot. Are you trying to get seconds?
Seems that the result is a function of CLOCKS_PER_SEC.

The description seems to indicate that the value returned will be CLOCKS_PER_SEC/value. In my case CLOCKS_PER_SEC == 20.

"Cumulative amount of time" is misleading as the unit of measure is not stated until you read the description.

I wanted something with more resolution than a second. Meanwhile I found a nice timer class that provides about 3ms resolution and even has a callback.

Amazing what folks have produced here.

Re: Cumulative Processor Time

Posted: Thu Mar 10, 2011 2:56 pm
by rnixon
There is a TICKS_PER_SECOND #define that has a default of 20, and this is what the system clock uses, and Secs and TimerTicks are based on it. But this is not accurate enough in some cases, so one of the unused hardware timers can be used (I think thats what your referring to). There is a thread on a stopwatch function that might be interesting as well:
http://forum.embeddedethernet.com/viewt ... ?f=7&t=397

Re: Cumulative Processor Time

Posted: Fri Mar 11, 2011 12:18 am
by tod
I just thought I would mention BspGetTickFraction() again, it lets you get a value of finer granularity without using a timer or interrupt. I mentioned some details about it in this thread..