walltimer.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef PLANCK_WALLTIMER_H
00033 #define PLANCK_WALLTIMER_H
00034
00035 #include <string>
00036 #include <map>
00037 #include <vector>
00038
00039 class wallTimer
00040 {
00041 private:
00042 double t_acc, t_started;
00043 bool running;
00044
00045 public:
00046 wallTimer() : t_acc(0.), t_started(0.), running(false) {}
00047 void start(double wtime_now)
00048 { if (!running) { t_started=wtime_now; running=true; } }
00049 void start();
00050 void stop(double wtime_now)
00051 { if (running) { t_acc+=wtime_now-t_started; running=false; } }
00052 void stop();
00053 void reset() { t_acc=t_started=0.; running=false;}
00054 double acc(double wtime_now) const
00055 { return running ? t_acc+wtime_now-t_started : t_acc; }
00056 double acc() const;
00057 };
00058
00059 class wallTimerSet
00060 {
00061 public:
00062 typedef std::map<std::string,int> maptype;
00063
00064 private:
00065 maptype lut;
00066 std::vector<wallTimer> timer;
00067
00068 public:
00069 int getIndex(const std::string &name);
00070 void start(int index);
00071 void stop(int index);
00072 void stopstart(int index1, int index2);
00073 void reset(int index);
00074 double acc(int index);
00075 void start(const std::string &name);
00076 void stop(const std::string &name);
00077 void stopstart(const std::string &name1, const std::string &name2);
00078 void reset(const std::string &name);
00079 double acc(const std::string &name);
00080
00081 void report() const;
00082
00083 const maptype &table() const { return lut; }
00084 };
00085
00086 extern wallTimerSet wallTimers;
00087
00088 void tstack_push(const std::string &name);
00089 void tstack_pop(const std::string &name);
00090 void tstack_pop();
00091 void tstack_replace(const std::string &name1, const std::string &name2);
00092 void tstack_replace(const std::string &name);
00093 void tstack_report(const std::string &stem);
00094
00095 #endif