#include <mplib1/stopwatch.h> struct cpu_stopwatch { struct stopwatch u_timing; struct stopwatch s_timing; char elps_str[100]; }; int init_cpu_stopwatch( struct cpu_stopwatch *cpu_p ); int start_cpu_stopwatch( struct cpu_stopwatch *cpu_p ); int stop_cpu_stopwatch( struct cpu_stopwatch *cpu_p ); int accrete_cpu_stopwatch( struct cpu_stopwatch *cpu_p_into, struct cpu_stopwatch *cpu_p_from ); char *display_cpu_stopwatch( struct cpu_stopwatch *cpu_p, int mode );This set of routines provides a mechanism for measuring the user cpu time and system cpu time of an enclosed block of code. They currently give a displayed accuracy to hundredths of a second. The cpu_stopwatch structure used contains a pair of stopwatch entries which record the user and system timings and cumulatives, and a string buffer for generating ASCII representations of the cumulative data.
init_cpu_stopwatch() initialises a cpu_stopwatch structure, resetting the user and system cumulative values, start values and the string buffer.
start_cpu_stopwatch() sets the start times of cpu_stopwatch user and system structure.
stop_cpu_stopwatch() determines the difference between the current times and those held in the start times, and adds them to the cumulative times.
accrete_cpu_stopwatch() adds the cumulative times in the cpu_p_from structure into the cumulative times in the cpu_p_into structure.
display_cpu_stopwatch() returns a pointer to an ascii representation of the cumulative times. Currently the only mode that is accepted is 0 which gives a string like
USR: 027.55 seconds CPU: 001.38 secondsor
USR: 001529.04 seconds CPU: 001022.27 secondsdepending on whether the number of seconds is greater than 999.
These routines behave in the same manner as the real-time elapsed stopwatch routines.