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;