40 GTSAM_EXPORT std::shared_ptr<TimingOutline>
gTimingRoot(
53 double secs = (double(usecs) / 1000000.0);
60 id_(
id), t_(0), tWall_(0), t2_(0.0), tIt_(0), tMax_(0), tMin_(0), n_(0), myOrder_(
61 0), lastChildOrder_(0), label_(label) {
62 #if GTSAM_USE_BOOST_FEATURES
63 #ifdef GTSAM_USING_NEW_BOOST_TIMERS
71 #if GTSAM_USE_BOOST_FEATURES
73 bool hasChildren =
false;
89 #if GTSAM_USE_BOOST_FEATURES
90 std::string formattedLabel =
label_;
91 std::replace(formattedLabel.begin(), formattedLabel.end(),
'_',
' ');
92 std::cout << outline <<
"-" << formattedLabel <<
": " <<
self() <<
" CPU ("
93 <<
n_ <<
" times, " << wall() <<
" wall, " << secs() <<
" children, min: "
94 <<
min() <<
" max: " <<
max() <<
")\n";
98 childOrder[
child.second->myOrder_] =
child.second;
101 for(
const ChildOrder::value_type& order_child: childOrder) {
102 std::string childOutline(outline);
103 childOutline +=
"| ";
104 order_child.second->print(childOutline);
112 #if GTSAM_USE_BOOST_FEATURES
115 std::cout <<
label_ +
" cpu time (s)" <<
"," <<
label_ +
" #calls" <<
","
116 <<
label_ +
" wall time(s)" <<
"," <<
label_ +
" subtree time (s)"
117 <<
"," <<
label_ +
" min time (s)" <<
"," <<
label_ +
"max time(s)"
122 childOrder[
child.second->myOrder_] =
child.second;
125 for (
const ChildOrder::value_type& order_child : childOrder) {
126 order_child.second->printCsvHeader();
129 std::cout << std::endl;
137 #if GTSAM_USE_BOOST_FEATURES
140 std::cout <<
self() <<
"," <<
n_ <<
"," << wall() <<
"," << secs() <<
","
141 <<
min() <<
"," <<
max() <<
",";
145 childOrder[
child.second->myOrder_] =
child.second;
148 for (
const ChildOrder::value_type& order_child : childOrder) {
149 order_child.second->printCsv(
false);
152 std::cout << std::endl;
159 const double parentTotal)
const {
160 #if GTSAM_USE_BOOST_FEATURES
161 const int w1 = 24, w2 = 2, w3 = 6, w4 = 8,
precision = 2;
162 const double selfTotal =
self(), selfMean = selfTotal /
double(
n_);
163 const double childTotal = secs();
166 const double selfStd =
sqrt(
t2_ /
double(
n_) - selfMean * selfMean);
167 const std::string label = outline +
label_ +
": ";
170 std::cout << label << std::fixed << std::setprecision(
precision)
171 << childTotal <<
" seconds" << std::endl;
173 std::cout << std::setw(w1 + outline.length()) << label;
176 << std::setw(w3) << std::setprecision(
precision) << selfMean
178 << std::setw(w3) << std::setprecision(
precision) << selfStd <<
" (std),"
180 << std::setprecision(
precision) << selfTotal <<
" (total),";
182 if (parentTotal > 0.0)
184 << std::setw(w3) << std::setprecision(
precision)
185 << 100.0 * selfTotal / parentTotal <<
" (%)";
187 std::cout << std::endl;
191 std::string childOutline(outline);
193 child.second->print2(childOutline, childTotal);
196 child.second->print2(childOutline, selfTotal);
204 const std::string& label,
const std::weak_ptr<TimingOutline>& thisPtr) {
205 #if GTSAM_USE_BOOST_FEATURES
206 assert(thisPtr.lock().get() ==
this);
213 result->parent_ = thisPtr;
224 #if GTSAM_USE_BOOST_FEATURES
225 #ifdef GTSAM_USING_NEW_BOOST_TIMERS
226 assert(timer_.is_stopped());
229 assert(!timerActive_);
231 *timerActive_ =
true;
235 tbbTimer_ = tbb::tick_count::now();
243 #if GTSAM_USE_BOOST_FEATURES
245 #ifdef GTSAM_USING_NEW_BOOST_TIMERS
247 assert(!timer_.is_stopped());
249 size_t cpuTime = (timer_.elapsed().user + timer_.elapsed().system) / 1000;
250 # ifndef GTSAM_USE_TBB
251 size_t wallTime = timer_.elapsed().wall / 1000;
256 assert(timerActive_);
257 double elapsed = timer_.elapsed();
259 *timerActive_ =
false;
260 # ifndef GTSAM_USE_TBB
261 size_t wallTime = cpuTime;
268 (tbb::tick_count::now() - tbbTimer_).seconds() * 1e6);
271 add(cpuTime, wallTime);
277 #if GTSAM_USE_BOOST_FEATURES
284 child.second->finishedIteration();
292 #if GTSAM_USE_BOOST_FEATURES
295 static size_t nextId = 0;
300 if (it == idMap.end()) {
313 void tic(
size_t id,
const char *labelC) {
315 #if GTSAM_USE_BOOST_FEATURES
316 const std::string label(labelC);
317 std::shared_ptr<TimingOutline> node =
325 void toc(
size_t id,
const char *labelC) {
327 #if GTSAM_USE_BOOST_FEATURES
328 const std::string label(labelC);
329 std::shared_ptr<TimingOutline> current(
gCurrentTimer.lock());
330 if (
id != current->id_) {
332 throw std::invalid_argument(
333 "gtsam timing: Mismatched tic/toc: gttoc(\"" + label +
334 "\") called when last tic was \"" + current->label_ +
"\".");
336 if (!current->parent_.lock()) {
338 throw std::invalid_argument(
339 "gtsam timing: Mismatched tic/toc: extra gttoc(\"" + label +
340 "\"), already at the root");