38 GTSAM_EXPORT std::shared_ptr<TimingOutline>
gTimingRoot(
51 double secs = (double(usecs) / 1000000.0);
58 id_(
id), t_(0), tWall_(0), t2_(0.0), tIt_(0), tMax_(0), tMin_(0), n_(0), myOrder_(
59 0), lastChildOrder_(0), label_(label) {
60 #ifdef GTSAM_USE_BOOST_FEATURES
61 #ifdef GTSAM_USING_NEW_BOOST_TIMERS
69 #ifdef GTSAM_USE_BOOST_FEATURES
71 bool hasChildren =
false;
87 #ifdef GTSAM_USE_BOOST_FEATURES
88 std::string formattedLabel =
label_;
89 std::replace(formattedLabel.begin(), formattedLabel.end(),
'_',
' ');
90 std::cout << outline <<
"-" << formattedLabel <<
": " <<
self() <<
" CPU ("
91 <<
n_ <<
" times, " << wall() <<
" wall, " << secs() <<
" children, min: "
92 <<
min() <<
" max: " <<
max() <<
")\n";
95 ChildOrder childOrder;
97 childOrder[
child.second->myOrder_] =
child.second;
100 for(
const ChildOrder::value_type& order_child: childOrder) {
101 std::string childOutline(outline);
102 childOutline +=
"| ";
103 order_child.second->print(childOutline);
110 const double parentTotal)
const {
111 #ifdef GTSAM_USE_BOOST_FEATURES
112 const int w1 = 24, w2 = 2, w3 = 6, w4 = 8,
precision = 2;
113 const double selfTotal =
self(), selfMean = selfTotal /
double(
n_);
114 const double childTotal = secs();
117 const double selfStd =
sqrt(
t2_ /
double(
n_) - selfMean * selfMean);
118 const std::string label = outline +
label_ +
": ";
121 std::cout << label << std::fixed << std::setprecision(
precision)
122 << childTotal <<
" seconds" << std::endl;
124 std::cout << std::setw(w1 + outline.length()) << label;
127 << std::setw(w3) << std::setprecision(
precision) << selfMean
129 << std::setw(w3) << std::setprecision(
precision) << selfStd <<
" (std),"
131 << std::setprecision(
precision) << selfTotal <<
" (total),";
133 if (parentTotal > 0.0)
135 << std::setw(w3) << std::setprecision(
precision)
136 << 100.0 * selfTotal / parentTotal <<
" (%)";
138 std::cout << std::endl;
142 std::string childOutline(outline);
144 child.second->print2(childOutline, childTotal);
147 child.second->print2(childOutline, selfTotal);
155 const std::string& label,
const std::weak_ptr<TimingOutline>& thisPtr) {
156 #ifdef GTSAM_USE_BOOST_FEATURES
157 assert(thisPtr.lock().get() ==
this);
164 result->parent_ = thisPtr;
175 #ifdef GTSAM_USE_BOOST_FEATURES
176 #ifdef GTSAM_USING_NEW_BOOST_TIMERS
177 assert(timer_.is_stopped());
180 assert(!timerActive_);
182 *timerActive_ =
true;
186 tbbTimer_ = tbb::tick_count::now();
194 #ifdef GTSAM_USE_BOOST_FEATURES
196 #ifdef GTSAM_USING_NEW_BOOST_TIMERS
198 assert(!timer_.is_stopped());
200 size_t cpuTime = (timer_.elapsed().user + timer_.elapsed().system) / 1000;
201 # ifndef GTSAM_USE_TBB
202 size_t wallTime = timer_.elapsed().wall / 1000;
207 assert(timerActive_);
208 double elapsed = timer_.elapsed();
210 *timerActive_ =
false;
211 # ifndef GTSAM_USE_TBB
212 size_t wallTime = cpuTime;
219 (tbb::tick_count::now() - tbbTimer_).seconds() * 1e6);
222 add(cpuTime, wallTime);
228 #ifdef GTSAM_USE_BOOST_FEATURES
235 child.second->finishedIteration();
243 #ifdef GTSAM_USE_BOOST_FEATURES
246 static size_t nextId = 0;
251 if (it == idMap.end()) {
264 void tic(
size_t id,
const char *labelC) {
266 #ifdef GTSAM_USE_BOOST_FEATURES
267 const std::string label(labelC);
268 std::shared_ptr<TimingOutline> node =
276 void toc(
size_t id,
const char *labelC) {
278 #ifdef GTSAM_USE_BOOST_FEATURES
279 const std::string label(labelC);
280 std::shared_ptr<TimingOutline> current(
gCurrentTimer.lock());
281 if (
id != current->id_) {
283 throw std::invalid_argument(
284 "gtsam timing: Mismatched tic/toc: gttoc(\"" + label +
285 "\") called when last tic was \"" + current->label_ +
"\".");
287 if (!current->parent_.lock()) {
289 throw std::invalid_argument(
290 "gtsam timing: Mismatched tic/toc: extra gttoc(\"" + label +
291 "\"), already at the root");