Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
timer.h
Go to the documentation of this file.
1 
14 #ifndef TIMER_INCLUDED
15 #define TIMER_INCLUDED
16 
17 //#define USE_RUSAGE
18 #undef USE_RUSAGE
19 
20 #ifdef USE_RUSAGE
21 #include <sys/resource.h>
22 #endif
23 
24 #include <cstdio>
25 #include <time.h>
26 #include <sys/time.h>
27 
28 #include "IO/bridgeIO.h"
29 using Bridge::vout;
30 
31 class Timer
32 {
33  public:
34  static const std::string class_name;
35 
36  public:
37  Timer(const std::string& id = "", const bool report = false)
38  : is_started(false), m_start(0), m_elapsed(0), m_counter(0),
39  m_id(id),
41  {}
42 
43  ~Timer();
44 
45  private:
46  // non-copyable
47  Timer(const Timer&);
48  Timer& operator=(const Timer&);
49 
50  public:
51 
52  void start();
53  void stop();
54  void reset();
55 
56  static void timestamp();
57 
58  double elapsed_sec() const;
59  double elapsed_msec() const;
60  unsigned long get_counter() const;
61 
63 
64  private:
65  bool is_started;
66  double m_start;
67 
68  double m_elapsed; // sec.
69  unsigned long m_counter;
70 
71  std::string m_id;
73 };
74 #endif /* _TIMER_H_ */
BridgeIO vout
Definition: bridgeIO.cpp:503
Timer & operator=(const Timer &)
bool m_report_on_exit
Definition: timer.h:72
double elapsed_sec() const
Definition: timer.cpp:107
void reset()
Definition: timer.cpp:97
double m_elapsed
Definition: timer.h:68
~Timer()
Definition: timer.cpp:37
bool is_started
Definition: timer.h:65
Timer(const std::string &id="", const bool report=false)
Definition: timer.h:37
double m_start
Definition: timer.h:66
unsigned long get_counter() const
Definition: timer.cpp:121
double elapsed_msec() const
Definition: timer.cpp:114
std::string m_id
Definition: timer.h:71
unsigned long m_counter
Definition: timer.h:69
void start()
Definition: timer.cpp:44
Bridge::VerboseLevel vl
VerboseLevel
Definition: bridgeIO.h:42
static void timestamp()
Definition: timer.cpp:19
Definition: timer.h:31
void stop()
Definition: timer.cpp:69
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
static const std::string class_name
Definition: timer.h:34