26 #ifndef EWOMS_TIMER_HH
27 #define EWOMS_TIMER_HH
53 #if defined(CLOCK_MONOTONIC) && defined(CLOCK_PROCESS_CPUTIME_ID)
54 struct timespec realtimeData;
55 struct timespec cputimeData;
57 std::chrono::high_resolution_clock::time_point realtimeData;
58 std::chrono::high_resolution_clock::time_point cputimeData;
91 stopTime_ = startTime_;
102 TimeData stopTime(stopTime_);
107 const auto &t1 = startTime_.realtimeData;
108 const auto &t2 = stopTime.realtimeData;
110 #if defined(CLOCK_MONOTONIC) && defined(CLOCK_PROCESS_CPUTIME_ID)
112 static_cast<double>(t2.tv_sec - t1.tv_sec)
113 + static_cast<double>(t2.tv_nsec - t1.tv_nsec)/1e9;
115 std::chrono::duration<double> dt =
116 std::chrono::duration_cast<std::chrono::duration<double> >(t2 - t1);
129 TimeData stopTime(stopTime_);
134 const auto &t1 = startTime_.cputimeData;
135 const auto &t2 = stopTime.cputimeData;
137 #if defined(CLOCK_MONOTONIC) && defined(CLOCK_PROCESS_CPUTIME_ID)
139 static_cast<double>(t2.tv_sec - t1.tv_sec)
140 + static_cast<double>(t2.tv_nsec - t1.tv_nsec)/1e9;
142 std::chrono::duration<double> dt =
143 std::chrono::duration_cast<std::chrono::duration<double> >(t2 - t1);
157 TimeData stopTime(stopTime_);
163 double globalVal = val;
180 static void measure_(TimeData& timeData)
184 #if defined(CLOCK_MONOTONIC) && defined(CLOCK_PROCESS_CPUTIME_ID)
186 clock_gettime(CLOCK_MONOTONIC, &timeData.realtimeData);
189 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &timeData.cputimeData);
191 timeData.realtimeData = std::chrono::high_resolution_clock::now();
192 timeData.cputimeData = std::chrono::high_resolution_clock::now();
void halt()
Stop the measurement and always return 0 for all timing values.
Definition: timer.hh:86
Timer()
Definition: timer.hh:62
double cpuTimeElapsed() const
Return the CPU time [s] used by all threads of the local process.
Definition: timer.hh:127
double globalCpuTimeElapsed() const
Return the CPU time [s] used by all threads of the all processes of the simulation.
Definition: timer.hh:155
Definition: baseauxiliarymodule.hh:35
double realTimeElapsed() const
Return the real time [s] elapsed.
Definition: timer.hh:100
Provides an encapsulation to measure the system time.
Definition: timer.hh:47
void start()
Start counting the time resources used by the simulation.
Definition: timer.hh:68
void stop()
Stop counting the time resources used by the simulation.
Definition: timer.hh:77