10 #ifndef __SOT_TIMER_HH 11 #define __SOT_TIMER_HH 24 #include <dynamic-graph/linear-algebra.h> 29 #include <dynamic-graph/all-signals.h> 30 #include <dynamic-graph/entity.h> 38 #if defined(timer_EXPORTS) 39 #define Timer_EXPORT __declspec(dllexport) 41 #define Timer_EXPORT __declspec(dllimport) 54 virtual const std::string &
getClassName(
void)
const {
return CLASS_NAME; }
57 struct timeval t0, t1;
63 Timer(
const std::string &name);
66 virtual void display(std::ostream &os)
const;
74 dynamicgraph::SignalPtr<T, int>
sigSIN;
75 dynamicgraph::SignalTimeDependent<T, int>
sigSOUT;
80 void plug(dynamicgraph::Signal<T, int> &sig) {
85 template <
bool UseClock> T &
compute(T &t,
const int &time) {
89 sotDEBUG(15) <<
"t0: " << c0 << std::endl;
91 gettimeofday(&t0, NULL);
92 sotDEBUG(15) <<
"t0: " << t0.tv_sec <<
" - " << t0.tv_usec << std::endl;
99 sotDEBUG(15) <<
"t1: " << c0 << std::endl;
100 dt = ((double)(c1 - c0) * 1000) / CLOCKS_PER_SEC;
102 gettimeofday(&t1, NULL);
103 dt = ((
static_cast<double>(t1.tv_sec) - static_cast<double>(t0.tv_sec)) *
105 (static_cast<double>(t1.tv_usec) -
static_cast<double>(t0.tv_usec) +
108 sotDEBUG(15) <<
"t1: " << t1.tv_sec <<
" - " << t1.tv_usec << std::endl;
112 timerSOUT.setTime(time);
118 double &
getDt(
double &res,
const int & ) {
124 void cmdChrono(
const std::string &cmd, std::istringstream &args,
134 : Entity(name), dt(0.), sigSIN(NULL,
"Timer(" + name +
")::input(T)::sin"),
135 sigSOUT(boost::bind(&
Timer::compute<false>, this, _1, _2), sigSIN,
136 "Timer(" + name +
")::output(T)::sout"),
137 sigClockSOUT(boost::bind(&
Timer::compute<true>, this, _1, _2), sigSIN,
138 "Timer(" + name +
")::output(T)::clockSout"),
139 timerSOUT(
"Timer(" + name +
")::output(double)::timer") {
149 os <<
"Timer <" <<
sigSIN <<
"> : " <<
dt <<
"ms." << std::endl;
dynamicgraph::SignalTimeDependent< T, int > sigClockSOUT
Definition: timer.hh:76
dynamicgraph::SignalPtr< T, int > sigSIN
Definition: timer.hh:74
double & getDt(double &res, const int &)
Definition: timer.hh:118
#define sotDEBUGOUT(level)
Definition: debug.hh:214
static const std::string CLASS_NAME
Definition: timer.hh:53
#define sotDEBUGIN(level)
Definition: debug.hh:213
Timer_EXPORT friend std::ostream & operator<<(std::ostream &os, const Timer< T > &timer)
Definition: timer.hh:67
Timer(const std::string &name)
Definition: timer.hh:133
double dt
Definition: timer.hh:59
clock_t c1
Definition: timer.hh:58
#define sotDEBUG(level)
Definition: debug.hh:167
virtual void display(std::ostream &os) const
Definition: timer.hh:148
dynamicgraph::SignalTimeDependent< T, int > sigSOUT
Definition: timer.hh:75
dynamicgraph::Signal< double, int > timerSOUT
Definition: timer.hh:77
virtual const std::string & getClassName(void) const
Definition: timer.hh:54
#define Timer_EXPORT
Definition: timer.hh:44
void plug(dynamicgraph::Signal< T, int > &sig)
Definition: timer.hh:80
T & compute(T &t, const int &time)
Definition: timer.hh:85
void cmdChrono(const std::string &cmd, std::istringstream &args, std::ostream &os)