21#include <gtsam/dllexport.h>
22#include <gtsam/config.h>
24#include <boost/smart_ptr/shared_ptr.hpp>
25#include <boost/smart_ptr/weak_ptr.hpp>
26#include <boost/version.hpp>
110#if BOOST_VERSION >= 104800
111# ifndef GTSAM_DISABLE_NEW_TIMERS
112# define GTSAM_USING_NEW_BOOST_TIMERS
116#ifdef GTSAM_USING_NEW_BOOST_TIMERS
117# include <boost/timer/timer.hpp>
119# include <boost/timer.hpp>
124# include <tbb/tick_count.h>
134 GTSAM_EXPORT
size_t getTicTocID(
const char *description);
137 GTSAM_EXPORT
void tic(
size_t id,
const char *label);
140 GTSAM_EXPORT
void toc(
size_t id,
const char *label);
156 size_t lastChildOrder_;
164#ifdef GTSAM_USING_NEW_BOOST_TIMERS
165 boost::timer::cpu_timer timer_;
171 tbb::tick_count tbbTimer_;
173 void add(
size_t usecs,
size_t usecsWall);
177 GTSAM_EXPORT
TimingOutline(
const std::string& label,
size_t myId);
178 GTSAM_EXPORT
size_t time()
const;
179 double secs()
const {
return double(
time()) / 1000000.0;}
180 double self()
const {
return double(t_) / 1000000.0;}
181 double wall()
const {
return double(tWall_) / 1000000.0;}
182 double min()
const {
return double(tMin_) / 1000000.0;}
183 double max()
const {
return double(tMax_) / 1000000.0;}
184 double mean()
const {
return self() / double(n_); }
185 GTSAM_EXPORT
void print(
const std::string& outline =
"")
const;
186 GTSAM_EXPORT
void print2(
const std::string& outline =
"",
const double parentTotal = -1.0)
const;
187 GTSAM_EXPORT
const boost::shared_ptr<TimingOutline>&
188 child(
size_t child,
const std::string& label,
const boost::weak_ptr<TimingOutline>& thisPtr);
189 GTSAM_EXPORT
void tic();
190 GTSAM_EXPORT
void toc();
191 GTSAM_EXPORT
void finishedIteration();
193 GTSAM_EXPORT
friend void toc(
size_t id,
const char *label);
207 : id_(
id), label_(label), isSet_(
true) {
219 GTSAM_EXTERN_EXPORT boost::shared_ptr<TimingOutline> gTimingRoot;
220 GTSAM_EXTERN_EXPORT boost::weak_ptr<TimingOutline> gCurrentTimer;
230#define gttic_(label) \
231 static const size_t label##_id_tic = ::gtsam::internal::getTicTocID(#label); \
232 ::gtsam::internal::AutoTicToc label##_obj(label##_id_tic, #label)
235#define gttoc_(label) \
239#define longtic_(label) \
240 static const size_t label##_id_tic = ::gtsam::internal::getTicTocID(#label); \
241 ::gtsam::internal::ticInternal(label##_id_tic, #label)
244#define longtoc_(label) \
245 static const size_t label##_id_toc = ::gtsam::internal::getTicTocID(#label); \
246 ::gtsam::internal::tocInternal(label##_id_toc, #label)
249inline void tictoc_finishedIteration_() {
250 ::gtsam::internal::gTimingRoot->finishedIteration(); }
253inline void tictoc_print_() {
254 ::gtsam::internal::gTimingRoot->print(); }
257inline void tictoc_print2_() {
258 ::gtsam::internal::gTimingRoot->print2(); }
261#define tictoc_getNode(variable, label) \
262 static const size_t label##_id_getnode = ::gtsam::internal::getTicTocID(#label); \
263 const boost::shared_ptr<const ::gtsam::internal::TimingOutline> variable = \
264 ::gtsam::internal::gCurrentTimer.lock()->child(label##_id_getnode, #label, ::gtsam::internal::gCurrentTimer);
267inline void tictoc_reset_() {
268 ::gtsam::internal::gTimingRoot.reset(new ::gtsam::internal::TimingOutline(
"Total", ::gtsam::internal::getTicTocID(
"Total")));
269 ::gtsam::internal::gCurrentTimer = ::gtsam::internal::gTimingRoot; }
272#define gttic(label) gttic_(label)
273#define gttoc(label) gttoc_(label)
274#define longtic(label) longtic_(label)
275#define longtoc(label) longtoc_(label)
276#define tictoc_finishedIteration tictoc_finishedIteration_
277#define tictoc_print tictoc_print_
278#define tictoc_reset tictoc_reset_
280#define gttic(label) ((void)0)
281#define gttoc(label) ((void)0)
282#define longtic(label) ((void)0)
283#define longtoc(label) ((void)0)
284#define tictoc_finishedIteration() ((void)0)
285#define tictoc_print() ((void)0)
286#define tictoc_reset() ((void)0)
Typedefs for easier changing of types.
A thin wrapper around std::map that uses boost's fast_pool_allocator.
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Timing Entry, arranged in a tree.
Definition: timing.h:145
double t2_
cache the \sum t_i^2
Definition: timing.h:150
ChildMap children_
subtrees
Definition: timing.h:162
double max() const
max time, in seconds
Definition: timing.h:183
double wall() const
wall time, in seconds
Definition: timing.h:181
double secs() const
time taken, in seconds, including children
Definition: timing.h:179
double self() const
self time only, in seconds
Definition: timing.h:180
GTSAM_EXPORT TimingOutline(const std::string &label, size_t myId)
Constructor.
Definition: timing.cpp:56
boost::weak_ptr< TimingOutline > parent_
parent pointer
Definition: timing.h:160
double min() const
min time, in seconds
Definition: timing.h:182
double mean() const
mean self time, in seconds
Definition: timing.h:184
GTSAM_EXPORT size_t time() const
time taken, including children
Definition: timing.cpp:65
Small class that calls internal::tic at construction, and internol::toc when destroyed.
Definition: timing.h:199