CARMA C++
StopWatch.h
Go to the documentation of this file.
1 #ifndef CARMA_UTIL_STOPWATCH_H
2 #define CARMA_UTIL_STOPWATCH_H
3 
11 #include <string>
12 #include <time.h>
13 
14 namespace carma {
15 namespace util {
16 
22 class StopWatch {
23 public:
27  enum ClockType {
28  WALL_CLOCK = 0,
29  CPU_TIME = 1
30  };
31 
35  explicit StopWatch( );
36 
40  explicit StopWatch( ClockType type );
41 
45  explicit StopWatch( const ::std::string & name );
46 
50  StopWatch( ClockType type,
51  const ::std::string & name );
52 
56  ~StopWatch();
57 
62  void start();
63 
68  void stop();
69 
73  bool isRunning() const;
74 
78  double getElapsedTime() const;
79 
83  double getCumulativeElapsedTime(bool reset=false);
84 
85 protected:
86  const ClockType type_;
87  const ::std::string name_;
88 
89  double startTime_;
90  double elapsedTime_;
91  double cumulativeElapsedTime_;
92  bool running_;
93  struct timespec scratchTimeSpec_;
94 };
95 
96 } // end namespace util
97 } // end namespace carma
98 
99 #endif //CARMA_UTIL_STOPWATCH_H
bool isRunning() const
is the watch running?
void stop()
stop the watch
void start()
start the watch
ClockType
enumeration for clock type
Definition: StopWatch.h:27
StopWatch()
constructor
~StopWatch()
destructor, does nothing
Class for determining the elapsed wall-clock or CPU time between two events.
Definition: StopWatch.h:22
double getElapsedTime() const
get the time interval in seconds between the last start() and stop()
double getCumulativeElapsedTime(bool reset=false)
get the the sum of the time intervals between each start and stop pair