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) 55 virtual const std::string &
getClassName(
void)
const {
return CLASS_NAME; }
58 struct timeval t0, t1;
64 Timer(
const std::string &name);
67 virtual void display(std::ostream &os)
const;
81 void plug(dg::Signal<T, int> &sig) {
86 template <
bool UseClock> T &
compute(T &t,
const int &time) {
90 sotDEBUG(15) <<
"t0: " << c0 << std::endl;
92 gettimeofday(&t0, NULL);
93 sotDEBUG(15) <<
"t0: " << t0.tv_sec <<
" - " << t0.tv_usec << std::endl;
100 sotDEBUG(15) <<
"t1: " << c0 << std::endl;
101 dt = ((double)(c1 - c0) * 1000) / CLOCKS_PER_SEC;
103 gettimeofday(&t1, NULL);
104 dt = ((
static_cast<double>(t1.tv_sec) - static_cast<double>(t0.tv_sec)) *
106 (static_cast<double>(t1.tv_usec) -
static_cast<double>(t0.tv_usec) +
109 sotDEBUG(15) <<
"t1: " << t1.tv_sec <<
" - " << t1.tv_usec << std::endl;
113 timerSOUT.setTime(time);
119 double &
getDt(
double &res,
const int & ) {
125 void cmdChrono(
const std::string &cmd, std::istringstream &args,
135 : Entity(name), dt(0.), sigSIN(NULL,
"Timer(" + name +
")::input(T)::sin"),
136 sigSOUT(boost::bind(&
Timer::compute<false>, this, _1, _2), sigSIN,
137 "Timer(" + name +
")::output(T)::sout"),
138 sigClockSOUT(boost::bind(&
Timer::compute<true>, this, _1, _2), sigSIN,
139 "Timer(" + name +
")::output(T)::clockSout"),
140 timerSOUT(
"Timer(" + name +
")::output(double)::timer") {
150 os <<
"Timer <" <<
sigSIN <<
"> : " <<
dt <<
"ms." << std::endl;
dg::SignalTimeDependent< T, int > sigSOUT
Definition: timer.hh:76
double & getDt(double &res, const int &)
Definition: timer.hh:119
#define sotDEBUGOUT(level)
Definition: debug.hh:214
void plug(dg::Signal< T, int > &sig)
Definition: timer.hh:81
static const std::string CLASS_NAME
Definition: timer.hh:54
#define sotDEBUGIN(level)
Definition: debug.hh:213
Timer_EXPORT friend std::ostream & operator<<(std::ostream &os, const Timer< T > &timer)
Definition: timer.hh:68
Timer(const std::string &name)
Definition: timer.hh:134
double dt
Definition: timer.hh:60
dg::Signal< double, int > timerSOUT
Definition: timer.hh:78
clock_t c1
Definition: timer.hh:59
#define sotDEBUG(level)
Definition: debug.hh:167
dg::SignalTimeDependent< T, int > sigClockSOUT
Definition: timer.hh:77
virtual void display(std::ostream &os) const
Definition: timer.hh:149
virtual const std::string & getClassName(void) const
Definition: timer.hh:55
#define Timer_EXPORT
Definition: timer.hh:44
T & compute(T &t, const int &time)
Definition: timer.hh:86
Definition: abstract-sot-external-interface.hh:17
dg::SignalPtr< T, int > sigSIN
Definition: timer.hh:75
void cmdChrono(const std::string &cmd, std::istringstream &args, std::ostream &os)