Using boost timer instead of chrono to support older boost versions
parent
1b5b4d494e
commit
dacff98f9f
|
@ -20,7 +20,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sys/time.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
|
@ -48,7 +47,7 @@ void TimingOutline::add(size_t usecs) {
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
TimingOutline::TimingOutline(const std::string& label) :
|
TimingOutline::TimingOutline(const std::string& label) :
|
||||||
t_(0), t2_(0.0), tIt_(0), tMax_(0), tMin_(0), n_(0), label_(label), timerActive_(false) {}
|
t_(0), t2_(0.0), tIt_(0), tMax_(0), tMin_(0), n_(0), label_(label) {}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
size_t TimingOutline::time() const {
|
size_t TimingOutline::time() const {
|
||||||
|
@ -151,18 +150,15 @@ const boost::shared_ptr<TimingOutline>& TimingOutline::child(size_t child, const
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void TimingOutline::tic() {
|
void TimingOutline::tic() {
|
||||||
assert(!timerActive_);
|
assert(timer_.is_stopped());
|
||||||
timerActive_ = true;
|
timer_.start();
|
||||||
gettimeofday(&t0_, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
void TimingOutline::toc() {
|
void TimingOutline::toc() {
|
||||||
struct timeval t;
|
assert(!timer_.is_stopped());
|
||||||
gettimeofday(&t, NULL);
|
timer_.stop();
|
||||||
assert(timerActive_);
|
add((timer_.elapsed().user + timer_.elapsed().system) / 1000);
|
||||||
add(t.tv_sec*1000000 + t.tv_usec - (t0_.tv_sec*1000000 + t0_.tv_usec));
|
|
||||||
timerActive_ = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
@ -231,6 +227,8 @@ void toc_(size_t id, const std::string& label) {
|
||||||
toc_(id);
|
toc_(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_OLD_TIMING
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
// Timing class implementation
|
// Timing class implementation
|
||||||
void Timing::print() {
|
void Timing::print() {
|
||||||
|
@ -260,3 +258,5 @@ void ticPop_(const std::string& prefix, const std::string& id) {
|
||||||
else
|
else
|
||||||
timingPrefix.resize(timingPrefix.size() - prefix.size() - 1);
|
timingPrefix.resize(timingPrefix.size() - prefix.size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,202 +1,204 @@
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
|
|
||||||
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
||||||
* Atlanta, Georgia 30332-0415
|
* Atlanta, Georgia 30332-0415
|
||||||
* All Rights Reserved
|
* All Rights Reserved
|
||||||
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
||||||
|
|
||||||
* See LICENSE for the license information
|
* See LICENSE for the license information
|
||||||
|
|
||||||
* -------------------------------------------------------------------------- */
|
* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file timing.h
|
* @file timing.h
|
||||||
* @brief Timing utilities
|
* @brief Timing utilities
|
||||||
* @author Richard Roberts, Michael Kaess
|
* @author Richard Roberts, Michael Kaess
|
||||||
* @date Oct 5, 2010
|
* @date Oct 5, 2010
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <boost/shared_ptr.hpp>
|
#include <boost/shared_ptr.hpp>
|
||||||
#include <boost/weak_ptr.hpp>
|
#include <boost/weak_ptr.hpp>
|
||||||
|
#include <boost/timer/timer.hpp>
|
||||||
class TimingOutline;
|
|
||||||
extern boost::shared_ptr<TimingOutline> timingRoot;
|
class TimingOutline;
|
||||||
extern boost::weak_ptr<TimingOutline> timingCurrent;
|
extern boost::shared_ptr<TimingOutline> timingRoot;
|
||||||
|
extern boost::weak_ptr<TimingOutline> timingCurrent;
|
||||||
class TimingOutline {
|
|
||||||
protected:
|
class TimingOutline {
|
||||||
size_t t_;
|
protected:
|
||||||
double t2_ ; /* cache the \sum t_i^2 */
|
size_t t_;
|
||||||
size_t tIt_;
|
double t2_ ; /* cache the \sum t_i^2 */
|
||||||
size_t tMax_;
|
size_t tIt_;
|
||||||
size_t tMin_;
|
size_t tMax_;
|
||||||
size_t n_;
|
size_t tMin_;
|
||||||
std::string label_;
|
size_t n_;
|
||||||
|
std::string label_;
|
||||||
boost::weak_ptr<TimingOutline> parent_;
|
|
||||||
std::vector<boost::shared_ptr<TimingOutline> > children_;
|
boost::weak_ptr<TimingOutline> parent_;
|
||||||
struct timeval t0_;
|
std::vector<boost::shared_ptr<TimingOutline> > children_;
|
||||||
bool timerActive_;
|
boost::timer::cpu_timer timer_;
|
||||||
|
|
||||||
void add(size_t usecs);
|
void add(size_t usecs);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TimingOutline(const std::string& label);
|
TimingOutline(const std::string& label);
|
||||||
|
|
||||||
size_t time() const;
|
size_t time() const;
|
||||||
|
|
||||||
void print(const std::string& outline = "") const;
|
void print(const std::string& outline = "") const;
|
||||||
|
|
||||||
void print2(const std::string& outline = "", const double parentTotal = -1.0) const;
|
void print2(const std::string& outline = "", const double parentTotal = -1.0) const;
|
||||||
|
|
||||||
const boost::shared_ptr<TimingOutline>& child(size_t child, const std::string& label, const boost::weak_ptr<TimingOutline>& thisPtr);
|
const boost::shared_ptr<TimingOutline>& child(size_t child, const std::string& label, const boost::weak_ptr<TimingOutline>& thisPtr);
|
||||||
|
|
||||||
void tic();
|
void tic();
|
||||||
|
|
||||||
void toc();
|
void toc();
|
||||||
|
|
||||||
void finishedIteration();
|
void finishedIteration();
|
||||||
|
|
||||||
friend class AutoTimer;
|
friend class AutoTimer;
|
||||||
friend void toc_(size_t id);
|
friend void toc_(size_t id);
|
||||||
friend void toc_(size_t id, const std::string& label);
|
friend void toc_(size_t id, const std::string& label);
|
||||||
}; // \TimingOutline
|
}; // \TimingOutline
|
||||||
|
|
||||||
void tic_(size_t id, const std::string& label);
|
void tic_(size_t id, const std::string& label);
|
||||||
|
|
||||||
void toc_(size_t id);
|
void toc_(size_t id);
|
||||||
|
|
||||||
void toc_(size_t id, const std::string& label);
|
void toc_(size_t id, const std::string& label);
|
||||||
|
|
||||||
inline void tictoc_finishedIteration_() {
|
inline void tictoc_finishedIteration_() {
|
||||||
timingRoot->finishedIteration();
|
timingRoot->finishedIteration();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_TIMING
|
#ifdef ENABLE_TIMING
|
||||||
inline void tic(size_t id, const std::string& label) { tic_(id, label); }
|
inline void tic(size_t id, const std::string& label) { tic_(id, label); }
|
||||||
inline void toc(size_t id) { toc_(id); }
|
inline void toc(size_t id) { toc_(id); }
|
||||||
inline void toc(size_t id, const std::string& label) { toc_(id, label); }
|
inline void toc(size_t id, const std::string& label) { toc_(id, label); }
|
||||||
inline void tictoc_finishedIteration() { tictoc_finishedIteration_(); }
|
inline void tictoc_finishedIteration() { tictoc_finishedIteration_(); }
|
||||||
#else
|
#else
|
||||||
inline void tic(size_t, const char*) {}
|
inline void tic(size_t, const char*) {}
|
||||||
inline void toc(size_t) {}
|
inline void toc(size_t) {}
|
||||||
inline void toc(size_t, const char*) {}
|
inline void toc(size_t, const char*) {}
|
||||||
inline void tictoc_finishedIteration() {}
|
inline void tictoc_finishedIteration() {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// simple class for accumulating execution timing information by name
|
|
||||||
class Timing;
|
inline void tictoc_print_() {
|
||||||
extern Timing timing;
|
timingRoot->print();
|
||||||
extern std::string timingPrefix;
|
}
|
||||||
|
|
||||||
double _tic();
|
/* print mean and standard deviation */
|
||||||
double _toc(double t);
|
inline void tictoc_print2_() {
|
||||||
double tic(const std::string& id);
|
timingRoot->print2();
|
||||||
double toc(const std::string& id);
|
}
|
||||||
void ticPush(const std::string& id);
|
|
||||||
void ticPop(const std::string& id);
|
#ifdef ENABLE_OLD_TIMING
|
||||||
void tictoc_print();
|
|
||||||
void tictoc_finishedIteration();
|
// simple class for accumulating execution timing information by name
|
||||||
|
class Timing;
|
||||||
/** These underscore versions work evening when ENABLE_TIMING is not defined */
|
extern Timing timing;
|
||||||
double _tic_();
|
extern std::string timingPrefix;
|
||||||
double _toc_(double t);
|
|
||||||
double tic_(const std::string& id);
|
double _tic();
|
||||||
double toc_(const std::string& id);
|
double _toc(double t);
|
||||||
void ticPush_(const std::string& id);
|
double tic(const std::string& id);
|
||||||
void ticPop_(const std::string& id);
|
double toc(const std::string& id);
|
||||||
void tictoc_print_();
|
void ticPush(const std::string& id);
|
||||||
void tictoc_finishedIteration_();
|
void ticPop(const std::string& id);
|
||||||
|
void tictoc_finishedIteration();
|
||||||
|
|
||||||
|
/** These underscore versions work evening when ENABLE_TIMING is not defined */
|
||||||
// simple class for accumulating execution timing information by name
|
double _tic_();
|
||||||
class Timing {
|
double _toc_(double t);
|
||||||
class Stats {
|
double tic_(const std::string& id);
|
||||||
public:
|
double toc_(const std::string& id);
|
||||||
std::string label;
|
void ticPush_(const std::string& id);
|
||||||
double t0;
|
void ticPop_(const std::string& id);
|
||||||
double t;
|
void tictoc_finishedIteration_();
|
||||||
double t_max;
|
|
||||||
double t_min;
|
|
||||||
int n;
|
|
||||||
};
|
// simple class for accumulating execution timing information by name
|
||||||
std::map<std::string, Stats> stats;
|
class Timing {
|
||||||
public:
|
class Stats {
|
||||||
void add_t0(const std::string& id, double t0) {
|
public:
|
||||||
stats[id].t0 = t0;
|
std::string label;
|
||||||
}
|
double t0;
|
||||||
double get_t0(const std::string& id) {
|
double t;
|
||||||
return stats[id].t0;
|
double t_max;
|
||||||
}
|
double t_min;
|
||||||
void add_dt(const std::string& id, double dt) {
|
int n;
|
||||||
Stats& s = stats[id];
|
};
|
||||||
s.t += dt;
|
std::map<std::string, Stats> stats;
|
||||||
s.n++;
|
public:
|
||||||
if (s.n==1 || s.t_max < dt) s.t_max = dt;
|
void add_t0(const std::string& id, double t0) {
|
||||||
if (s.n==1 || s.t_min > dt) s.t_min = dt;
|
stats[id].t0 = t0;
|
||||||
}
|
}
|
||||||
void print();
|
double get_t0(const std::string& id) {
|
||||||
|
return stats[id].t0;
|
||||||
double time(const std::string& id) {
|
}
|
||||||
Stats& s = stats[id];
|
void add_dt(const std::string& id, double dt) {
|
||||||
return s.t;
|
Stats& s = stats[id];
|
||||||
}
|
s.t += dt;
|
||||||
};
|
s.n++;
|
||||||
|
if (s.n==1 || s.t_max < dt) s.t_max = dt;
|
||||||
double _tic_();
|
if (s.n==1 || s.t_min > dt) s.t_min = dt;
|
||||||
inline double _toc_(double t) {
|
}
|
||||||
double s = _tic_();
|
void print();
|
||||||
return (std::max(0., s-t));
|
|
||||||
}
|
double time(const std::string& id) {
|
||||||
inline double tic_(const std::string& id) {
|
Stats& s = stats[id];
|
||||||
double t0 = _tic_();
|
return s.t;
|
||||||
timing.add_t0(timingPrefix + " " + id, t0);
|
}
|
||||||
return t0;
|
};
|
||||||
}
|
|
||||||
inline double toc_(const std::string& id) {
|
double _tic_();
|
||||||
std::string comb(timingPrefix + " " + id);
|
inline double _toc_(double t) {
|
||||||
double dt = _toc_(timing.get_t0(comb));
|
double s = _tic_();
|
||||||
timing.add_dt(comb, dt);
|
return (std::max(0., s-t));
|
||||||
return dt;
|
}
|
||||||
}
|
inline double tic_(const std::string& id) {
|
||||||
inline void ticPush_(const std::string& prefix, const std::string& id) {
|
double t0 = _tic_();
|
||||||
if(timingPrefix.size() > 0)
|
timing.add_t0(timingPrefix + " " + id, t0);
|
||||||
timingPrefix += ".";
|
return t0;
|
||||||
timingPrefix += prefix;
|
}
|
||||||
tic_(id);
|
inline double toc_(const std::string& id) {
|
||||||
}
|
std::string comb(timingPrefix + " " + id);
|
||||||
void ticPop_(const std::string& prefix, const std::string& id);
|
double dt = _toc_(timing.get_t0(comb));
|
||||||
|
timing.add_dt(comb, dt);
|
||||||
inline void tictoc_print_() {
|
return dt;
|
||||||
timing.print();
|
}
|
||||||
timingRoot->print();
|
inline void ticPush_(const std::string& prefix, const std::string& id) {
|
||||||
}
|
if(timingPrefix.size() > 0)
|
||||||
|
timingPrefix += ".";
|
||||||
/* print mean and standard deviation */
|
timingPrefix += prefix;
|
||||||
inline void tictoc_print2_() {
|
tic_(id);
|
||||||
timingRoot->print2();
|
}
|
||||||
}
|
void ticPop_(const std::string& prefix, const std::string& id);
|
||||||
|
|
||||||
#ifdef ENABLE_TIMING
|
#ifdef ENABLE_TIMING
|
||||||
inline double _tic() { return _tic_(); }
|
inline double _tic() { return _tic_(); }
|
||||||
inline double _toc(double t) { return _toc_(t); }
|
inline double _toc(double t) { return _toc_(t); }
|
||||||
inline double tic(const std::string& id) { return tic_(id); }
|
inline double tic(const std::string& id) { return tic_(id); }
|
||||||
inline double toc(const std::string& id) { return toc_(id); }
|
inline double toc(const std::string& id) { return toc_(id); }
|
||||||
inline void ticPush(const std::string& prefix, const std::string& id) { ticPush_(prefix, id); }
|
inline void ticPush(const std::string& prefix, const std::string& id) { ticPush_(prefix, id); }
|
||||||
inline void ticPop(const std::string& prefix, const std::string& id) { ticPop_(prefix, id); }
|
inline void ticPop(const std::string& prefix, const std::string& id) { ticPop_(prefix, id); }
|
||||||
inline void tictoc_print() { tictoc_print_(); }
|
inline void tictoc_print() { tictoc_print_(); }
|
||||||
#else
|
#else
|
||||||
inline double _tic() {return 0.;}
|
inline double _tic() {return 0.;}
|
||||||
inline double _toc(double) {return 0.;}
|
inline double _toc(double) {return 0.;}
|
||||||
inline double tic(const std::string&) {return 0.;}
|
inline double tic(const std::string&) {return 0.;}
|
||||||
inline double toc(const std::string&) {return 0.;}
|
inline double toc(const std::string&) {return 0.;}
|
||||||
inline void ticPush(const std::string&, const std::string&) {}
|
inline void ticPush(const std::string&, const std::string&) {}
|
||||||
inline void ticPop(const std::string&, const std::string&) {}
|
inline void ticPop(const std::string&, const std::string&) {}
|
||||||
inline void tictoc_print() {}
|
inline void tictoc_print() {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
|
@ -140,19 +140,13 @@ SharedDiagonal Gaussian::Cholesky(Matrix& Ab, size_t nFrontals) const {
|
||||||
// TODO: really no rank problems ?
|
// TODO: really no rank problems ?
|
||||||
|
|
||||||
// pre-whiten everything (cheaply if possible)
|
// pre-whiten everything (cheaply if possible)
|
||||||
tic("Cholesky: 1 whiten");
|
|
||||||
WhitenInPlace(Ab);
|
WhitenInPlace(Ab);
|
||||||
toc("Cholesky: 1 whiten");
|
|
||||||
|
|
||||||
// Form A'*A (todo: this is probably less efficient than possible)
|
// Form A'*A (todo: this is probably less efficient than possible)
|
||||||
tic("Cholesky: 2 A' * A");
|
|
||||||
Ab = Ab.transpose() * Ab;
|
Ab = Ab.transpose() * Ab;
|
||||||
toc("Cholesky: 2 A' * A");
|
|
||||||
|
|
||||||
// Use Cholesky to factor Ab
|
// Use Cholesky to factor Ab
|
||||||
tic("Cholesky: 3 careful");
|
|
||||||
size_t maxrank = choleskyCareful(Ab).first;
|
size_t maxrank = choleskyCareful(Ab).first;
|
||||||
toc("Cholesky: 3 careful");
|
|
||||||
|
|
||||||
// Due to numerical error the rank could appear to be more than the number
|
// Due to numerical error the rank could appear to be more than the number
|
||||||
// of variables. The important part is that it does not includes the
|
// of variables. The important part is that it does not includes the
|
||||||
|
|
Loading…
Reference in New Issue