HTML automatically generated with rman
Table of Contents

Name

init_timers, stamp_timers, diff_timers - routines to time your code

Synopsis


#include <timers.h>void init_timers(int maxtimers);void stamp_timers(int slot);long
long diff_timers(int slot1, int slot2);

Description

init_timers is used to allocate a set of maxtimers slots to hold timer information. stamp_timers is used remember the timer info in a slot. The difference between slot2 and slot1 (slot2>slot1 is normally assumed) is returned by diff_timers.

Timers use a low level assembly routine to directly accces the TSC (Time Stamp Counter), and have the usual flaws on multi proccesing cores and multi-tasking operating systems how to translate this to a CPU usage. For long term stability routines such as cputime(3NEMO) should be used,for short fine grained understanding, these routines could be useful.

Example


    init_timers(n+1);
    for (i=0; i<n; i++)
    stamp_timers(i);
    stamp_timers(n);
    for (i=0; i<n; i++)
    printf("Method-1: %Ld0,diff_timers(i,i+1));
    stamp_timers(0);
    for (i=0; i<n; i++) {
    stamp_timers(i+1);
    printf("Method-2: %Ld0,diff_timers(i,i+1));
    }

Caveats

Currently this function is only implemented on Intel hardware, where it uses the Time Stamp Counter. For other processors 0 is returned.

long long is assumed to hold 64 bits, where unsigned is assumed 32 bit.

See Also

cputime(3NEMO)

Author

Peter Teuben

Files


~/src/kernel/misc      timers.c

Update History


23-apr-04    created        PJT


Table of Contents