37 GTSAM_EXPORT std::shared_ptr<TimingOutline>
gTimingRoot(
50 double secs = (double(usecs) / 1000000.0);
59 #ifdef GTSAM_USE_BOOST_FEATURES 60 #ifdef GTSAM_USING_NEW_BOOST_TIMERS 68 #ifdef GTSAM_USE_BOOST_FEATURES 70 bool hasChildren =
false;
72 time +=
child.second->time();
86 #ifdef GTSAM_USE_BOOST_FEATURES 87 std::string formattedLabel =
label_;
88 std::replace(formattedLabel.begin(), formattedLabel.end(),
'_',
' ');
89 std::cout << outline <<
"-" << formattedLabel <<
": " <<
self() <<
" CPU (" 90 <<
n_ <<
" times, " <<
wall() <<
" wall, " <<
secs() <<
" children, min: " 91 <<
min() <<
" max: " <<
max() <<
")\n";
94 ChildOrder childOrder;
96 childOrder[
child.second->myOrder_] =
child.second;
99 for(
const ChildOrder::value_type& order_child: childOrder) {
100 std::string childOutline(outline);
101 childOutline +=
"| ";
102 order_child.second->print(childOutline);
109 const double parentTotal)
const {
110 #ifdef GTSAM_USE_BOOST_FEATURES 111 const int w1 = 24, w2 = 2, w3 = 6, w4 = 8,
precision = 2;
112 const double selfTotal =
self(), selfMean = selfTotal /
double(
n_);
113 const double childTotal =
secs();
116 const double selfStd =
sqrt(
t2_ /
double(
n_) - selfMean * selfMean);
117 const std::string label = outline +
label_ +
": ";
120 std::cout << label << std::fixed << std::setprecision(
precision)
121 << childTotal <<
" seconds" << std::endl;
123 std::cout << std::setw(w1 + outline.length()) << label;
126 << std::setw(w3) << std::setprecision(
precision) << selfMean
128 << std::setw(w3) << std::setprecision(
precision) << selfStd <<
" (std)," 130 << std::setprecision(
precision) << selfTotal <<
" (total),";
132 if (parentTotal > 0.0)
134 << std::setw(w3) << std::setprecision(
precision)
135 << 100.0 * selfTotal / parentTotal <<
" (%)";
137 std::cout << std::endl;
141 std::string childOutline(outline);
143 child.second->print2(childOutline, childTotal);
146 child.second->print2(childOutline, selfTotal);
154 const std::string& label,
const std::weak_ptr<TimingOutline>& thisPtr) {
155 #ifdef GTSAM_USE_BOOST_FEATURES 156 assert(thisPtr.lock().get() ==
this);
163 result->parent_ = thisPtr;
174 #ifdef GTSAM_USE_BOOST_FEATURES 175 #ifdef GTSAM_USING_NEW_BOOST_TIMERS 176 assert(timer_.is_stopped());
179 assert(!timerActive_);
181 *timerActive_ =
true;
185 tbbTimer_ = tbb::tick_count::now();
193 #ifdef GTSAM_USE_BOOST_FEATURES 195 #ifdef GTSAM_USING_NEW_BOOST_TIMERS 197 assert(!timer_.is_stopped());
199 size_t cpuTime = (timer_.elapsed().user + timer_.elapsed().system) / 1000;
200 # ifndef GTSAM_USE_TBB 201 size_t wallTime = timer_.elapsed().wall / 1000;
206 assert(timerActive_);
207 double elapsed = timer_.elapsed();
208 size_t cpuTime =
size_t(elapsed * 1000000.0);
209 *timerActive_ =
false;
210 # ifndef GTSAM_USE_TBB 211 size_t wallTime = cpuTime;
218 (tbb::tick_count::now() - tbbTimer_).seconds() * 1e6);
221 add(cpuTime, wallTime);
227 #ifdef GTSAM_USE_BOOST_FEATURES 234 child.second->finishedIteration();
242 #ifdef GTSAM_USE_BOOST_FEATURES 245 static size_t nextId = 0;
249 auto it = idMap.find(description);
250 if (it == idMap.end()) {
263 void tic(
size_t id,
const char *labelC) {
265 #ifdef GTSAM_USE_BOOST_FEATURES 266 const std::string label(labelC);
267 std::shared_ptr<TimingOutline> node =
275 void toc(
size_t id,
const char *labelC) {
277 #ifdef GTSAM_USE_BOOST_FEATURES 278 const std::string label(labelC);
279 std::shared_ptr<TimingOutline> current(
gCurrentTimer.lock());
280 if (
id != current->id_) {
282 throw std::invalid_argument(
283 "gtsam timing: Mismatched tic/toc: gttoc(\"" + label +
284 "\") called when last tic was \"" + current->label_ +
"\".");
286 if (!current->parent_.lock()) {
288 throw std::invalid_argument(
289 "gtsam timing: Mismatched tic/toc: extra gttoc(\"" + label +
290 "\"), already at the root");
double max() const
max time, in seconds
GTSAM_EXPORT size_t time() const
time taken, including children
double secs() const
time taken, in seconds, including children
GTSAM_EXPORT void finishedIteration()
static const std::shared_ptr< TimingOutline > nullTimingOutline
double min() const
min time, in seconds
GTSAM_EXPORT void print2(const std::string &outline="", const double parentTotal=-1.0) const
double wall() const
wall time, in seconds
GTSAM_EXPORT const std::shared_ptr< TimingOutline > & child(size_t child, const std::string &label, const std::weak_ptr< TimingOutline > &thisPtr)
GTSAM_EXTERN_EXPORT std::shared_ptr< TimingOutline > gTimingRoot
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)
GTSAM_EXTERN_EXPORT std::weak_ptr< TimingOutline > gCurrentTimer
Jet< T, N > sqrt(const Jet< T, N > &f)
ChildMap children_
subtrees
GTSAM_EXPORT void print(const std::string &outline="") const