hpp-centroidal-dynamics: include/hpp/centroidal-dynamics/stop-watch.hh Source File

hpp-centroidal-dynamics 9.0.2 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
30 #include "hpp/centroidal-dynamics/Stdafx.hh"
31
32 #ifndef WIN32
33 /* The classes below are exported */
34 #pragma GCC visibility push(default)
35 #endif
36
37 // Generic stopwatch exception class
38 struct StopwatchException {
39 public:
40 StopwatchException(std::string error) : error(error) {}
41 std::string error;
42 };
43
44 enum StopwatchMode {
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:
209 struct PerformanceData {
210 PerformanceData()
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
245 StopwatchMode mode;
246
249 std::map<std::string, PerformanceData>* records_of;
250 };
251
252 Stopwatch& getProfiler();
253
254 #ifndef WIN32
255 #pragma GCC visibility pop
256 #endif
257
258 #endif
Stdafx.hh
Stopwatch
A class representing a stopwatch.
Definition: stop-watch.hh:142
Stopwatch::get_time_so_far
long double get_time_so_far(std::string perf_name)
Definition: stop-watch.cpp:249
Stopwatch::take_time
long double take_time()
Definition: stop-watch.cpp:62
Stopwatch::get_min_time
long double get_min_time(std::string perf_name)
Definition: stop-watch.cpp:282
Stopwatch::get_max_time
long double get_max_time(std::string perf_name)
Definition: stop-watch.cpp:292
Stopwatch::reset
void reset(std::string perf_name)
Definition: stop-watch.cpp:189
Stopwatch::get_total_time
long double get_total_time(std::string perf_name)
Definition: stop-watch.cpp:262
Stopwatch::set_mode
void set_mode(StopwatchMode mode)
Definition: stop-watch.cpp:56
Stopwatch::performance_exists
bool performance_exists(std::string perf_name)
Definition: stop-watch.cpp:58
Stopwatch::~Stopwatch
~Stopwatch()
Definition: stop-watch.cpp:54
Stopwatch::report_all
void report_all(int precision=2, std::ostream &output=std::cout)
Definition: stop-watch.cpp:178
Stopwatch::turn_on
void turn_on()
Definition: stop-watch.cpp:207
Stopwatch::records_of
std::map< std::string, PerformanceData > * records_of
Definition: stop-watch.hh:249
Stopwatch::start
void start(std::string perf_name)
Definition: stop-watch.cpp:104
Stopwatch::get_average_time
long double get_average_time(std::string perf_name)
Definition: stop-watch.cpp:272
Stopwatch::active
bool active
Definition: stop-watch.hh:242
Stopwatch::pause
void pause(std::string perf_name)
Definition: stop-watch.cpp:150
Stopwatch::reset_all
void reset_all()
Definition: stop-watch.cpp:168
Stopwatch::Stopwatch
Stopwatch(StopwatchMode _mode=NONE)
Definition: stop-watch.cpp:50
Stopwatch::stop
void stop(std::string perf_name)
Definition: stop-watch.cpp:122
Stopwatch::turn_off
void turn_off()
Definition: stop-watch.cpp:212
Stopwatch::get_last_time
long double get_last_time(std::string perf_name)
Definition: stop-watch.cpp:302
Stopwatch::mode
StopwatchMode mode
Definition: stop-watch.hh:245
Stopwatch::report
void report(std::string perf_name, int precision=2, std::ostream &output=std::cout)
Definition: stop-watch.cpp:217
getProfiler
Stopwatch & getProfiler()
Definition: stop-watch.cpp:45
StopwatchMode
StopwatchMode
Definition: stop-watch.hh:44
CPU_TIME
@ CPU_TIME
Definition: stop-watch.hh:46
REAL_TIME
@ REAL_TIME
Definition: stop-watch.hh:47
NONE
@ NONE
Definition: stop-watch.hh:45
StopwatchException
Definition: stop-watch.hh:38
StopwatchException::StopwatchException
StopwatchException(std::string error)
Definition: stop-watch.hh:40
StopwatchException::error
std::string error
Definition: stop-watch.hh:41
Stopwatch::PerformanceData
Definition: stop-watch.hh:209
Stopwatch::PerformanceData::min_time
long double min_time
Definition: stop-watch.hh:226
Stopwatch::PerformanceData::total_time
long double total_time
Definition: stop-watch.hh:223
Stopwatch::PerformanceData::max_time
long double max_time
Definition: stop-watch.hh:229
Stopwatch::PerformanceData::stops
int stops
Definition: stop-watch.hh:238
Stopwatch::PerformanceData::paused
bool paused
Definition: stop-watch.hh:235
Stopwatch::PerformanceData::last_time
long double last_time
Definition: stop-watch.hh:232
Stopwatch::PerformanceData::clock_start
long double clock_start
Definition: stop-watch.hh:220
Stopwatch::PerformanceData::PerformanceData
PerformanceData()
Definition: stop-watch.hh:210