21#include <gtsam/dllexport.h>
22#include <gtsam/config.h>
24#if GTSAM_USE_BOOST_FEATURES
25#include <boost/version.hpp>
113#if GTSAM_USE_BOOST_FEATURES
115#if BOOST_VERSION >= 104800
116# ifndef GTSAM_DISABLE_NEW_TIMERS
117# define GTSAM_USING_NEW_BOOST_TIMERS
121#ifdef GTSAM_USING_NEW_BOOST_TIMERS
122# include <boost/timer/timer.hpp>
124# include <boost/timer.hpp>
130# include <tbb/tick_count.h>
140 GTSAM_EXPORT
size_t getTicTocID(
const char *description);
143 GTSAM_EXPORT
void tic(
size_t id,
const char *label);
146 GTSAM_EXPORT
void toc(
size_t id,
const char *label);
162 size_t lastChildOrder_;
171#if GTSAM_USE_BOOST_FEATURES
172#ifdef GTSAM_USING_NEW_BOOST_TIMERS
173 boost::timer::cpu_timer timer_;
179 tbb::tick_count tbbTimer_;
182 std::chrono::time_point<std::chrono::steady_clock> wall_timer_start_;
183 std::clock_t cpu_timer_start_;
184 bool timer_active_ =
false;
186 void add(
size_t usecs,
size_t usecsWall);
190 GTSAM_EXPORT
TimingOutline(
const std::string& label,
size_t myId);
191 GTSAM_EXPORT
size_t time()
const;
192 double secs()
const {
return double(
time()) / 1000000.0;}
193#if GTSAM_USE_BOOST_FEATURES
194 double self()
const {
return double(t_) / 1000000.0;}
195 double wall()
const {
return double(tWall_) / 1000000.0;}
196 double min()
const {
return double(tMin_) / 1000000.0;}
197 double max()
const {
return double(tMax_) / 1000000.0;}
198 double mean()
const {
return self() / double(n_); }
201 double self()
const {
return double(t_) / 1000000.0;}
202 double wall()
const {
return double(tWall_) / 1000000.0;}
203 double min()
const {
return double(tMin_) / 1000000.0;}
204 double max()
const {
return double(tMax_) / 1000000.0;}
205 double mean()
const {
return n_ > 0 ?
self() / double(n_) : 0.0; }
207 GTSAM_EXPORT
void print(
const std::string& outline =
"")
const;
208 GTSAM_EXPORT
void print2(
const std::string& outline =
"",
const double parentTotal = -1.0)
const;
219 GTSAM_EXPORT
void printCsvHeader(
bool addLineBreak =
false)
const;
230 GTSAM_EXPORT
void printCsv(
bool addLineBreak =
false)
const;
232 GTSAM_EXPORT
const std::shared_ptr<TimingOutline>&
233 child(
size_t child,
const std::string& label,
const std::weak_ptr<TimingOutline>& thisPtr);
234 GTSAM_EXPORT
void tic();
235 GTSAM_EXPORT
void toc();
236 GTSAM_EXPORT
void finishedIteration();
238 GTSAM_EXPORT
friend void toc(
size_t id,
const char *label);
244 class GTSAM_EXPORT AutoTicToc {
251 AutoTicToc(
size_t id,
const char* label)
252 : id_(
id), label_(label), isSet_(
true) {
264 GTSAM_EXTERN_EXPORT std::shared_ptr<TimingOutline> gTimingRoot;
265 GTSAM_EXTERN_EXPORT std::weak_ptr<TimingOutline> gCurrentTimer;
275#define gttic_(label) \
276 static const size_t label##_id_tic = ::gtsam::internal::getTicTocID(#label); \
277 ::gtsam::internal::AutoTicToc label##_obj(label##_id_tic, #label)
280#define gttoc_(label) \
284#define longtic_(label) \
285 static const size_t label##_id_tic = ::gtsam::internal::getTicTocID(#label); \
286 ::gtsam::internal::ticInternal(label##_id_tic, #label)
289#define longtoc_(label) \
290 static const size_t label##_id_toc = ::gtsam::internal::getTicTocID(#label); \
291 ::gtsam::internal::tocInternal(label##_id_toc, #label)
294inline void tictoc_finishedIteration_() {
295 ::gtsam::internal::gTimingRoot->finishedIteration(); }
298inline void tictoc_print_() {
299 ::gtsam::internal::gTimingRoot->print(); }
302inline void tictoc_printCsv_(
bool displayHeader =
false) {
304 ::gtsam::internal::gTimingRoot->printCsvHeader(
true);
306 ::gtsam::internal::gTimingRoot->printCsv(
true);
310inline void tictoc_print2_() {
311 ::gtsam::internal::gTimingRoot->print2(); }
314#define tictoc_getNode(variable, label) \
315 static const size_t label##_id_getnode = ::gtsam::internal::getTicTocID(#label); \
316 const std::shared_ptr<const ::gtsam::internal::TimingOutline> variable = \
317 ::gtsam::internal::gCurrentTimer.lock()->child(label##_id_getnode, #label, ::gtsam::internal::gCurrentTimer);
320inline void tictoc_reset_() {
321 ::gtsam::internal::gTimingRoot.reset(new ::gtsam::internal::TimingOutline(
"Total", ::gtsam::internal::getTicTocID(
"Total")));
322 ::gtsam::internal::gCurrentTimer = ::gtsam::internal::gTimingRoot; }
325#define gttic(label) gttic_(label)
326#define gttoc(label) gttoc_(label)
327#define longtic(label) longtic_(label)
328#define longtoc(label) longtoc_(label)
329#define tictoc_finishedIteration tictoc_finishedIteration_
330#define tictoc_print tictoc_print_
331#define tictoc_reset tictoc_reset_
333#define gttic(label) ((void)0)
334#define gttoc(label) ((void)0)
335#define longtic(label) ((void)0)
336#define longtoc(label) ((void)0)
337#define tictoc_finishedIteration() ((void)0)
338#define tictoc_print() ((void)0)
339#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
void print(const Matrix &A, const string &s, ostream &stream)
print without optional string, must specify cout yourself
Definition Matrix.cpp:143
FastMap is a thin wrapper around std::map that uses the boost fast_pool_allocator instead of the defa...
Definition FastMap.h:40
double t2_
cache the
Definition timing.h:156
ChildMap children_
subtrees
Definition timing.h:168
std::weak_ptr< TimingOutline > parent_
parent pointer
Definition timing.h:166
double max() const
max time, in seconds
Definition timing.h:204
GTSAM_EXPORT void printCsv(bool addLineBreak=false) const
Print the times recursively from parent to child in CSV format.
Definition timing.cpp:135
double wall() const
wall time, in seconds
Definition timing.h:202
double secs() const
time taken, in seconds, including children
Definition timing.h:192
double self() const
self time only, in seconds
Definition timing.h:201
GTSAM_EXPORT TimingOutline(const std::string &label, size_t myId)
Constructor.
Definition timing.cpp:65
double min() const
min time, in seconds
Definition timing.h:203
double mean() const
mean self time, in seconds
Definition timing.h:205
GTSAM_EXPORT size_t time() const
time taken, including children
Definition timing.cpp:77
GTSAM_EXPORT void printCsvHeader(bool addLineBreak=false) const
Print the CSV header.
Definition timing.cpp:112
Helper struct that encapsulates a value with a default, this is just used as a member object so you d...
Definition types.h:58