/* ******************************************************************************* * Copyright (c) 1996 Martin Poole * ******************************************************************************* ** ** WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! WARNING !! ** ** Any changes to be made to this file should first be checked with ** mplib1 source control for library integrity. ** ** mplib1 source control can be reached at mplib1@quatermass.co.uk ** * * * $Source: /home/cvs/cvsroot/onelan/onelan/src/mplib1/libsrc/cpustopwatch.c,v $ * $Author: mpoole $ * $Date: 2002/10/07 09:37:38 $ * $Revision: 1.2 $ * * ******************************************************************************* * * * $Log: cpustopwatch.c,v $ * Revision 1.2 2002/10/07 09:37:38 mpoole * Initial checkin of mplib1-3.1.0 * * Revision 1.1 2002/10/07 09:36:55 mpoole * Initial checkin of mplib1-3.1.0 * * ******************************************************************************* */ #ident "$Header: /home/cvs/cvsroot/onelan/onelan/src/mplib1/libsrc/cpustopwatch.c,v 1.2 2002/10/07 09:37:38 mpoole Exp $" /* ------------------------------------------------------------------ Include files ------------------------------------------------------------------ */ #include #include #include #include #include #include #include #ifdef RUSAGE_IN_UCBLIB #include #else #include #endif #include #include /* ------------------------------------------------------------------ defines ------------------------------------------------------------------ */ #ifndef RUSAGE_SELF /* Last ditch variation, in case nothing else works */ #define RUSAGE_SELF 1 #define RUSAGE_CHILDREN 2 struct rusage { struct timeval ru_utime; struct timeval ru_stime; }; #endif /* ------------------------------------------------------------------ Code starts here ------------------------------------------------------------------ */ int init_cpu_stopwatch( struct cpu_stopwatch *cpu_p ) { if (cpu_p) memset( cpu_p, '\0', CPU_STOPWATCH_SIZE ); return(0); } int start_cpu_stopwatch( struct cpu_stopwatch *cpu_p ) { struct rusage start_usage; getrusage( RUSAGE_SELF, &start_usage ); memcpy( &cpu_p->u_timing.start_time, &start_usage.ru_utime, sizeof(struct timeval) ); memcpy( &cpu_p->s_timing.start_time, &start_usage.ru_stime, sizeof(struct timeval) ); return(0); } int stop_cpu_stopwatch( struct cpu_stopwatch *cpu_p ) { struct rusage end_usage; getrusage( RUSAGE_SELF, &end_usage ); accum_stop_timevals( &cpu_p->u_timing, &end_usage.ru_utime ); accum_stop_timevals( &cpu_p->s_timing, &end_usage.ru_stime ); return(0); } int accrete_cpu_stopwatch( struct cpu_stopwatch *cpu_p_into, struct cpu_stopwatch *cpu_p_from ) { add_timevals( &cpu_p_into->u_timing.cumulative_time, &cpu_p_from->u_timing.cumulative_time ); add_timevals( &cpu_p_into->s_timing.cumulative_time, &cpu_p_from->s_timing.cumulative_time ); return(0); } char * display_cpu_stopwatch( struct cpu_stopwatch *cpu_p, int mode ) { display_stopwatch( &cpu_p->u_timing, mode ); display_stopwatch( &cpu_p->s_timing, mode ); sprintf( cpu_p->elps_str, "USR: %s CPU: %s", cpu_p->u_timing.elps_str, cpu_p->s_timing.elps_str ); return(0); } /* -- End of File -- */