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;