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;