Cumulative Processor Time

Discussion to talk about software related topics only.
Post Reply
SeeCwriter
Posts: 616
Joined: Mon May 12, 2008 10:55 am

Cumulative Processor Time

Post 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
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Cumulative Processor Time

Post by rnixon »

Just use the global variable, Secs. Its the seconds since boot time.
k1mgy
Posts: 24
Joined: Thu Oct 14, 2010 8:25 am

Re: Cumulative Processor Time

Post 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?
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Cumulative Processor Time

Post 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?
k1mgy
Posts: 24
Joined: Thu Oct 14, 2010 8:25 am

Re: Cumulative Processor Time

Post 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.
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Cumulative Processor Time

Post 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
User avatar
tod
Posts: 587
Joined: Sat Apr 26, 2008 8:27 am
Location: Southern California
Contact:

Re: Cumulative Processor Time

Post 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..
Post Reply