An open source method of characteristics neutron transport code.
Timer.h
Go to the documentation of this file.
1 
8 #ifndef TIMER_H_
9 #define TIMER_H_
10 
11 #ifdef __cplusplus
12 #ifdef SWIG
13 #include "Python.h"
14 #endif
15 #include "log.h"
16 #include "constants.h"
17 #include <time.h>
18 #include <omp.h>
19 #include <iostream>
20 #include <sstream>
21 #include <fstream>
22 #include <iomanip>
23 #include <utility>
24 #include <map>
25 #include <vector>
26 #include <string>
27 #include <ios>
28 #include <unistd.h>
29 #endif
30 
31 #ifdef MPIx
32 #include <mpi.h>
33 #endif
34 
35 
40 class Timer {
41 
42 private:
43 
46  static std::vector<double> _start_times;
47 
49  float _elapsed_time;
50 
52  bool _running;
53 
55  static std::map<std::string, double> _timer_splits;
56 
62  Timer &operator=(const Timer &) { return *this; }
63 
68  Timer(const Timer &) { }
69 
70 public:
74  Timer() {
75  _running = false;
76  _elapsed_time = 0;
77  }
78 
82  virtual ~Timer() { }
83 
88  static Timer *Get() {
89  static Timer instance;
90  return &instance;
91  }
92 
93  void startTimer();
94  void stopTimer();
95  void recordSplit(const char* msg);
96  double getTime();
97  double getSplit(const char* msg);
98  void printSplits();
99  void clearSplit(const char* msg);
100  void clearSplits();
101  void processMemUsage(double& vm_usage, double& resident_set);
102 #ifdef MPIx
103  void reduceTimer(MPI_Comm comm);
104 #endif
105 };
106 
107 #endif /* TIMER_H_ */
void printSplits()
Prints the times and messages for each split to the console.
Definition: Timer.cpp:96
double getSplit(const char *msg)
Returns the time associated with a particular split.
Definition: Timer.cpp:79
double getTime()
Returns the time elapsed from startTimer() to stopTimer().
Definition: Timer.cpp:68
Math constants and comparision tolerances.
void clearSplits()
Clears all times split messages from the Timer.
Definition: Timer.cpp:136
void startTimer()
Starts the Timer.
Definition: Timer.cpp:12
void stopTimer()
Stops the Timer.
Definition: Timer.cpp:26
Timer()
Constructor sets the current split elapsed time to zero.
Definition: Timer.h:74
virtual ~Timer()
Destructor.
Definition: Timer.h:82
void recordSplit(const char *msg)
Records a message corresponding to a time for the current split.
Definition: Timer.cpp:52
static Timer * Get()
Returns a static instance of the Timer class.
Definition: Timer.h:88
The Timer class is for timing and profiling regions of code.
Definition: Timer.h:40
Utility functions for writing log messages to the screen.
void clearSplit(const char *msg)
Clears the time split for this message and deletes the message&#39;s entry in the Timer&#39;s splits log...
Definition: Timer.cpp:122
void processMemUsage(double &vm_usage, double &resident_set)
Read memory usage file (on a HPC installation), and process it to make it more readable. Used for profiling.
Definition: Timer.cpp:148