#include "clock.h"

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

Contents


Public Routines in File clock.c

Index

absolute_wallclockclock_secondsenable_clockssystem_seconds
clock_initclock_startfprint_clocksystem_time
clock_millisecondsclock_stopfree_clockuser_seconds
clock_resetclocks_enabledget_dateuser_time
clock_runningdisable_clocksinit_wallclockwallclock

Details


unsigned absolute_wallclock(void);

Clock clock_init(char *str);
This routine initializes a clock. You give it a string (which is not copied), representing the name of the new clock, and it returns a Clock to be used for all operations on the clock.

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


unsigned clock_milliseconds(Clock p);
This routine returns the current value of a clock, in milliseconds. The value is in milliseconds.
void clock_reset(Clock p);
This routine resets a clock, as if it had just been initialized. (You should not need this routine under normal circumstances.)
BOOL clock_running(Clock p);
This routine tells you whether or not a clock is running.
double clock_seconds(Clock p);
This routine returns the current value of a clock, in seconds. The clock need not be stopped.
void clock_start(Clock p);
This routine starts clock n. It is okay if the clock is already going.
void clock_stop(Clock p);
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.
BOOL clocks_enabled(void);

void disable_clocks(void);

void enable_clocks(void);

void fprint_clock(FILE *fp, Clock p);
This routine
void free_clock(Clock p);

char * get_date(void);
This routine returns a string representation of the current date and time.
void init_wallclock();
This routine initializes the wall-clock timer.
double system_seconds();
This routine returns the system CPU time, in seconds, 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 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.)
double user_seconds();
This routine returns the user CPU time, in seconds, that the current process has used so far.
unsigned user_time();
This routine returns the user CPU time, in milliseconds, that the current process has used so far.
unsigned wallclock();
This routine returns the number of wall-clock seconds since init_wallclock() was called. The result is unsigned.

Public Definitions in File clock.h

typedef struct clock * Clock;


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.