Print timing outline in order of appearance in code

release/4.3a0
Richard Roberts 2012-10-08 22:40:29 +00:00
parent 82593a2432
commit 9ebc906150
2 changed files with 17 additions and 7 deletions

View File

@ -49,7 +49,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), 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 #ifdef GTSAM_USING_NEW_BOOST_TIMERS
timer_.stop(); timer_.stop();
@ -72,14 +72,22 @@ size_t TimingOutline::time() const {
/* ************************************************************************* */ /* ************************************************************************* */
void TimingOutline::print(const std::string& outline) 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 << n_ << " times, " << double(time())/1000000.0 << " children, min: " << double(tMin_)/1000000.0 <<
" max: " << double(tMax_)/1000000.0 << ")\n"; " max: " << double(tMax_)/1000000.0 << ")\n";
// Order children
typedef FastMap<size_t, boost::shared_ptr<TimingOutline> > ChildOrder;
ChildOrder childOrder;
BOOST_FOREACH(const ChildMap::value_type& child, children_) { BOOST_FOREACH(const ChildMap::value_type& child, children_) {
std::string childOutline(outline); childOrder[child.second->myOrder_] = child.second;
childOutline += " ";
child.second->print(childOutline);
} }
// 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 { void TimingOutline::print2(const std::string& outline, const double parentTotal) const {
@ -128,6 +136,8 @@ const boost::shared_ptr<TimingOutline>& TimingOutline::child(size_t child, const
if(!result) { if(!result) {
// Create child if necessary // Create child if necessary
result.reset(new TimingOutline(label, child)); result.reset(new TimingOutline(label, child));
++ this->lastChildOrder_;
result->myOrder_ = this->lastChildOrder_;
result->parent_ = thisPtr; result->parent_ = thisPtr;
} }
return result; return result;

View File

@ -26,11 +26,9 @@
// Enabling the new Boost timers introduces dependencies on other Boost // Enabling the new Boost timers introduces dependencies on other Boost
// libraries so this is disabled for now until we modify the build scripts // 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. // to link each component or MATLAB wrapper with only the libraries it needs.
//#if 0
#if BOOST_VERSION >= 104800 #if BOOST_VERSION >= 104800
#define GTSAM_USING_NEW_BOOST_TIMERS #define GTSAM_USING_NEW_BOOST_TIMERS
#endif #endif
//#endif
#ifdef GTSAM_USING_NEW_BOOST_TIMERS #ifdef GTSAM_USING_NEW_BOOST_TIMERS
#include <boost/timer/timer.hpp> #include <boost/timer/timer.hpp>
@ -54,6 +52,8 @@ namespace gtsam {
size_t tMax_; size_t tMax_;
size_t tMin_; size_t tMin_;
size_t n_; size_t n_;
size_t myOrder_;
size_t lastChildOrder_;
std::string label_; std::string label_;
boost::weak_ptr<TimingOutline> parent_; boost::weak_ptr<TimingOutline> parent_;
typedef FastMap<size_t, boost::shared_ptr<TimingOutline> > ChildMap; typedef FastMap<size_t, boost::shared_ptr<TimingOutline> > ChildMap;