22 #include <boost/algorithm/string/replace.hpp> 23 #include <boost/format.hpp> 37 GTSAM_EXPORT boost::shared_ptr<TimingOutline>
gTimingRoot(
50 double secs = (double(usecs) / 1000000.0);
59 #ifdef GTSAM_USING_NEW_BOOST_TIMERS 67 bool hasChildren =
false;
69 time +=
child.second->time();
80 std::string formattedLabel =
label_;
81 boost::replace_all(formattedLabel,
"_",
" ");
82 std::cout << outline <<
"-" << formattedLabel <<
": " <<
self() <<
" CPU (" 83 <<
n_ <<
" times, " <<
wall() <<
" wall, " <<
secs() <<
" children, min: " 84 <<
min() <<
" max: " <<
max() <<
")\n";
87 ChildOrder childOrder;
89 childOrder[
child.second->myOrder_] =
child.second;
92 for(
const ChildOrder::value_type& order_child: childOrder) {
93 std::string childOutline(outline);
95 order_child.second->print(childOutline);
101 const double parentTotal)
const {
103 const int w1 = 24, w2 = 2, w3 = 6, w4 = 8,
precision = 2;
104 const double selfTotal =
self(), selfMean = selfTotal /
double(
n_);
105 const double childTotal =
secs();
108 const double selfStd =
sqrt(
t2_ /
double(
n_) - selfMean * selfMean);
109 const std::string label = outline +
label_ +
": ";
112 std::cout << label << std::fixed << std::setprecision(
precision)
113 << childTotal <<
" seconds" << std::endl;
115 std::cout << std::setw(w1 + outline.length()) << label;
118 << std::setw(w3) << std::setprecision(
precision) << selfMean
120 << std::setw(w3) << std::setprecision(
precision) << selfStd <<
" (std)," 122 << std::setprecision(
precision) << selfTotal <<
" (total),";
124 if (parentTotal > 0.0)
126 << std::setw(w3) << std::setprecision(
precision)
127 << 100.0 * selfTotal / parentTotal <<
" (%)";
129 std::cout << std::endl;
133 std::string childOutline(outline);
135 child.second->print2(childOutline, childTotal);
138 child.second->print2(childOutline, selfTotal);
145 const std::string& label,
const boost::weak_ptr<TimingOutline>& thisPtr) {
146 assert(thisPtr.lock().get() ==
this);
153 result->parent_ = thisPtr;
160 #ifdef GTSAM_USING_NEW_BOOST_TIMERS 161 assert(
timer_.is_stopped());
170 tbbTimer_ = tbb::tick_count::now();
176 #ifdef GTSAM_USING_NEW_BOOST_TIMERS 178 assert(!
timer_.is_stopped());
180 size_t cpuTime = (
timer_.elapsed().user +
timer_.elapsed().system) / 1000;
181 # ifndef GTSAM_USE_TBB 182 size_t wallTime =
timer_.elapsed().wall / 1000;
189 size_t cpuTime =
size_t(elapsed * 1000000.0);
191 # ifndef GTSAM_USE_TBB 192 size_t wallTime = cpuTime;
199 (tbb::tick_count::now() - tbbTimer_).seconds() * 1e6);
202 add(cpuTime, wallTime);
213 child.second->finishedIteration();
221 static size_t nextId = 0;
227 if (it == idMap.end()) {
228 it = idMap.insert(std::make_pair(description, nextId)).first;
237 void tic(
size_t id,
const char *labelC) {
238 const std::string label(labelC);
239 boost::shared_ptr<TimingOutline> node =
246 void toc(
size_t id,
const char *label) {
247 boost::shared_ptr<TimingOutline> current(
gCurrentTimer.lock());
248 if (
id != current->id_) {
250 throw std::invalid_argument(
252 "gtsam timing: Mismatched tic/toc: gttoc(\"%s\") called when last tic was \"%s\".")
253 % label % current->label_).str());
255 if (!current->parent_.lock()) {
257 throw std::invalid_argument(
259 "gtsam timing: Mismatched tic/toc: extra gttoc(\"%s\"), already at the root")
double t2_
cache the t_i^2
GTSAM_EXTERN_EXPORT boost::shared_ptr< TimingOutline > gTimingRoot
GTSAM_EXPORT const boost::shared_ptr< TimingOutline > & child(size_t child, const std::string &label, const boost::weak_ptr< TimingOutline > &thisPtr)
GTSAM_EXPORT void finishedIteration()
GTSAM_EXTERN_EXPORT boost::weak_ptr< TimingOutline > gCurrentTimer
double wall() const
wall time, in seconds
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
gtsam::ValueWithDefault< bool, false > timerActive_
double min() const
min time, in seconds
GTSAM_EXPORT void print(const std::string &outline="") const
GTSAM_EXPORT size_t time() const
time taken, including children
double secs() const
time taken, in seconds, including children
GTSAM_EXPORT TimingOutline(const std::string &label, size_t myId)
Constructor.
void add(size_t usecs, size_t usecsWall)
size_t getTicTocID(const char *descriptionC)
double max() const
max time, in seconds
GTSAM_EXPORT void print2(const std::string &outline="", const double parentTotal=-1.0) const
ChildMap children_
subtrees