tsid 1.9.0
Efficient Task Space Inverse Dynamics for Multi-body Systems based on Pinocchio
Loading...
Searching...
No Matches
stop-watch.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2010-2013 Tommaso Urli
3
4Tommaso Urli tommaso.urli@uniud.it University of Udine
5
6Permission is hereby granted, free of charge, to any person obtaining
7a copy of this software and associated documentation files (the
8"Software"), to deal in the Software without restriction, including
9without limitation the rights to use, copy, modify, merge, publish,
10distribute, sublicense, and/or sell copies of the Software, and to
11permit persons to whom the Software is furnished to do so, subject to
12the following conditions:
13
14The above copyright notice and this permission notice shall be
15included in all copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25*/
26
27#ifndef __invdyn_stopwatch_H__
28#define __invdyn_stopwatch_H__
29
31
32#ifndef WIN32
33/* The classes below are exported */
34#pragma GCC visibility push(default)
35#endif
36
37// #define START_PROFILER(name)
38// #define STOP_PROFILER(name)
39#define START_PROFILER(name) getProfiler().start(name)
40#define STOP_PROFILER(name) getProfiler().stop(name)
41
42#define STOP_WATCH_MAX_NAME_LENGTH 60
43#define STOP_WATCH_TIME_WIDTH 10
44
45// Generic stopwatch exception class
47 public:
49 std::string error;
50};
51
53 NONE = 0, // Clock is not initialized
54 CPU_TIME = 1, // Clock calculates time ranges using ctime and CLOCKS_PER_SEC
55 REAL_TIME = 2 // Clock calculates time by asking the operating system how
56 // much real time passed
57};
58
150class Stopwatch {
151 public:
154
156 ~Stopwatch();
157
159 bool performance_exists(std::string perf_name);
160
163
165 void start(std::string perf_name);
166
168 void stop(std::string perf_name);
169
171 void pause(std::string perf_name);
172
174 void reset(std::string perf_name);
175
177 void reset_all();
178
180 void report(std::string perf_name, int precision = 2,
181 std::ostream& output = std::cout);
182
184 void report_all(int precision = 2, std::ostream& output = std::cout);
185
187 long double get_total_time(std::string perf_name);
188
190 long double get_average_time(std::string perf_name);
191
193 long double get_min_time(std::string perf_name);
194
196 long double get_max_time(std::string perf_name);
197
199 long double get_last_time(std::string perf_name);
200
203 long double get_time_so_far(std::string perf_name);
204
207 void turn_off();
208
210 void turn_on();
211
213 long double take_time();
214
215 protected:
219 : clock_start(0),
220 total_time(0),
221 min_time(0),
222 max_time(0),
223 last_time(0),
224 paused(false),
225 stops(0) {}
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
261
262#ifndef WIN32
263#pragma GCC visibility pop
264#endif
265
266#endif
A class representing a stopwatch.
Definition stop-watch.hpp:150
long double get_time_so_far(std::string perf_name)
Definition stop-watch.cpp:263
long double take_time()
Definition stop-watch.cpp:60
long double get_min_time(std::string perf_name)
Definition stop-watch.cpp:296
long double get_max_time(std::string perf_name)
Definition stop-watch.cpp:306
void reset(std::string perf_name)
Definition stop-watch.cpp:206
long double get_total_time(std::string perf_name)
Definition stop-watch.cpp:276
void set_mode(StopwatchMode mode)
Definition stop-watch.cpp:54
bool performance_exists(std::string perf_name)
Definition stop-watch.cpp:56
~Stopwatch()
Definition stop-watch.cpp:52
void report_all(int precision=2, std::ostream &output=std::cout)
Definition stop-watch.cpp:182
void turn_on()
Definition stop-watch.cpp:224
std::map< std::string, PerformanceData > * records_of
Definition stop-watch.hpp:257
void start(std::string perf_name)
Definition stop-watch.cpp:102
long double get_average_time(std::string perf_name)
Definition stop-watch.cpp:286
bool active
Definition stop-watch.hpp:250
void pause(std::string perf_name)
Definition stop-watch.cpp:151
void reset_all()
Definition stop-watch.cpp:172
Stopwatch(StopwatchMode _mode=NONE)
Definition stop-watch.cpp:48
void stop(std::string perf_name)
Definition stop-watch.cpp:120
void turn_off()
Definition stop-watch.cpp:229
long double get_last_time(std::string perf_name)
Definition stop-watch.cpp:316
StopwatchMode mode
Definition stop-watch.hpp:253
void report(std::string perf_name, int precision=2, std::ostream &output=std::cout)
Definition stop-watch.cpp:234
StopwatchMode
Definition stop-watch.hpp:52
@ CPU_TIME
Definition stop-watch.hpp:54
@ REAL_TIME
Definition stop-watch.hpp:55
@ NONE
Definition stop-watch.hpp:53
Stopwatch & getProfiler()
Definition stop-watch.cpp:43
StopwatchException(std::string error)
Definition stop-watch.hpp:48
std::string error
Definition stop-watch.hpp:49
long double min_time
Definition stop-watch.hpp:234
long double total_time
Definition stop-watch.hpp:231
long double max_time
Definition stop-watch.hpp:237
int stops
Definition stop-watch.hpp:246
bool paused
Definition stop-watch.hpp:243
long double last_time
Definition stop-watch.hpp:240
long double clock_start
Definition stop-watch.hpp:228
PerformanceData()
Definition stop-watch.hpp:218