diff -r f07ff78d4fad -r 4fbe868c1fb4 src/work/marci/time_measure.h --- a/src/work/marci/time_measure.h Mon Apr 26 17:31:49 2004 +0000 +++ b/src/work/marci/time_measure.h Mon Apr 26 17:33:51 2004 +0000 @@ -2,6 +2,10 @@ #ifndef HUGO_TIME_MEASURE_H #define HUGO_TIME_MEASURE_H +///ingroup graphs +///\file +///\brief Tools for measuring cpu usage + #include #include #include @@ -10,14 +14,10 @@ namespace hugo { -// double currTime() { -// timeval tv; -// //timezone tz; -// gettimeofday(&tv, 0); -// return double(tv.tv_sec)+double(tv.tv_usec)/1000000.0; -// } + /// \addtogroup misc + /// @{ - /// Class to store (cpu)time instances. + /// A class to store (cpu)time instances. /// This class stores five time values. /// - a real time @@ -27,7 +27,7 @@ /// - a system cpu time of children /// /// TimeStamp's can be added to or substracted from each other and - /// they can be push to a stream. + /// they can be pushed to a stream. class TimeStamp { @@ -38,8 +38,7 @@ tms &getTms() {return ts;} const tms &getTms() const {return ts;} - double getRealTime() const {return real_time;} - ///Read the current time values of the process. + ///Read the current time values of the process void stamp() { timeval tv; @@ -47,12 +46,13 @@ gettimeofday(&tv, 0);real_time=tv.tv_sec+double(tv.tv_usec)/1e6; } - /// Constructor initializing with zero. + /// Constructor initializing with zero TimeStamp() { ts.tms_utime=ts.tms_stime=ts.tms_cutime=ts.tms_cstime=0; real_time=0;} - ///Constructor initializing with the current time values of the process. + ///Constructor initializing with the current time values of the process TimeStamp(void *) { stamp();} + /// TimeStamp &operator+=(const TimeStamp &b) { ts.tms_utime+=b.ts.tms_utime; @@ -62,11 +62,13 @@ real_time+=b.real_time; return *this; } + /// TimeStamp operator+(const TimeStamp &b) const { TimeStamp t(*this); return t+=b; } + /// TimeStamp &operator-=(const TimeStamp &b) { ts.tms_utime-=b.ts.tms_utime; @@ -76,6 +78,7 @@ real_time-=b.real_time; return *this; } + /// TimeStamp operator-(const TimeStamp &b) const { TimeStamp t(*this); @@ -91,25 +94,31 @@ friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t); + ///Gives back the user time of the process double getUserTime() const { return double(ts.tms_utime)/sysconf(_SC_CLK_TCK); } + ///Gives back the system time of the process double getSystemTime() const { return double(ts.tms_stime)/sysconf(_SC_CLK_TCK); } + ///Gives back the user time of the process' children double getCUserTime() const { return double(ts.tms_cutime)/sysconf(_SC_CLK_TCK); } + ///Gives back the user time of the process' children double getCSystemTime() const { return double(ts.tms_cstime)/sysconf(_SC_CLK_TCK); } + ///Gives back the real time of the process + double getRealTime() const {return real_time;} }; - ///Class measuring the cpu time and real time usage of the process. + ///Class measuring the cpu time and real time usage of the process class Timer { TimeStamp start_time; @@ -117,10 +126,10 @@ void _reset() {start_time.stamp();} public: - ///Constructor. It starts with zero time counters. + ///Constructor. It starts with zero time counters Timer() {_reset();} - ///Computes the ellapsed time. + ///Computes the ellapsed time ///This conversion computes the ellapsed time ///since the construction of \c t or since @@ -132,7 +141,7 @@ return t-start_time; } - ///Resets the time counters. + ///Resets the time counters TimeStamp reset() { TimeStamp t(start_time); @@ -141,7 +150,20 @@ } }; - ///Prints the time counters. + ///Prints the time counters + + ///Prints the time counters in the folloing form: + /// + /// u: XX.XXs s: XX.XXs cu: XX.XXs cs: XX.XXs real: XX.XXs + /// + /// where the values are the + /// - a user cpu time, + /// - a system cpu time, + /// - a user cpu time of children, + /// - a system cpu time of children and + /// - a real time, + /// + ///respectively inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t) { long cls = sysconf(_SC_CLK_TCK); @@ -153,6 +175,8 @@ return os; } + /// @} + } //namespace hugo #endif //HUGO_TIME_MEASURE_H