Class Reference for E1039 Core & Analysis Software
PHTimer2.h
Go to the documentation of this file.
1 #ifndef __PH_TIMER_2_H__
2 #define __PH_TIMER_2_H__
3 #include <iostream>
4 #include <string>
5 #include <ctime>
6 
8 
16 class PHTimer2
17 {
18  enum State { STOP, RUN };
19 
20  std::string m_name;
21  State m_state;
22  timespec m_time_start;
23  timespec m_time_stop;
24  double m_time_acc;
25  unsigned int m_n_cycle;
26 
27  public:
28  PHTimer2(const std::string& name="Generic Timer");
29  virtual ~PHTimer2();
30 
31  void set_name(const std::string& name) { m_name = name; }
32  std::string get_name() const { return m_name; }
33 
34  double get_accumulated_time() const { return m_time_acc; }
35  unsigned int get_ncycle () const { return m_n_cycle; }
36  double get_time_per_cycle () const;
37 
38  void reset();
39  void stop();
40  void restart();
41  void reset_and_start();
42 
43  void print_stat(std::string header=" Timer2:", std::ostream& os=std::cout) const;
44 
46  void test(unsigned int time_msec, std::ostream& os=std::cout);
47 
48  protected:
49  double elapsed() const;
50  int get_clock_time(timespec* tp);
51 };
52 
53 #endif
Class to measure the time spent by a code block.
Definition: PHTimer2.h:17
void print_stat(std::string header=" Timer2:", std::ostream &os=std::cout) const
Definition: PHTimer2.cc:54
PHTimer2(const std::string &name="Generic Timer")
Definition: PHTimer2.cc:7
unsigned int get_ncycle() const
Definition: PHTimer2.h:35
double elapsed() const
In millisecond.
Definition: PHTimer2.cc:72
double get_accumulated_time() const
Definition: PHTimer2.h:34
void reset()
Definition: PHTimer2.cc:26
void test(unsigned int time_msec, std::ostream &os=std::cout)
Test this class by waiting for a given time (in ms).
Definition: PHTimer2.cc:62
virtual ~PHTimer2()
Definition: PHTimer2.cc:16
double get_time_per_cycle() const
Definition: PHTimer2.cc:21
void reset_and_start()
Definition: PHTimer2.cc:48
std::string get_name() const
Definition: PHTimer2.h:32
void restart()
Definition: PHTimer2.cc:42
int get_clock_time(timespec *tp)
Definition: PHTimer2.cc:82
void stop()
Definition: PHTimer2.cc:33
void set_name(const std::string &name)
Definition: PHTimer2.h:31