hpp-centroidal-dynamics  5.0.0
Utility classes for testing (robust) equilibrium of a system in contact with the environment, and other centroidal dynamics methods.
stop-watch.hh
Go to the documentation of this file.
1 /*
2 Copyright (c) 2010-2013 Tommaso Urli
3 
4 Tommaso Urli tommaso.urli@uniud.it University of Udine
5 
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
13 
14 The above copyright notice and this permission notice shall be
15 included in all copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 
25 */
26 
27 #ifndef HPP_CENTROIDAL_DYNAMICS_STOP_WATCH_HH
28 #define HPP_CENTROIDAL_DYNAMICS_STOP_WATCH_HH
29 
31 
32 #ifndef WIN32
33 /* The classes below are exported */
34 #pragma GCC visibility push(default)
35 #endif
36 
37 // Generic stopwatch exception class
39  public:
40  StopwatchException(std::string error) : error(error) {}
41  std::string error;
42 };
43 
45  NONE = 0, // Clock is not initialized
46  CPU_TIME = 1, // Clock calculates time ranges using ctime and CLOCKS_PER_SEC
47  REAL_TIME = 2 // Clock calculates time by asking the operating system how
48  // much real time passed
49 };
50 
142 class Stopwatch {
143  public:
145  Stopwatch(StopwatchMode _mode = NONE);
146 
148  ~Stopwatch();
149 
151  bool performance_exists(std::string perf_name);
152 
154  void set_mode(StopwatchMode mode);
155 
157  void start(std::string perf_name);
158 
160  void stop(std::string perf_name);
161 
163  void pause(std::string perf_name);
164 
166  void reset(std::string perf_name);
167 
169  void reset_all();
170 
172  void report(std::string perf_name, int precision = 2,
173  std::ostream& output = std::cout);
174 
176  void report_all(int precision = 2, std::ostream& output = std::cout);
177 
179  long double get_total_time(std::string perf_name);
180 
182  long double get_average_time(std::string perf_name);
183 
185  long double get_min_time(std::string perf_name);
186 
188  long double get_max_time(std::string perf_name);
189 
191  long double get_last_time(std::string perf_name);
192 
195  long double get_time_so_far(std::string perf_name);
196 
199  void turn_off();
200 
202  void turn_on();
203 
205  long double take_time();
206 
207  protected:
211  : clock_start(0),
212  total_time(0),
213  min_time(0),
214  max_time(0),
215  last_time(0),
216  paused(false),
217  stops(0) {}
218 
220  long double clock_start;
221 
223  long double total_time;
224 
226  long double min_time;
227 
229  long double max_time;
230 
232  long double last_time;
233 
235  bool paused;
236 
238  int stops;
239  };
240 
242  bool active;
243 
246 
249  std::map<std::string, PerformanceData>* records_of;
250 };
251 
253 
254 #ifndef WIN32
255 #pragma GCC visibility pop
256 #endif
257 
258 #endif
Definition: stop-watch.hh:209
std::string error
Definition: stop-watch.hh:41
PerformanceData()
Definition: stop-watch.hh:210
long double last_time
Definition: stop-watch.hh:232
long double min_time
Definition: stop-watch.hh:226
Definition: stop-watch.hh:38
StopwatchMode
Definition: stop-watch.hh:44
A class representing a stopwatch.
Definition: stop-watch.hh:142
StopwatchMode mode
Definition: stop-watch.hh:245
bool paused
Definition: stop-watch.hh:235
long double clock_start
Definition: stop-watch.hh:220
Definition: stop-watch.hh:46
std::map< std::string, PerformanceData > * records_of
Definition: stop-watch.hh:249
Stopwatch & getProfiler()
Definition: stop-watch.cpp:45
Definition: stop-watch.hh:47
long double total_time
Definition: stop-watch.hh:223
int stops
Definition: stop-watch.hh:238
Definition: stop-watch.hh:45
bool active
Definition: stop-watch.hh:242
StopwatchException(std::string error)
Definition: stop-watch.hh:40
long double max_time
Definition: stop-watch.hh:229