From 9ebc906150d0f3fca5eaecbaad8cce90112ca5e0 Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Mon, 8 Oct 2012 22:40:29 +0000 Subject: [PATCH] Print timing outline in order of appearance in code --- gtsam/base/timing.cpp | 20 +++++++++++++++----- gtsam/base/timing.h | 4 ++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/gtsam/base/timing.cpp b/gtsam/base/timing.cpp index 2cadc4129..024a68788 100644 --- a/gtsam/base/timing.cpp +++ b/gtsam/base/timing.cpp @@ -49,7 +49,7 @@ void TimingOutline::add(size_t usecs) { /* ************************************************************************* */ TimingOutline::TimingOutline(const std::string& label, size_t myId) : - myId_(myId), t_(0), t2_(0.0), tIt_(0), tMax_(0), tMin_(0), n_(0), label_(label) + myId_(myId), t_(0), t2_(0.0), tIt_(0), tMax_(0), tMin_(0), n_(0), myOrder_(0), lastChildOrder_(0), label_(label) { #ifdef GTSAM_USING_NEW_BOOST_TIMERS timer_.stop(); @@ -72,14 +72,22 @@ size_t TimingOutline::time() const { /* ************************************************************************* */ void TimingOutline::print(const std::string& outline) const { - std::cout << outline << " " << label_ << ": " << double(t_)/1000000.0 << " (" << + std::cout << outline << "-" << label_ << ": " << double(t_)/1000000.0 << " (" << n_ << " times, " << double(time())/1000000.0 << " children, min: " << double(tMin_)/1000000.0 << " max: " << double(tMax_)/1000000.0 << ")\n"; + // Order children + typedef FastMap > ChildOrder; + ChildOrder childOrder; BOOST_FOREACH(const ChildMap::value_type& child, children_) { - std::string childOutline(outline); - childOutline += " "; - child.second->print(childOutline); + childOrder[child.second->myOrder_] = child.second; } + // Print children + BOOST_FOREACH(const ChildOrder::value_type order_child, childOrder) { + std::string childOutline(outline); + childOutline += "| "; + order_child.second->print(childOutline); + } + std::cout.flush(); } void TimingOutline::print2(const std::string& outline, const double parentTotal) const { @@ -128,6 +136,8 @@ const boost::shared_ptr& TimingOutline::child(size_t child, const if(!result) { // Create child if necessary result.reset(new TimingOutline(label, child)); + ++ this->lastChildOrder_; + result->myOrder_ = this->lastChildOrder_; result->parent_ = thisPtr; } return result; diff --git a/gtsam/base/timing.h b/gtsam/base/timing.h index aeb127252..949ed187e 100644 --- a/gtsam/base/timing.h +++ b/gtsam/base/timing.h @@ -26,11 +26,9 @@ // Enabling the new Boost timers introduces dependencies on other Boost // libraries so this is disabled for now until we modify the build scripts // to link each component or MATLAB wrapper with only the libraries it needs. -//#if 0 #if BOOST_VERSION >= 104800 #define GTSAM_USING_NEW_BOOST_TIMERS #endif -//#endif #ifdef GTSAM_USING_NEW_BOOST_TIMERS #include @@ -54,6 +52,8 @@ namespace gtsam { size_t tMax_; size_t tMin_; size_t n_; + size_t myOrder_; + size_t lastChildOrder_; std::string label_; boost::weak_ptr parent_; typedef FastMap > ChildMap;