# HG changeset patch # User alpar # Date 1083001178 0 # Node ID 3544872b38c27032be8a1fe92ff70a6f72b442af # Parent a677104e946a248670f81e417397000cd4e4b14e time_measure.h went to src/include. diff -r a677104e946a -r 3544872b38c2 src/include/time_measure.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/include/time_measure.h Mon Apr 26 17:39:38 2004 +0000 @@ -0,0 +1,182 @@ +// -*- c++ -*- +#ifndef HUGO_TIME_MEASURE_H +#define HUGO_TIME_MEASURE_H + +///ingroup graphs +///\file +///\brief Tools for measuring cpu usage + +#include +#include +#include +#include +#include + +namespace hugo { + + /// \addtogroup misc + /// @{ + + /// A class to store (cpu)time instances. + + /// This class stores five time values. + /// - a real time + /// - a user cpu time + /// - a system cpu time + /// - a user cpu time of children + /// - a system cpu time of children + /// + /// TimeStamp's can be added to or substracted from each other and + /// they can be pushed to a stream. + + class TimeStamp + { + tms ts; + double real_time; + + public: + + tms &getTms() {return ts;} + const tms &getTms() const {return ts;} + ///Read the current time values of the process + void stamp() + { + timeval tv; + times(&ts); + gettimeofday(&tv, 0);real_time=tv.tv_sec+double(tv.tv_usec)/1e6; + } + + /// 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 + TimeStamp(void *) { stamp();} + + /// + TimeStamp &operator+=(const TimeStamp &b) + { + ts.tms_utime+=b.ts.tms_utime; + ts.tms_stime+=b.ts.tms_stime; + ts.tms_cutime+=b.ts.tms_cutime; + ts.tms_cstime+=b.ts.tms_cstime; + 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; + ts.tms_stime-=b.ts.tms_stime; + ts.tms_cutime-=b.ts.tms_cutime; + ts.tms_cstime-=b.ts.tms_cstime; + real_time-=b.real_time; + return *this; + } + /// + TimeStamp operator-(const TimeStamp &b) const + { + TimeStamp t(*this); + return t-=b; + } + + ///The time ellapsed since the last call of stamp() + TimeStamp ellapsed() const + { + TimeStamp t(NULL); + return t-*this; + } + + 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 Timer + { + TimeStamp start_time; + + void _reset() {start_time.stamp();} + + public: + ///Constructor. It starts with zero time counters + Timer() {_reset();} + + ///Computes the ellapsed time + + ///This conversion computes the ellapsed time + ///since the construction of \c t or since + ///the last \c t.reset(). + operator TimeStamp () + { + TimeStamp t; + t.stamp(); + return t-start_time; + } + + ///Resets the time counters + TimeStamp reset() + { + TimeStamp t(start_time); + _reset(); + return start_time-t; + } + }; + + ///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); + os << "u: " << double(t.getTms().tms_utime)/cls << + "s, s: " << double(t.getTms().tms_stime)/cls << + "s, cu: " << double(t.getTms().tms_cutime)/cls << + "s, cs: " << double(t.getTms().tms_cstime)/cls << + "s, real: " << t.getRealTime() << "s"; + return os; + } + + /// @} + +} //namespace hugo + +#endif //HUGO_TIME_MEASURE_H diff -r a677104e946a -r 3544872b38c2 src/work/marci/time_measure.h --- a/src/work/marci/time_measure.h Mon Apr 26 17:39:15 2004 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,182 +0,0 @@ -// -*- c++ -*- -#ifndef HUGO_TIME_MEASURE_H -#define HUGO_TIME_MEASURE_H - -///ingroup graphs -///\file -///\brief Tools for measuring cpu usage - -#include -#include -#include -#include -#include - -namespace hugo { - - /// \addtogroup misc - /// @{ - - /// A class to store (cpu)time instances. - - /// This class stores five time values. - /// - a real time - /// - a user cpu time - /// - a system cpu time - /// - a user cpu time of children - /// - a system cpu time of children - /// - /// TimeStamp's can be added to or substracted from each other and - /// they can be pushed to a stream. - - class TimeStamp - { - tms ts; - double real_time; - - public: - - tms &getTms() {return ts;} - const tms &getTms() const {return ts;} - ///Read the current time values of the process - void stamp() - { - timeval tv; - times(&ts); - gettimeofday(&tv, 0);real_time=tv.tv_sec+double(tv.tv_usec)/1e6; - } - - /// 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 - TimeStamp(void *) { stamp();} - - /// - TimeStamp &operator+=(const TimeStamp &b) - { - ts.tms_utime+=b.ts.tms_utime; - ts.tms_stime+=b.ts.tms_stime; - ts.tms_cutime+=b.ts.tms_cutime; - ts.tms_cstime+=b.ts.tms_cstime; - 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; - ts.tms_stime-=b.ts.tms_stime; - ts.tms_cutime-=b.ts.tms_cutime; - ts.tms_cstime-=b.ts.tms_cstime; - real_time-=b.real_time; - return *this; - } - /// - TimeStamp operator-(const TimeStamp &b) const - { - TimeStamp t(*this); - return t-=b; - } - - ///The time ellapsed since the last call of stamp() - TimeStamp ellapsed() const - { - TimeStamp t(NULL); - return t-*this; - } - - 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 Timer - { - TimeStamp start_time; - - void _reset() {start_time.stamp();} - - public: - ///Constructor. It starts with zero time counters - Timer() {_reset();} - - ///Computes the ellapsed time - - ///This conversion computes the ellapsed time - ///since the construction of \c t or since - ///the last \c t.reset(). - operator TimeStamp () - { - TimeStamp t; - t.stamp(); - return t-start_time; - } - - ///Resets the time counters - TimeStamp reset() - { - TimeStamp t(start_time); - _reset(); - return start_time-t; - } - }; - - ///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); - os << "u: " << double(t.getTms().tms_utime)/cls << - "s, s: " << double(t.getTms().tms_stime)/cls << - "s, cu: " << double(t.getTms().tms_cutime)/cls << - "s, cs: " << double(t.getTms().tms_cstime)/cls << - "s, real: " << t.getRealTime() << "s"; - return os; - } - - /// @} - -} //namespace hugo - -#endif //HUGO_TIME_MEASURE_H