timeutil.h
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
16 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18 // PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
21 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 
27 #ifndef G2O_TIMEUTIL_H
28 #define G2O_TIMEUTIL_H
29 
30 #ifdef _WINDOWS
31 #include <time.h>
32 #else
33 #include <sys/time.h>
34 #endif
35 
36 #include <string>
37 
38 
40 // @{
41 
46 #ifndef DO_EVERY_TS
49 #define DO_EVERY_TS(secs, currentTime, code) \
50 if (1) {\
51  static double s_lastDone_ = (currentTime); \
52  double s_now_ = (currentTime); \
53  if (s_lastDone_ > s_now_) \
54  s_lastDone_ = s_now_; \
55  if (s_now_ - s_lastDone_ > (secs)) { \
56  code; \
57  s_lastDone_ = s_now_; \
58  }\
59 } else \
60  (void)0
61 #endif
62 
64 #ifndef DO_EVERY
65 #define DO_EVERY(secs, code) DO_EVERY_TS(secs, g2o::get_time(), code)
66 #endif
67 
68 #ifndef MEASURE_TIME
69 #define MEASURE_TIME(text, code) \
70  if(1) { \
71  double _start_time_ = g2o::get_time(); \
72  code; \
73  fprintf(stderr, "%s took %f sec\n", text, g2o::get_time() - _start_time_); \
74  } else \
75  (void) 0
76 #endif
77 
78 namespace g2o {
79 
80 #ifdef _WINDOWS
81 typedef struct timeval {
82  long tv_sec;
83  long tv_usec;
84 } timeval;
85  int gettimeofday(struct timeval *tv, struct timezone *tz);
86 #endif
87 
91 inline double get_time()
92 {
93  struct timeval ts;
94  gettimeofday(&ts,0);
95  return ts.tv_sec + ts.tv_usec*1e-6;
96 }
97 
106  double get_monotonic_time();
107 
114 class ScopeTime {
115  public:
116  ScopeTime(const char* title);
117  ~ScopeTime();
118  private:
119  std::string _title;
120  double _startTime;
121 };
122 
123 } // end namespace
124 
125 #ifndef MEASURE_FUNCTION_TIME
126 #define MEASURE_FUNCTION_TIME \
127  g2o::ScopeTime scopeTime(__PRETTY_FUNCTION__)
128 #endif
129 
130 
131 // @}
132 #endif
double get_monotonic_time()
Definition: timeutil.cpp:113
double _startTime
Definition: timeutil.h:120
Class to measure the time spent in a scope.
Definition: timeutil.h:114
std::string _title
Definition: timeutil.h:119
double get_time()
Definition: timeutil.h:91


orb_slam2_ros
Author(s):
autogenerated on Wed Apr 21 2021 02:53:05