g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
stuff
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
#include <chrono>
31
#include <string>
32
33
#include "
g2o/stuff/misc.h
"
34
#include "
g2o_stuff_api.h
"
35
37
// @{
38
42
46
#ifndef DO_EVERY_TS
47
#define DO_EVERY_TS(secs, currentTime, code) \
48
if (1) { \
49
static double s_lastDone_ = (currentTime); \
50
double s_now_ = (currentTime); \
51
if (s_lastDone_ > s_now_) s_lastDone_ = s_now_; \
52
if (s_now_ - s_lastDone_ > (secs)) { \
53
code; \
54
s_lastDone_ = s_now_; \
55
} \
56
} else \
57
(void)0
58
#endif
59
61
#ifndef DO_EVERY
62
#define DO_EVERY(secs, code) DO_EVERY_TS(secs, g2o::get_time(), code)
63
#endif
64
65
#ifndef MEASURE_TIME
66
#define MEASURE_TIME(text, code) \
67
if (1) { \
68
double _start_time_ = g2o::get_time(); \
69
code; \
70
G2O_DEBUG("{} took {} sec", text, g2o::get_time() - _start_time_); \
71
} else \
72
(void)0
73
#endif
74
75
namespace
g2o
{
76
77
using
seconds
= std::chrono::duration<double>;
78
82
inline
double
get_time
() {
83
return
seconds
{std::chrono::system_clock::now().time_since_epoch()}.count();
84
}
85
91
G2O_STUFF_API
double
get_monotonic_time
();
92
99
class
G2O_STUFF_API
ScopeTime
{
100
public
:
101
ScopeTime
(
const
char
* title);
102
~ScopeTime
();
103
104
private
:
105
std::string
_title
;
106
double
_startTime
;
107
};
108
109
}
// namespace g2o
110
111
#ifndef MEASURE_FUNCTION_TIME
112
#define MEASURE_FUNCTION_TIME g2o::ScopeTime scopeTime(__PRETTY_FUNCTION__)
113
#endif
114
115
// @}
116
#endif
g2o::ScopeTime::_title
std::string _title
Definition
timeutil.h:105
g2o::ScopeTime::_startTime
double _startTime
Definition
timeutil.h:106
g2o::ScopeTime::ScopeTime
ScopeTime(const char *title)
Definition
timeutil.cpp:35
g2o_stuff_api.h
G2O_STUFF_API
#define G2O_STUFF_API
Definition
g2o_stuff_api.h:56
misc.h
some general case utility functions
g2o
Definition
dl_wrapper.cpp:55
g2o::get_time
double get_time()
Definition
timeutil.h:82
g2o::get_monotonic_time
double get_monotonic_time()
Definition
timeutil.cpp:43
g2o::seconds
std::chrono::duration< double > seconds
Definition
timeutil.h:77
Generated on
for g2o by
1.17.0