Added wall time to timing functions

release/4.3a0
Richard Roberts 2013-08-01 21:57:03 +00:00
parent 424ef0728f
commit ff88c8fdc8
2 changed files with 10 additions and 8 deletions

View File

@ -41,8 +41,9 @@ GTSAM_EXPORT boost::weak_ptr<TimingOutline> timingCurrent(timingRoot);
/* ************************************************************************* */ /* ************************************************************************* */
/* ************************************************************************* */ /* ************************************************************************* */
void TimingOutline::add(size_t usecs) { void TimingOutline::add(size_t usecs, size_t usecsWall) {
t_ += usecs; t_ += usecs;
tWall_ += usecsWall;
tIt_ += usecs; tIt_ += usecs;
t2_ += (double(usecs)/1000000.0)*(double(usecs)/1000000.0); t2_ += (double(usecs)/1000000.0)*(double(usecs)/1000000.0);
++ n_; ++ n_;
@ -50,7 +51,7 @@ void TimingOutline::add(size_t usecs) {
/* ************************************************************************* */ /* ************************************************************************* */
TimingOutline::TimingOutline(const std::string& label, size_t myId) : TimingOutline::TimingOutline(const std::string& label, size_t myId) :
myId_(myId), t_(0), t2_(0.0), tIt_(0), tMax_(0), tMin_(0), n_(0), myOrder_(0), lastChildOrder_(0), label_(label) myId_(myId), t_(0), tWall_(0), t2_(0.0), tIt_(0), tMax_(0), tMin_(0), n_(0), myOrder_(0), lastChildOrder_(0), label_(label)
{ {
#ifdef GTSAM_USING_NEW_BOOST_TIMERS #ifdef GTSAM_USING_NEW_BOOST_TIMERS
timer_.stop(); timer_.stop();
@ -75,9 +76,9 @@ size_t TimingOutline::time() const {
void TimingOutline::print(const std::string& outline) const { void TimingOutline::print(const std::string& outline) const {
std::string formattedLabel = label_; std::string formattedLabel = label_;
boost::replace_all(formattedLabel, "_", " "); boost::replace_all(formattedLabel, "_", " ");
std::cout << outline << "-" << formattedLabel << ": " << double(t_)/1000000.0 << " (" << std::cout << outline << "-" << formattedLabel << ": " << double(t_)/1000000.0 << " CPU (" <<
n_ << " times, " << double(time())/1000000.0 << " children, min: " << double(tMin_)/1000000.0 << n_ << " times, " << double(tWall_)/1000000.0 << " wall, " << double(time())/1000000.0 << " children, min: "
" max: " << double(tMax_)/1000000.0 << ")\n"; << double(tMin_)/1000000.0 << " max: " << double(tMax_)/1000000.0 << ")\n";
// Order children // Order children
typedef FastMap<size_t, boost::shared_ptr<TimingOutline> > ChildOrder; typedef FastMap<size_t, boost::shared_ptr<TimingOutline> > ChildOrder;
ChildOrder childOrder; ChildOrder childOrder;
@ -163,11 +164,11 @@ void TimingOutline::tocInternal() {
#ifdef GTSAM_USING_NEW_BOOST_TIMERS #ifdef GTSAM_USING_NEW_BOOST_TIMERS
assert(!timer_.is_stopped()); assert(!timer_.is_stopped());
timer_.stop(); timer_.stop();
add((timer_.elapsed().user + timer_.elapsed().system) / 1000); add((timer_.elapsed().user + timer_.elapsed().system) / 1000, timer_.elapsed().wall / 1000);
#else #else
assert(timerActive_); assert(timerActive_);
double elapsed = timer_.elapsed(); double elapsed = timer_.elapsed();
add(size_t(elapsed * 1000000.0)); add(size_t(elapsed * 1000000.0), 0);
*timerActive_ = false; *timerActive_ = false;
#endif #endif
} }

View File

@ -48,6 +48,7 @@ namespace gtsam {
protected: protected:
size_t myId_; size_t myId_;
size_t t_; size_t t_;
size_t tWall_;
double t2_ ; /* cache the \sum t_i^2 */ double t2_ ; /* cache the \sum t_i^2 */
size_t tIt_; size_t tIt_;
size_t tMax_; size_t tMax_;
@ -65,7 +66,7 @@ namespace gtsam {
boost::timer timer_; boost::timer timer_;
gtsam::ValueWithDefault<bool,false> timerActive_; gtsam::ValueWithDefault<bool,false> timerActive_;
#endif #endif
void add(size_t usecs); void add(size_t usecs, size_t usecsWall);
public: public:
TimingOutline(const std::string& label, size_t myId); TimingOutline(const std::string& label, size_t myId);
size_t time() const; size_t time() const;