time_measure.h went to src/include.
authoralpar
Mon, 26 Apr 2004 17:39:38 +0000
changeset 4283544872b38c2
parent 427 a677104e946a
child 429 0e83db759894
time_measure.h went to src/include.
src/include/time_measure.h
src/work/marci/time_measure.h
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/include/time_measure.h	Mon Apr 26 17:39:38 2004 +0000
     1.3 @@ -0,0 +1,182 @@
     1.4 +// -*- c++ -*-
     1.5 +#ifndef HUGO_TIME_MEASURE_H
     1.6 +#define HUGO_TIME_MEASURE_H
     1.7 +
     1.8 +///ingroup graphs
     1.9 +///\file
    1.10 +///\brief Tools for measuring cpu usage
    1.11 +
    1.12 +#include <sys/time.h>
    1.13 +#include <sys/times.h>
    1.14 +#include <fstream>
    1.15 +#include <iostream>
    1.16 +#include <unistd.h>
    1.17 +
    1.18 +namespace hugo {
    1.19 +
    1.20 +  /// \addtogroup misc
    1.21 +  /// @{
    1.22 +
    1.23 +  /// A class to store (cpu)time instances.
    1.24 +
    1.25 +  /// This class stores five time values.
    1.26 +  /// - a real time
    1.27 +  /// - a user cpu time
    1.28 +  /// - a system cpu time
    1.29 +  /// - a user cpu time of children
    1.30 +  /// - a system cpu time of children
    1.31 +  ///
    1.32 +  /// TimeStamp's can be added to or substracted from each other and
    1.33 +  /// they can be pushed to a stream.
    1.34 +
    1.35 +  class TimeStamp
    1.36 +  {
    1.37 +    tms ts;
    1.38 +    double real_time;
    1.39 +  
    1.40 +  public:
    1.41 +
    1.42 +    tms &getTms() {return ts;}
    1.43 +    const tms &getTms() const {return ts;}
    1.44 +    ///Read the current time values of the process
    1.45 +    void stamp()
    1.46 +    {
    1.47 +      timeval tv;
    1.48 +      times(&ts);
    1.49 +      gettimeofday(&tv, 0);real_time=tv.tv_sec+double(tv.tv_usec)/1e6;
    1.50 +    }
    1.51 +  
    1.52 +    /// Constructor initializing with zero
    1.53 +    TimeStamp()
    1.54 +    { ts.tms_utime=ts.tms_stime=ts.tms_cutime=ts.tms_cstime=0; real_time=0;}
    1.55 +    ///Constructor initializing with the current time values of the process
    1.56 +    TimeStamp(void *) { stamp();}
    1.57 +  
    1.58 +    ///
    1.59 +    TimeStamp &operator+=(const TimeStamp &b)
    1.60 +    {
    1.61 +      ts.tms_utime+=b.ts.tms_utime;
    1.62 +      ts.tms_stime+=b.ts.tms_stime;
    1.63 +      ts.tms_cutime+=b.ts.tms_cutime;
    1.64 +      ts.tms_cstime+=b.ts.tms_cstime;
    1.65 +      real_time+=b.real_time;
    1.66 +      return *this;
    1.67 +    }
    1.68 +    ///
    1.69 +    TimeStamp operator+(const TimeStamp &b) const
    1.70 +    {
    1.71 +      TimeStamp t(*this);
    1.72 +      return t+=b;
    1.73 +    }
    1.74 +    ///
    1.75 +    TimeStamp &operator-=(const TimeStamp &b)
    1.76 +    {
    1.77 +      ts.tms_utime-=b.ts.tms_utime;
    1.78 +      ts.tms_stime-=b.ts.tms_stime;
    1.79 +      ts.tms_cutime-=b.ts.tms_cutime;
    1.80 +      ts.tms_cstime-=b.ts.tms_cstime;
    1.81 +      real_time-=b.real_time;
    1.82 +      return *this;
    1.83 +    }
    1.84 +    ///
    1.85 +    TimeStamp operator-(const TimeStamp &b) const
    1.86 +    {
    1.87 +      TimeStamp t(*this);
    1.88 +      return t-=b;
    1.89 +    }
    1.90 +
    1.91 +    ///The time ellapsed since the last call of stamp()
    1.92 +    TimeStamp ellapsed() const
    1.93 +    {
    1.94 +      TimeStamp t(NULL);
    1.95 +      return t-*this;
    1.96 +    }
    1.97 +  
    1.98 +    friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t);
    1.99 +  
   1.100 +    ///Gives back the user time of the process
   1.101 +    double getUserTime() const
   1.102 +    {
   1.103 +      return double(ts.tms_utime)/sysconf(_SC_CLK_TCK);
   1.104 +    }
   1.105 +    ///Gives back the system time of the process
   1.106 +    double getSystemTime() const
   1.107 +    {
   1.108 +      return double(ts.tms_stime)/sysconf(_SC_CLK_TCK);
   1.109 +    }
   1.110 +    ///Gives back the user time of the process' children
   1.111 +    double getCUserTime() const
   1.112 +    {
   1.113 +      return double(ts.tms_cutime)/sysconf(_SC_CLK_TCK);
   1.114 +    }
   1.115 +    ///Gives back the user time of the process' children
   1.116 +    double getCSystemTime() const
   1.117 +    {
   1.118 +      return double(ts.tms_cstime)/sysconf(_SC_CLK_TCK);
   1.119 +    }
   1.120 +    ///Gives back the real time of the process
   1.121 +    double getRealTime() const {return real_time;}
   1.122 +  };
   1.123 +
   1.124 +  ///Class measuring the cpu time and real time usage of the process
   1.125 +  class Timer
   1.126 +  {
   1.127 +    TimeStamp start_time;
   1.128 +
   1.129 +    void _reset() {start_time.stamp();}
   1.130 +  
   1.131 +  public: 
   1.132 +    ///Constructor. It starts with zero time counters
   1.133 +    Timer() {_reset();}
   1.134 +
   1.135 +    ///Computes the ellapsed time
   1.136 +
   1.137 +    ///This conversion computes the ellapsed time
   1.138 +    ///since the construction of \c t or since
   1.139 +    ///the last \c t.reset().
   1.140 +    operator TimeStamp ()
   1.141 +    {
   1.142 +      TimeStamp t;
   1.143 +      t.stamp();
   1.144 +      return t-start_time;
   1.145 +    }
   1.146 +
   1.147 +    ///Resets the time counters
   1.148 +    TimeStamp reset()
   1.149 +    {
   1.150 +      TimeStamp t(start_time);
   1.151 +      _reset();
   1.152 +      return start_time-t;
   1.153 +    }
   1.154 +  };
   1.155 +
   1.156 +  ///Prints the time counters
   1.157 +
   1.158 +  ///Prints the time counters in the folloing form:
   1.159 +  ///
   1.160 +  /// u: XX.XXs s: XX.XXs cu: XX.XXs cs: XX.XXs real: XX.XXs 
   1.161 +  ///
   1.162 +  /// where the values are the
   1.163 +  /// - a user cpu time,
   1.164 +  /// - a system cpu time,
   1.165 +  /// - a user cpu time of children,
   1.166 +  /// - a system cpu time of children and
   1.167 +  /// - a real time,
   1.168 +  ///
   1.169 +  ///respectively
   1.170 +  inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t)
   1.171 +  {
   1.172 +    long cls = sysconf(_SC_CLK_TCK);
   1.173 +    os << "u: " << double(t.getTms().tms_utime)/cls <<
   1.174 +      "s, s: " << double(t.getTms().tms_stime)/cls <<
   1.175 +      "s, cu: " << double(t.getTms().tms_cutime)/cls <<
   1.176 +      "s, cs: " << double(t.getTms().tms_cstime)/cls <<
   1.177 +      "s, real: " << t.getRealTime() << "s";
   1.178 +    return os;
   1.179 +  }
   1.180 +
   1.181 +  /// @}  
   1.182 +
   1.183 +} //namespace hugo
   1.184 +
   1.185 +#endif //HUGO_TIME_MEASURE_H
     2.1 --- a/src/work/marci/time_measure.h	Mon Apr 26 17:39:15 2004 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,182 +0,0 @@
     2.4 -// -*- c++ -*-
     2.5 -#ifndef HUGO_TIME_MEASURE_H
     2.6 -#define HUGO_TIME_MEASURE_H
     2.7 -
     2.8 -///ingroup graphs
     2.9 -///\file
    2.10 -///\brief Tools for measuring cpu usage
    2.11 -
    2.12 -#include <sys/time.h>
    2.13 -#include <sys/times.h>
    2.14 -#include <fstream>
    2.15 -#include <iostream>
    2.16 -#include <unistd.h>
    2.17 -
    2.18 -namespace hugo {
    2.19 -
    2.20 -  /// \addtogroup misc
    2.21 -  /// @{
    2.22 -
    2.23 -  /// A class to store (cpu)time instances.
    2.24 -
    2.25 -  /// This class stores five time values.
    2.26 -  /// - a real time
    2.27 -  /// - a user cpu time
    2.28 -  /// - a system cpu time
    2.29 -  /// - a user cpu time of children
    2.30 -  /// - a system cpu time of children
    2.31 -  ///
    2.32 -  /// TimeStamp's can be added to or substracted from each other and
    2.33 -  /// they can be pushed to a stream.
    2.34 -
    2.35 -  class TimeStamp
    2.36 -  {
    2.37 -    tms ts;
    2.38 -    double real_time;
    2.39 -  
    2.40 -  public:
    2.41 -
    2.42 -    tms &getTms() {return ts;}
    2.43 -    const tms &getTms() const {return ts;}
    2.44 -    ///Read the current time values of the process
    2.45 -    void stamp()
    2.46 -    {
    2.47 -      timeval tv;
    2.48 -      times(&ts);
    2.49 -      gettimeofday(&tv, 0);real_time=tv.tv_sec+double(tv.tv_usec)/1e6;
    2.50 -    }
    2.51 -  
    2.52 -    /// Constructor initializing with zero
    2.53 -    TimeStamp()
    2.54 -    { ts.tms_utime=ts.tms_stime=ts.tms_cutime=ts.tms_cstime=0; real_time=0;}
    2.55 -    ///Constructor initializing with the current time values of the process
    2.56 -    TimeStamp(void *) { stamp();}
    2.57 -  
    2.58 -    ///
    2.59 -    TimeStamp &operator+=(const TimeStamp &b)
    2.60 -    {
    2.61 -      ts.tms_utime+=b.ts.tms_utime;
    2.62 -      ts.tms_stime+=b.ts.tms_stime;
    2.63 -      ts.tms_cutime+=b.ts.tms_cutime;
    2.64 -      ts.tms_cstime+=b.ts.tms_cstime;
    2.65 -      real_time+=b.real_time;
    2.66 -      return *this;
    2.67 -    }
    2.68 -    ///
    2.69 -    TimeStamp operator+(const TimeStamp &b) const
    2.70 -    {
    2.71 -      TimeStamp t(*this);
    2.72 -      return t+=b;
    2.73 -    }
    2.74 -    ///
    2.75 -    TimeStamp &operator-=(const TimeStamp &b)
    2.76 -    {
    2.77 -      ts.tms_utime-=b.ts.tms_utime;
    2.78 -      ts.tms_stime-=b.ts.tms_stime;
    2.79 -      ts.tms_cutime-=b.ts.tms_cutime;
    2.80 -      ts.tms_cstime-=b.ts.tms_cstime;
    2.81 -      real_time-=b.real_time;
    2.82 -      return *this;
    2.83 -    }
    2.84 -    ///
    2.85 -    TimeStamp operator-(const TimeStamp &b) const
    2.86 -    {
    2.87 -      TimeStamp t(*this);
    2.88 -      return t-=b;
    2.89 -    }
    2.90 -
    2.91 -    ///The time ellapsed since the last call of stamp()
    2.92 -    TimeStamp ellapsed() const
    2.93 -    {
    2.94 -      TimeStamp t(NULL);
    2.95 -      return t-*this;
    2.96 -    }
    2.97 -  
    2.98 -    friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t);
    2.99 -  
   2.100 -    ///Gives back the user time of the process
   2.101 -    double getUserTime() const
   2.102 -    {
   2.103 -      return double(ts.tms_utime)/sysconf(_SC_CLK_TCK);
   2.104 -    }
   2.105 -    ///Gives back the system time of the process
   2.106 -    double getSystemTime() const
   2.107 -    {
   2.108 -      return double(ts.tms_stime)/sysconf(_SC_CLK_TCK);
   2.109 -    }
   2.110 -    ///Gives back the user time of the process' children
   2.111 -    double getCUserTime() const
   2.112 -    {
   2.113 -      return double(ts.tms_cutime)/sysconf(_SC_CLK_TCK);
   2.114 -    }
   2.115 -    ///Gives back the user time of the process' children
   2.116 -    double getCSystemTime() const
   2.117 -    {
   2.118 -      return double(ts.tms_cstime)/sysconf(_SC_CLK_TCK);
   2.119 -    }
   2.120 -    ///Gives back the real time of the process
   2.121 -    double getRealTime() const {return real_time;}
   2.122 -  };
   2.123 -
   2.124 -  ///Class measuring the cpu time and real time usage of the process
   2.125 -  class Timer
   2.126 -  {
   2.127 -    TimeStamp start_time;
   2.128 -
   2.129 -    void _reset() {start_time.stamp();}
   2.130 -  
   2.131 -  public: 
   2.132 -    ///Constructor. It starts with zero time counters
   2.133 -    Timer() {_reset();}
   2.134 -
   2.135 -    ///Computes the ellapsed time
   2.136 -
   2.137 -    ///This conversion computes the ellapsed time
   2.138 -    ///since the construction of \c t or since
   2.139 -    ///the last \c t.reset().
   2.140 -    operator TimeStamp ()
   2.141 -    {
   2.142 -      TimeStamp t;
   2.143 -      t.stamp();
   2.144 -      return t-start_time;
   2.145 -    }
   2.146 -
   2.147 -    ///Resets the time counters
   2.148 -    TimeStamp reset()
   2.149 -    {
   2.150 -      TimeStamp t(start_time);
   2.151 -      _reset();
   2.152 -      return start_time-t;
   2.153 -    }
   2.154 -  };
   2.155 -
   2.156 -  ///Prints the time counters
   2.157 -
   2.158 -  ///Prints the time counters in the folloing form:
   2.159 -  ///
   2.160 -  /// u: XX.XXs s: XX.XXs cu: XX.XXs cs: XX.XXs real: XX.XXs 
   2.161 -  ///
   2.162 -  /// where the values are the
   2.163 -  /// - a user cpu time,
   2.164 -  /// - a system cpu time,
   2.165 -  /// - a user cpu time of children,
   2.166 -  /// - a system cpu time of children and
   2.167 -  /// - a real time,
   2.168 -  ///
   2.169 -  ///respectively
   2.170 -  inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t)
   2.171 -  {
   2.172 -    long cls = sysconf(_SC_CLK_TCK);
   2.173 -    os << "u: " << double(t.getTms().tms_utime)/cls <<
   2.174 -      "s, s: " << double(t.getTms().tms_stime)/cls <<
   2.175 -      "s, cu: " << double(t.getTms().tms_cutime)/cls <<
   2.176 -      "s, cs: " << double(t.getTms().tms_cstime)/cls <<
   2.177 -      "s, real: " << t.getRealTime() << "s";
   2.178 -    return os;
   2.179 -  }
   2.180 -
   2.181 -  /// @}  
   2.182 -
   2.183 -} //namespace hugo
   2.184 -
   2.185 -#endif //HUGO_TIME_MEASURE_H