src/Utility/Timer.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  *
00007  * Visit http://people.web.psi.ch/adelmann/ for more details
00008  *
00009  ***************************************************************************/
00010 
00011 /***************************************************************************/
00012 /*                                                                         */
00013 /*              (C) Copyright 1995 The Board of Trustees of the            */
00014 /*                          University of Illinois                         */
00015 /*                           All Rights Reserved                           */
00016 /*                                                                         */
00017 /***************************************************************************/
00018 
00019 /***************************************************************************
00020  * CVS INFORMATION:
00021  * $Id
00022  ***************************************************************************
00023  * DESCRIPTION:
00024  *      The Timer class allows for easy timing of the program.  The timer
00025  * tracks real (clock) time elapsed, user time, and system time.
00026  *
00027  ***************************************************************************/
00028 
00029 #ifndef TIMER_H
00030 #define TIMER_H
00031 
00032 #ifdef __sgi
00033 // make sure this is defined for BSD time routines
00034 #define _BSD_TYPES
00035 // fix a glitch in ANSI compatibility with SGI headers
00036 #define _STAMP_T
00037 #endif
00038 
00039 #ifndef __MWERKS__
00040 // For now, stub out all Timer guts for MetroWerks
00041 
00042 #include <unistd.h>
00043 #include <sys/types.h>
00044 #include <sys/times.h>
00045 #include <sys/time.h>
00046 #endif // __MWERKS__
00047 
00048 #ifdef __sgi
00049 // fix a glitch in ANSI compatibility with SGI headers
00050 #undef _STAMP_T
00051 #endif
00052 
00053 
00054 class Timer
00055 {
00056 public:
00057   Timer();                      // Constructor
00058   ~Timer();                     // Destructor
00059   void clear();                 // Set all accumulated times to 0
00060   void start();                 // Start timer
00061   void stop();                  // Stop timer
00062 
00063   double clock_time();          // Report clock time accumulated in seconds
00064   double user_time();           // Report user time accumlated in seconds
00065   double system_time();         // Report system time accumulated in seconds
00066   double cpu_time()
00067   {
00068     // Report total cpu_time which is just user_time + system_time
00069     return ( user_time() + system_time() );
00070   }             
00071 
00072 #ifndef __MWERKS__
00073 // For now, stub out all Timer guts for MetroWerks
00074 
00075   double calibration;           // Calibration time: time it takes to
00076                                 // get in and out of timer functions
00077 private:
00078   short timer_state;            // State of timer, either on or off
00079 #ifdef IPPL_XT3
00080   double last_clock;            // Previous value from dclock()
00081   double current_clock;         // Current value from dclock()
00082 #else
00083   long cpu_speed;                 // CPU speed for times() call
00084 
00085   unsigned long last_secs;        // Clock seconds value when the
00086                                   // timer was last started
00087   long last_usecs;                // Clock useconds value when the
00088                                   // timer was last started
00089   unsigned long last_user_time;   // User time when timer was last started
00090   unsigned long last_system_time; // System time when timer was last started
00091 
00092   long current_secs;            // Current accumulated clock seconds
00093   long current_usecs;           // Current accumulated clock useconds
00094   long current_user_time;       // Current accumulated user time
00095   long current_system_time;     // Current accumulated system time
00096 #endif
00097 
00098 #if ( defined(IPPL_T3E) || defined(IPPL_XT3) )
00099   // don't need these structs
00100 #else
00101   struct tms tmsbuf;            //  Values from call to times
00102   struct timeval tvbuf;         //  Values from call to gettimeofday
00103   struct timezone tzbuf;        //  Timezone values from gettimeofday
00104                                 //  These values aren't used for anything
00105 #endif
00106 
00107 #endif // __MWERKS__
00108 };
00109 
00110 #endif // TIMER_H
00111 
00112 /***************************************************************************
00113  * $RCSfile: Timer.h,v $   $Author: adelmann $
00114  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:33 $
00115  * IPPL_VERSION_ID: $Id: Timer.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $ 
00116  ***************************************************************************/

Generated on Mon Jan 16 13:23:59 2006 for IPPL by  doxygen 1.4.6