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 __sot_core_stopwatch_H__
28 #define __sot_core_stopwatch_H__
29 
30 #include <ctime>
31 #include <iostream>
32 #include <map>
33 #include <sstream>
34 
35 #ifndef WIN32
36 /* The classes below are exported */
37 #pragma GCC visibility push(default)
38 #endif
39 
40 // Generic stopwatch exception class
42  public:
43  StopwatchException(std::string error) : error(error) {}
44  std::string error;
45 };
46 
48  NONE = 0, // Clock is not initialized
49  CPU_TIME = 1, // Clock calculates time ranges using ctime and CLOCKS_PER_SEC
50  REAL_TIME = 2 // Clock calculates time by asking the operating system how
51  // much real time passed
52 };
53 
54 #define STOP_WATCH_MAX_NAME_LENGTH 80
55 
147 class Stopwatch {
148  public:
150  Stopwatch(StopwatchMode _mode = NONE);
151 
153  ~Stopwatch();
154 
156  bool performance_exists(std::string perf_name);
157 
159  void set_mode(StopwatchMode mode);
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:
216  : clock_start(0),
217  total_time(0),
218  min_time(0),
219  max_time(0),
220  last_time(0),
221  paused(false),
222  stops(0) {}
223 
225  long double clock_start;
226 
228  long double total_time;
229 
231  long double min_time;
232 
234  long double max_time;
235 
237  long double last_time;
238 
240  bool paused;
241 
243  int stops;
244  };
245 
247  bool active;
248 
251 
254  std::map<std::string, PerformanceData> *records_of;
255 };
256 
258 
259 #ifndef WIN32
260 #pragma GCC visibility pop
261 #endif
262 
263 #endif
std::string error
Definition: stop-watch.hh:44
StopwatchMode
Definition: stop-watch.hh:47
A class representing a stopwatch.
Definition: stop-watch.hh:147
StopwatchMode mode
Definition: stop-watch.hh:250
std::map< std::string, PerformanceData > * records_of
Definition: stop-watch.hh:254
Stopwatch & getProfiler()
Definition: stop-watch.cpp:46
bool active
Definition: stop-watch.hh:247
StopwatchException(std::string error)
Definition: stop-watch.hh:43


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Wed Jun 21 2023 02:51:26