HOPS
HOPS class reference
MHO_Timer.hh
Go to the documentation of this file.
1 #ifndef MHO_Timer_HH__
2 #define MHO_Timer_HH__
3 
4 #include <ctime>
5 #include <string>
6 
7 namespace hops
8 {
9 
10 /*!*
11  *@file MHO_Timer.hh
12  *@class MHO_Timer
13  *@author J. Barrett - barrettj@mit.edu
14  *@brief Class MHO_Timer - A timer class responsible for thread and process benchmarking
15  * For more information on the linux system variables and functions that were leveraged see:
16  * https://linux.die.net/man/3/clock_gettime
17  * TODO -- detect if system actually has a realtime clock and disable if not present
18  */
19 
20 class MHO_Timer
21 {
22  public:
23  MHO_Timer();
24  MHO_Timer(std::string name);
25  virtual ~MHO_Timer();
26 
31  void SetName(std::string name) { fName = name; };
32 
33  /*!* Get the timer name
34  * @param None
35  * @return fName string timer name
36  */
37  std::string GetName() const { return fName; };
38 
39  //set the clock type used
40  /*!* Set the timer's clock ID to that of the linux system wide realtime clock
41  * @param None
42  * @returns None
43  */
44  void MeasureWallclockTime(); //CLOCK_REALTIME
45 
46  /*!* Get the ID for the process clock
47  * @param None
48  * @returns None
49  */
50  void MeasureProcessTime(); //CLOCK_PROCESS_CPUTIME_ID
51 
52  /*!* Get the ID for the thread clock which indicates the time used by all threads in the process
53  * @param None
54  * @returns None
55  */
56  void MeasureThreadTime(); //CLOCK_THREAD_CPUTIME_ID
57 
58  /*!* Store the current linux system time as the start time of a timer in a timespec struct
59  * @param None
60  * @returns None
61  */
62  void Start();
63 
64  /*!* Store the current linux system time as the stop time of a timer in a timespec struct
65  * @param None
66  * @returns None
67  */
68  void Stop();
69 
70  /*!* Call GetTimeDifference and return the result as a timespec struct
71  * @param None
72  * @returns ret_val timespec which is a struct containing the start and stop time in seconds and nanoseconds as two seperate values
73  */
74  timespec GetDurationAsTimeSpec() const;
75 
76  /*!* Call GetTimeDifference and return the result as a double
77  * @param None
78  * @returns ret_val double which contains the start and stop time in seconds
79  */
80  double GetDurationAsDouble() const;
81 
82  //Get the time since the start without stopping the timer
83  double GetTimeSinceStart() const;
84 
85  protected:
86  /*!* Calculate total compute time spent on a process or thread and store the result in a timespec struct
87  * @param start timespec which is the start time for a process or thread
88  * @param stop timespec which is the start time for a process or thread
89  * @returns ret_val timespec which contains the time spent on a given process or thread in seconds and nanoseconds
90  */
91  timespec GetTimeDifference(const timespec& start, const timespec& stop) const;
92 
93  std::string fName;
94  clockid_t fClockID;
95  timespec fStart;
96  timespec fStop;
97 };
98 
99 } // namespace hops
100 
101 #endif
Class MHO_Timer - A timer class responsible for thread and process benchmarking For more information ...
Definition: MHO_Timer.hh:21
void MeasureWallclockTime()
Definition: Message/src/MHO_Timer.cc:22
timespec GetDurationAsTimeSpec() const
Definition: Message/src/MHO_Timer.cc:63
std::string fName
Definition: MHO_Timer.hh:93
timespec GetTimeDifference(const timespec &start, const timespec &stop) const
Definition: Message/src/MHO_Timer.cc:47
timespec fStart
Definition: MHO_Timer.hh:95
double GetTimeSinceStart() const
Definition: Message/src/MHO_Timer.cc:68
timespec fStop
Definition: MHO_Timer.hh:96
std::string GetName() const
Definition: MHO_Timer.hh:37
void MeasureProcessTime()
Definition: Message/src/MHO_Timer.cc:27
void SetName(std::string name)
Definition: MHO_Timer.hh:31
clockid_t fClockID
Definition: MHO_Timer.hh:94
double GetDurationAsDouble() const
Definition: Message/src/MHO_Timer.cc:78
void MeasureThreadTime()
Definition: Message/src/MHO_Timer.cc:32
void Stop()
Definition: Message/src/MHO_Timer.cc:42
void Start()
Definition: Message/src/MHO_Timer.cc:37
virtual ~MHO_Timer()
Definition: Message/src/MHO_Timer.cc:18
MHO_Timer()
Definition: Message/src/MHO_Timer.cc:8
Definition: MHO_ChannelLabeler.hh:17