NeoPZ
TPZTimer.h
Go to the documentation of this file.
1 
7 #ifndef TPZTIMER_H
8 #define TPZTIMER_H
9 
10 #include <string>
11 #include <vector>
12 #include <iostream>
13 
14 #include <time.h>
15 
23 {
26 
28  clock_t start;
30  clock_t elapsed;
31 }; // Change from the original "RESUSE".
32 
33 
34 //--| TPZTimer |----------------------------------------------------------------
35 
46 class TPZTimer
47 {
48 public:
49  /* @brief Empty constructor */
50  TPZTimer();
51 
57  TPZTimer( std::string pn );
58 
60  ~TPZTimer();
61 
63  std::string& processName();
64 
66  const std::string& processName() const;
67 
69  void start();
70 
72  void stop();
73 
75  void reset();
76 
78  double seconds() const;
79 
81  friend std::ostream& operator<<( std::ostream& Out, const TPZTimer& t );
82 
83 private:
86 
88  double AccumSec;
89 
91  std::string ProcessName;
92 };
93 
94 //--| TPZMultiTimer |-----------------------------------------------------------
95 
101 {
102 public:
107  TPZMultiTimer( int nT );
108 
110  ~TPZMultiTimer();
111 
113  int nTimers() const;
114 
116  TPZTimer& getTimer( int i );
117 
119  const TPZTimer& getTimer( int i ) const;
120 
122  std::string& processName( int i );
123 
125  const std::string& processName( int i ) const;
126 
128  void start( int i );
129 
131  void start();
132 
134  void stop( int i );
135 
137  void stop();
138 
140  void reset( int i );
141 
143  void reset();
144 
146  double seconds( int i ) const;
147 
149  friend std::ostream& operator<<( std::ostream& Out, const TPZMultiTimer& t );
150 
151 private:
153  std::vector< TPZTimer > timers;
154 };
155 
156 //--| IMPLEMENTATION :: TPZTimer |----------------------------------------------
157 
158 // Empty constructor.
159 inline TPZTimer::TPZTimer() : AccumSec( 0.0 ), ProcessName( "" ) {}
160 
161 // Default constructor.
162 inline TPZTimer::TPZTimer( std::string pn ) : AccumSec( 0.0 ), ProcessName( pn ) {}
163 
164 // Destructor.
166 
167 // Gets the process name (for reporting purposes).
168 inline std::string& TPZTimer::processName()
169 {
170  return ProcessName;
171 }
172 
173 // Gets the process name (for reporting purposes).
174 inline const std::string& TPZTimer::processName() const
175 {
176  return ProcessName;
177 }
178 
179 // Resets the timer.
180 inline void TPZTimer::reset()
181 {
182  AccumSec = 0.0;
183 }
184 
185 // Returns the total accumulated time in seconds.
186 inline double TPZTimer::seconds() const
187 {
188  return AccumSec;
189 }
190 
191 //--| IMPLEMENTATION :: TPZMultiTimer |-----------------------------------------
192 
193 // Default constructor.
194 inline TPZMultiTimer::TPZMultiTimer( int nT ) : timers()
195 {
196  timers = std::vector< TPZTimer >( nT );
197 }
198 
199 // Destructor.
201 {
202  // Nothing to do here!
203 }
204 
205 // Number of active timers.
206 inline int TPZMultiTimer::nTimers() const
207 {
208  return timers.size();
209 }
210 
211 // Returns a specific timer.
213 {
214  return timers[ i ];
215 }
216 
217 // Returns a specific timer.
218 inline const TPZTimer& TPZMultiTimer::getTimer( int i ) const
219 {
220  return timers[ i ];
221 }
222 
223 // Gets the process name (for reporting purposes).
224 inline std::string& TPZMultiTimer::processName( int i )
225 {
226  return timers[ i ].processName();
227 }
228 
229 // Gets the process name (for reporting purposes).
230 inline const std::string& TPZMultiTimer::processName( int i ) const
231 {
232  return timers[ i ].processName();
233 }
234 
235 // Turns the timer on.
236 inline void TPZMultiTimer::start( int i )
237 {
238  timers[ i ].start();
239 }
240 
241 // Turns the timer on.
242 inline void TPZMultiTimer::start()
243 {
244  for( unsigned int ii = 0; ii < timers.size(); ii++ )
245  {
246  timers[ ii ].start();
247  }
248 }
249 
250 // Turns the timer off, and computes the elapsed time.
251 inline void TPZMultiTimer::stop( int i )
252 {
253  timers[ i ].stop();
254 }
255 
256 // Turns the timer off, and computes the elapsed time.
257 inline void TPZMultiTimer::stop()
258 {
259  for( unsigned int ii = 0; ii < timers.size(); ii++ )
260  {
261  timers[ ii ].stop();
262  }
263 }
264 
265 // Zeroes the timer.
266 inline void TPZMultiTimer::reset( int i )
267 {
268  timers[ i ].reset();
269 }
270 
271 // Zeroes the timer.
272 inline void TPZMultiTimer::reset()
273 {
274  for( unsigned int ii = 0; ii < timers.size(); ii++ )
275  {
276  timers[ ii ].reset();
277  }
278 }
279 
280 // Returns the elapsed time in seconds.
281 inline double TPZMultiTimer::seconds( int i ) const
282 {
283  return timers[ i ].seconds();
284 }
285 
288 #endif // TPZTIMER_H
The timer class. Utility.
Definition: TPZTimer.h:46
~TPZTimer()
Default Destructor.
Definition: TPZTimer.h:165
std::vector< TPZTimer > timers
Vector of timers.
Definition: TPZTimer.h:153
std::string & processName(int i)
Gets the process name (for reporting purposes).
Definition: TPZTimer.h:224
std::string ProcessName
Name of the process being timed.
Definition: TPZTimer.h:91
void start()
Turns the timer on.
Definition: TPZTimer.h:242
int waitstatus
Waiting status.
Definition: TPZTimer.h:25
PZResourceUsage resources
Information on the resources used.
Definition: TPZTimer.h:85
TPZMultiTimer(int nT)
Default constructor.
Definition: TPZTimer.h:194
void reset()
Zeroes the timer.
Definition: TPZTimer.h:272
void stop()
Turns the timer off, and computes the elapsed time.
Definition: TPZTimer.h:257
std::string & processName()
Gets the process name (for reporting purposes).
Definition: TPZTimer.h:168
TPZTimer()
Definition: TPZTimer.h:159
void reset()
Zeroes the timer.
Definition: TPZTimer.h:180
int nTimers() const
Number of active timers.
Definition: TPZTimer.h:206
clock_t start
Wallclock time of process (start)
Definition: TPZTimer.h:28
double seconds(int i) const
Returns the elapsed time in seconds.
Definition: TPZTimer.h:281
double AccumSec
Total accumulated time in seconds.
Definition: TPZTimer.h:88
Controls several timers at once. Utility.
Definition: TPZTimer.h:100
clock_t elapsed
Wallclock time of process (elapsed)
Definition: TPZTimer.h:30
Information on the resources used by a child process. Utility.
Definition: TPZTimer.h:22
std::ostream & operator<<(std::ostream &out, const TPZCounter &count)
Re-implements << operator to show the counter (count) data.
Definition: pzreal.cpp:40
double seconds() const
Returns the elapsed time in seconds.
Definition: TPZTimer.h:186
TPZTimer & getTimer(int i)
Returns a specific timer.
Definition: TPZTimer.h:212
~TPZMultiTimer()
Destructor.
Definition: TPZTimer.h:200