#include "clock.h"

This page has information from files clock.h and clock.c.

Contents


Public Routines in File clock.c

Index

clock_initclock_stopfprint_all_clocksuser_time
clock_resetclock_valuefprint_clockwall_init
clock_runningdisable_clocksget_datewall_time
clock_startenable_clockssystem_time

Details


int clock_init(char *str);
This routine initializes a clock. You give it a string (any length, which is copied), representing the name of the new clock, and it returns a nonnegative integer ID which is to be used for all of the clock operations. There is no limit on the number of clocks you can have. If you already have a clock with the given name, -1 is returned.

The clock operations are clock_start(), clock_stop(), clock_value(), and clock_reset().


void clock_reset(int n);
This routine resets a clock, as if it had just been initialized. (You shouldn't need this routine under normal circumstances.)
BOOL clock_running(int n);
This routine tells you whether or not a clock is running.
void clock_start(int n);
This routine starts clock n. It is okay if the clock is already going.
void clock_stop(int n);
This routine stops clock n and adds the time to the accumulated total, unless there have been too many starts and not enough stops. See the introduction.
unsigned clock_value(int n);
This routine returns the current value of a clock. The value is in milliseconds. The clock need not be stopped.
void disable_clocks(void);

void enable_clocks(void);

void fprint_all_clocks(FILE *fp);
This routine
void fprint_clock(FILE *fp, int n);
This routine
char * get_date(void);
This routine returns a string representation of the current date and time.
unsigned system_time();
This routine returns the system CPU time, in milliseconds, that has been spent on the current process. (System time measures low-level operations such as system calls, paging, and I/O that the operating systems does on behalf of the process.)
unsigned user_time();
This routine returns the user CPU time, in milliseconds, that the current process has used so far.
void wall_init();
This routine initializes the wall-clock timer.
int wall_time();
This routine returns the number of wall-clock seconds since wall_init() was called.

Public Definitions in File clock.h


Introduction

This package is for timing various operations. Say you need to time an operation P. You first call clock_init() to set up a clock, then you can start and stop the clock as you wish, then you can get the accumulated time with clock_value(). These clocks measure the user CPU time.

An unusual feature of these clocks is that they can be used inside of recursive routines. For example, you can start the clock at the beginning of a recursive routine and stop it at the end. If you start it 3 times then stop it three times, it will really stop only on the third call. This works by a counter of the number of extra times the clock has been started, and clock_stop() will stop the clock only when the count is 0. (This feature probably isn't very useful, and most people can ignore it.)

Also here are some routines for getting process system/user CPU time, elapsed wall-clock time, and the time/date.


These activities are projects of the Mathematics and Computer Science Division of Argonne National Laboratory.