ls1-MarDyn
ls1-MarDyn molecular dynamics code
TimerProfiler.h
1/*
2 * TimerProfiler.h
3 *
4 * Created on: Apr 9, 2017
5 * Author: Andrei Costinescu
6 */
7
8#ifndef SRC_IO_TIMERPROFILER_H_
9#define SRC_IO_TIMERPROFILER_H_
10
11#include <iostream>
12#include <map>
13#include <memory>
14#include <vector>
15
16#include "utils/Timer.h"
17
18class XMLfileUnits;
19
29public:
30
31 enum class Displaymode {
32 ALL,
33 ACTIVE,
34 NON_ZERO,
35 NONE
36 };
37
46
61 void readXML(XMLfileUnits& xmlconfig);
62
63 void setDisplayMode(Displaymode mode) { _displayMode = mode; }
64 Displaymode getDisplayMode() { return _displayMode; }
65
74 void registerTimer(std::string timerName, std::vector<std::string> parentTimerNames, Timer *timer=nullptr, bool activate=true);
75
82 Timer* getTimer(std::string timerName);
83
89 void activateTimer(std::string timerName);
90
96 void deactivateTimer(std::string timerName);
97
104 void setSyncTimer(std::string timerName, bool sync);
105
112 void print(std::string timerName, std::string outputPrefix="");
113
120 void printTimers(std::string timerName=_baseTimerName, std::string outputPrefix="");
121
127 void start(std::string timerName);
128
134 void stop(std::string timerName);
135
141 void reset(std::string timerName);
142
148 void resetTimers(std::string timerName=_baseTimerName);
149
159
166 void setOutputString(std::string timerName, std::string outputString);
167
174 std::string getOutputString(std::string timerName);
175
182 double getTime(std::string timerName);
183
189 ++_numElapsedIterations;
190 }
191
197 unsigned long getNumElapsedIterations() const {
198 return _numElapsedIterations;
199 }
200
201private:
206 static const std::string _baseTimerName;
207
216 bool _checkTimer(std::string timerName, bool checkActive=true);
217
223 void _debugMessage(std::string timerName);
224
229 class _Timer{
230 public:
236 _Timer(std::string timerName="", Timer* timer=nullptr,
237 std::vector<std::string>childTimerNames={}, std::vector<std::string>parentTimerNames={},
238 std::string outputString=""):
239 _timer(timer), _childTimerNames(childTimerNames), _parentTimerNames(parentTimerNames),
240 _outputString(outputString), _timerName(timerName) {}
241
246 std::unique_ptr<Timer> _timer;
247
252 std::vector<std::string> _childTimerNames;
253
258 std::vector<std::string> _parentTimerNames;
259
265 std::string _outputString;
266
271 std::string _timerName;
272 };
273
280 std::map<std::string, _Timer> _timers;
281
282 unsigned long _numElapsedIterations;
283
284 Displaymode _displayMode;
285};
286
287#endif /* SRC_IO_TIMERPROFILER_H_ */
Class for managing timers across the simulation.
Definition: TimerProfiler.h:28
void start(std::string timerName)
Starts the timer "timerName".
Definition: TimerProfiler.cpp:110
Timer * getTimer(std::string timerName)
Gets a pointer to the timer with name "timerName".
Definition: TimerProfiler.cpp:46
double getTime(std::string timerName)
Gets the time collected by timer "timerName".
Definition: TimerProfiler.cpp:257
unsigned long getNumElapsedIterations() const
get the number of iterations since the last resetting of all timers.
Definition: TimerProfiler.h:197
void setSyncTimer(std::string timerName, bool sync)
Sets sync mode of the timer "timerName".
Definition: TimerProfiler.cpp:81
void incrementTimerTimestepCounter()
Increment the timestep-counter.
Definition: TimerProfiler.h:188
void resetTimers(std::string timerName=_baseTimerName)
Resets the timer "timerName" and all of its descendants.
Definition: TimerProfiler.cpp:145
void setOutputString(std::string timerName, std::string outputString)
Sets the output string for the timer output.
Definition: TimerProfiler.cpp:240
void readXML(XMLfileUnits &xmlconfig)
Read in XML configuration for TimerProfiler.
Definition: TimerProfiler.cpp:27
void readInitialTimersFromFile(std::string fileName)
Sets up initial configuration of the timers during the simulation.
Definition: TimerProfiler.cpp:157
void activateTimer(std::string timerName)
Activates the timer "timerName".
Definition: TimerProfiler.cpp:71
void printTimers(std::string timerName=_baseTimerName, std::string outputPrefix="")
Prints time collected by timer "timerName" and the time from all of its descendants.
Definition: TimerProfiler.cpp:99
void registerTimer(std::string timerName, std::vector< std::string > parentTimerNames, Timer *timer=nullptr, bool activate=true)
Adds a timer in the container.
Definition: TimerProfiler.cpp:54
TimerProfiler()
Constructor of TimerProfiler.
Definition: TimerProfiler.cpp:22
void deactivateTimer(std::string timerName)
Deactivates the timer "timerName".
Definition: TimerProfiler.cpp:76
This class is used to measure times in sequential and parallel versions.
Definition: Timer.h:59
XML file with unit attributes abstraction.
Definition: xmlfileUnits.h:25
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
Definition: vtk-punstructured.h:270