PetaVision  Alpha
Clock.hpp
1 /*
2  * Clock.hpp
3  *
4  * Created on: Jun 6, 2016
5  * Author: pschultz
6  */
7 
8 #ifndef CLOCK_HPP_
9 #define CLOCK_HPP_
10 
11 #include <ostream>
12 #include <stdint.h>
13 #include <sys/resource.h>
14 #include <sys/time.h>
15 #include <time.h>
16 
17 // #define MACH_TIMER 1
18 #undef MACH_TIMER
19 #ifdef MACH_TIMER
20 #include <CoreServices/CoreServices.h>
21 #include <mach/mach.h>
22 #include <mach/mach_time.h>
23 #endif // MACH_TIMER
24 
25 // #define CYCLE_TIMER 1
26 #undef CYCLE_TIMER
27 
28 namespace PV {
29 
30 class Clock {
31  public:
32  void start_clock();
33  void stop_clock();
34  void print_elapsed(std::ostream &stream);
35 #ifdef MACH_TIMER
36  double elapsed_time();
37  double mach_time_to_sec(uint64_t elapsed);
38 #endif // MACH_TIMER
39 
40  // Data members
41  private:
42  clock_t m_start;
43  clock_t m_end;
44  double m_rstart;
45  double m_rend;
46  double m_tstart;
47  double m_tend;
48 
49  struct timeval m_tv_start;
50  struct timeval m_tv_end;
51 
52 #ifdef CYCLE_TIMER
53  uint64_t m_cycle_start;
54  uint64_t m_cycle_end;
55 #endif
56 
57 #ifdef MACH_TIMER
58  uint64_t m_mach_start;
59  uint64_t m_mach_end;
60  mach_timebase_info_data_t sTimebaseInfo;
61 #endif
62 };
63 
64 } // namespace PV
65 
66 #endif /* CLOCK_HPP_ */