Fallback on old boost timers

release/4.3a0
Richard Roberts 2012-06-05 21:30:42 +00:00
parent 5fc823c3af
commit c2fe87fdc4
2 changed files with 30 additions and 1 deletions

View File

@ -30,7 +30,9 @@
boost::shared_ptr<TimingOutline> timingRoot(new TimingOutline("Total"));
boost::weak_ptr<TimingOutline> timingCurrent(timingRoot);
//Timing timing;
#ifdef ENABLE_OLD_TIMING
Timing timing;
#endif
std::string timingPrefix;
/* ************************************************************************* */
@ -150,15 +152,27 @@ const boost::shared_ptr<TimingOutline>& TimingOutline::child(size_t child, const
/* ************************************************************************* */
void TimingOutline::tic() {
#ifdef GTSAM_USING_NEW_BOOST_TIMERS
assert(timer_.is_stopped());
timer_.start();
#else
assert(!timerActive_);
timer_.restart();
*timerActive_ = true;
#endif
}
/* ************************************************************************* */
void TimingOutline::toc() {
#ifdef GTSAM_USING_NEW_BOOST_TIMERS
assert(!timer_.is_stopped());
timer_.stop();
add((timer_.elapsed().user + timer_.elapsed().system) / 1000);
#else
assert(timerActive_);
double elapsed = timer_.elapsed();
add(size_t(elapsed * 1000000.0));
#endif
}
/* ************************************************************************* */

View File

@ -22,7 +22,17 @@
#include <vector>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <gtsam/base/types.h>
#if BOOST_VERSION >= 104800
#define GTSAM_USING_NEW_BOOST_TIMERS
#endif
#ifdef GTSAM_USING_NEW_BOOST_TIMERS
#include <boost/timer/timer.hpp>
#else
#include <boost/timer.hpp>
#endif
class TimingOutline;
extern boost::shared_ptr<TimingOutline> timingRoot;
@ -40,7 +50,12 @@ protected:
boost::weak_ptr<TimingOutline> parent_;
std::vector<boost::shared_ptr<TimingOutline> > children_;
#ifdef GTSAM_USING_NEW_BOOST_TIMERS
boost::timer::cpu_timer timer_;
#else
boost::timer timer_;
gtsam::ValueWithDefault<bool,false> timerActive_;
#endif
void add(size_t usecs);