hpp-rbprm  4.10.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 
28 #ifndef WBR_STOPWATCH_H
29 #define WBR_STOPWATCH_H
30 
32 
33 #ifndef WIN32
34  /* The classes below are exported */
35  #pragma GCC visibility push(default)
36 #endif
37 
38 // Generic stopwatch exception class
40 {
41 public:
42  StopwatchException(std::string error) : error(error) { }
43  std::string error;
44 };
45 
46 
48 {
49  NONE = 0, // Clock is not initialized
50  CPU_TIME = 1, // Clock calculates time ranges using ctime and CLOCKS_PER_SEC
51  REAL_TIME = 2 // Clock calculates time by asking the operating system how
52  // much real time passed
53 };
54 
146 class Stopwatch {
147 public:
148 
151 
153  ~Stopwatch();
154 
156  bool performance_exists(std::string perf_name);
157 
160 
162  void start(std::string perf_name);
163 
165  void stop(std::string perf_name);
166 
168  void pause(std::string perf_name);
169 
171  void reset(std::string perf_name);
172 
174  void reset_all();
175 
177  void report(std::string perf_name, int precision=2,
178  std::ostream& output = std::cout);
179 
181  void report_all(int precision=2, std::ostream& output = std::cout);
182 
184  long double get_total_time(std::string perf_name);
185 
187  long double get_average_time(std::string perf_name);
188 
190  long double get_min_time(std::string perf_name);
191 
193  long double get_max_time(std::string perf_name);
194 
196  long double get_last_time(std::string perf_name);
197 
200  long double get_time_so_far(std::string perf_name);
201 
204  void turn_off();
205 
207  void turn_on();
208 
210  long double take_time();
211 
212 protected:
213 
216 
218  clock_start(0),
219  total_time(0),
220  min_time(0),
221  max_time(0),
222  last_time(0),
223  paused(false),
224  stops(0) {
225  }
226 
228  long double clock_start;
229 
231  long double total_time;
232 
234  long double min_time;
235 
237  long double max_time;
238 
240  long double last_time;
241 
243  bool paused;
244 
246  int stops;
247  };
248 
250  bool active;
251 
254 
257  std::map<std::string, PerformanceData >* records_of;
258 
259 };
260 
262 
263 #ifndef WIN32
264  #pragma GCC visibility pop
265 #endif
266 
267 #endif
CPU_TIME
@ CPU_TIME
Definition: stop-watch.hh:50
Stopwatch::stop
void stop(std::string perf_name)
Stopwatch::get_average_time
long double get_average_time(std::string perf_name)
StopwatchException
Definition: stop-watch.hh:39
Stopwatch::get_max_time
long double get_max_time(std::string perf_name)
Stopwatch::get_last_time
long double get_last_time(std::string perf_name)
NONE
@ NONE
Definition: stop-watch.hh:49
Stopwatch::PerformanceData::max_time
long double max_time
Definition: stop-watch.hh:237
Stopwatch::~Stopwatch
~Stopwatch()
Stopwatch::get_min_time
long double get_min_time(std::string perf_name)
Stopwatch::PerformanceData
Definition: stop-watch.hh:215
Stopwatch::active
bool active
Definition: stop-watch.hh:250
Stopwatch::performance_exists
bool performance_exists(std::string perf_name)
Stopwatch::PerformanceData::paused
bool paused
Definition: stop-watch.hh:243
StopwatchMode
StopwatchMode
Definition: stop-watch.hh:47
Stopwatch::PerformanceData::PerformanceData
PerformanceData()
Definition: stop-watch.hh:217
Stopwatch
A class representing a stopwatch.
Definition: stop-watch.hh:146
Stopwatch::take_time
long double take_time()
Stopwatch::get_time_so_far
long double get_time_so_far(std::string perf_name)
Stopwatch::Stopwatch
Stopwatch(StopwatchMode _mode=NONE)
Stopwatch::set_mode
void set_mode(StopwatchMode mode)
Stopwatch::PerformanceData::stops
int stops
Definition: stop-watch.hh:246
REAL_TIME
@ REAL_TIME
Definition: stop-watch.hh:51
Stopwatch::PerformanceData::last_time
long double last_time
Definition: stop-watch.hh:240
Stopwatch::pause
void pause(std::string perf_name)
Stopwatch::turn_off
void turn_off()
Stopwatch::report
void report(std::string perf_name, int precision=2, std::ostream &output=std::cout)
Stopwatch::mode
StopwatchMode mode
Definition: stop-watch.hh:253
Stopwatch::records_of
std::map< std::string, PerformanceData > * records_of
Definition: stop-watch.hh:257
Stopwatch::turn_on
void turn_on()
getProfiler
Stopwatch & getProfiler()
Stopwatch::PerformanceData::clock_start
long double clock_start
Definition: stop-watch.hh:228
Stopwatch::get_total_time
long double get_total_time(std::string perf_name)
Stdafx.hh
StopwatchException::error
std::string error
Definition: stop-watch.hh:43
Stopwatch::reset_all
void reset_all()
StopwatchException::StopwatchException
StopwatchException(std::string error)
Definition: stop-watch.hh:42
Stopwatch::PerformanceData::min_time
long double min_time
Definition: stop-watch.hh:234
Stopwatch::start
void start(std::string perf_name)
Stopwatch::reset
void reset(std::string perf_name)
Stopwatch::report_all
void report_all(int precision=2, std::ostream &output=std::cout)
Stopwatch::PerformanceData::total_time
long double total_time
Definition: stop-watch.hh:231