hpp-rbprm  4.12.0
Implementation of RB-PRM planner using hpp.
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 WBR_STOPWATCH_H
28 #define WBR_STOPWATCH_H
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, std::ostream& output = std::cout);
173 
175  void report_all(int precision = 2, std::ostream& output = std::cout);
176 
178  long double get_total_time(std::string perf_name);
179 
181  long double get_average_time(std::string perf_name);
182 
184  long double get_min_time(std::string perf_name);
185 
187  long double get_max_time(std::string perf_name);
188 
190  long double get_last_time(std::string perf_name);
191 
194  long double get_time_so_far(std::string perf_name);
195 
198  void turn_off();
199 
201  void turn_on();
202 
204  long double take_time();
205 
206  protected:
210  : clock_start(0), total_time(0), min_time(0), max_time(0), last_time(0), paused(false), stops(0) {}
211 
213  long double clock_start;
214 
216  long double total_time;
217 
219  long double min_time;
220 
222  long double max_time;
223 
225  long double last_time;
226 
228  bool paused;
229 
231  int stops;
232  };
233 
235  bool active;
236 
239 
242  std::map<std::string, PerformanceData>* records_of;
243 };
244 
246 
247 #ifndef WIN32
248 #pragma GCC visibility pop
249 #endif
250 
251 #endif
Definition: stop-watch.hh:208
std::string error
Definition: stop-watch.hh:41
PerformanceData()
Definition: stop-watch.hh:209
long double last_time
Definition: stop-watch.hh:225
long double min_time
Definition: stop-watch.hh:219
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:238
bool paused
Definition: stop-watch.hh:228
long double clock_start
Definition: stop-watch.hh:213
Definition: stop-watch.hh:46
std::map< std::string, PerformanceData > * records_of
Definition: stop-watch.hh:242
Stopwatch & getProfiler()
Definition: stop-watch.hh:47
long double total_time
Definition: stop-watch.hh:216
int stops
Definition: stop-watch.hh:231
Definition: stop-watch.hh:45
bool active
Definition: stop-watch.hh:235
StopwatchException(std::string error)
Definition: stop-watch.hh:40
long double max_time
Definition: stop-watch.hh:222