10 #ifndef __SOT_TIMER_HH
11 #define __SOT_TIMER_HH
24 #include <dynamic-graph/linear-algebra.h>
30 #include <dynamic-graph/all-signals.h>
31 #include <dynamic-graph/entity.h>
40 #if defined(timer_EXPORTS)
41 #define Timer_EXPORT __declspec(dllexport)
43 #define Timer_EXPORT __declspec(dllimport)
57 virtual const std::string &
getClassName(
void)
const {
return CLASS_NAME; }
60 struct timeval t0, t1;
66 Timer(
const std::string &name);
69 virtual void display(std::ostream &os)
const;
77 dynamicgraph::SignalPtr<T, int>
sigSIN;
78 dynamicgraph::SignalTimeDependent<T, int>
sigSOUT;
83 void plug(dynamicgraph::Signal<T, int> &sig) {
88 template <
bool UseClock>
93 sotDEBUG(15) <<
"t0: " << c0 << std::endl;
95 gettimeofday(&t0, NULL);
96 sotDEBUG(15) <<
"t0: " << t0.tv_sec <<
" - " << t0.tv_usec << std::endl;
103 sotDEBUG(15) <<
"t1: " << c0 << std::endl;
104 dt = ((double)(c1 - c0) * 1000) / CLOCKS_PER_SEC;
106 gettimeofday(&t1, NULL);
107 dt = ((
static_cast<double>(t1.tv_sec) -
static_cast<double>(t0.tv_sec)) *
109 (
static_cast<double>(t1.tv_usec) -
static_cast<double>(t0.tv_usec) +
112 sotDEBUG(15) <<
"t1: " << t1.tv_sec <<
" - " << t1.tv_usec << std::endl;
116 timerSOUT.setTime(time);
122 double &
getDt(
double &res,
const int & ) {
128 void cmdChrono(
const std::string &cmd, std::istringstream &args,
140 sigSIN(NULL,
"Timer(" + name +
")::input(T)::sin"),
141 sigSOUT(boost::bind(&
Timer::compute<false>, this, _1, _2), sigSIN,
142 "Timer(" + name +
")::output(T)::sout"),
143 sigClockSOUT(boost::bind(&
Timer::compute<true>, this, _1, _2), sigSIN,
144 "Timer(" + name +
")::output(T)::clockSout"),
145 timerSOUT(
"Timer(" + name +
")::output(double)::timer") {
156 os <<
"Timer <" << sigSIN <<
"> : " << dt <<
"ms." << std::endl;
clock_t c0
Definition: timer.hh:61
dynamicgraph::SignalPtr< T, int > sigSIN
Definition: timer.hh:77
dynamicgraph::SignalTimeDependent< T, int > sigClockSOUT
Definition: timer.hh:79
T & compute(T &t, const int &time)
Definition: timer.hh:89
Timer(const std::string &name)
Definition: timer.hh:137
virtual void display(std::ostream &os) const
Definition: timer.hh:155
void plug(dynamicgraph::Signal< T, int > &sig)
Definition: timer.hh:83
dynamicgraph::Signal< double, int > timerSOUT
Definition: timer.hh:80
virtual const std::string & getClassName(void) const
Definition: timer.hh:57
dynamicgraph::SignalTimeDependent< T, int > sigSOUT
Definition: timer.hh:78
static const std::string CLASS_NAME
Definition: timer.hh:56
Timer_EXPORT friend std::ostream & operator<<(std::ostream &os, const Timer< T > &timer)
Definition: timer.hh:70
double dt
Definition: timer.hh:62
double & getDt(double &res, const int &)
Definition: timer.hh:122
#define sotDEBUGOUT(level)
Definition: debug.hh:212
#define sotDEBUGIN(level)
Definition: debug.hh:211
#define sotDEBUG(level)
Definition: debug.hh:165
#define Timer_EXPORT
Definition: timer.hh:46
void cmdChrono(const std::string &cmd, std::istringstream &args, std::ostream &os)