ocra-recipes
Doxygen documentation for the ocra-recipes repository
wocra/include/wocra/Performances.h
Go to the documentation of this file.
1 
8 #ifndef __PERFORMANCES_H__
9 #define __PERFORMANCES_H__
10 
11 #include <sys/time.h>
12 
13 #include <list>
14 
15 #include <iostream>
16 
17 namespace wocra
18 {
19 
66 {
67 public:
68 
73 
77  virtual ~PerformanceRecorder() {};
78 
83  double getCurrentTime() {
84  gettimeofday(&tim, NULL);
85  return tim.tv_sec+(tim.tv_usec/1000000.0);
86  };
87 
92  void initializeTime() {
94  };
95 
101  double t = getCurrentTime();
102  _record.push_back( t - _initTime );
103  };
104 
108  double getRelativeTime() {
109  return getCurrentTime() - _initTime;
110  };
111 
112  void saveTime(double t)
113  {
114  _record.push_back( t );
115  }
116 
120  const std::list< double >& getSavedTime() const {
121  return _record;
122  }
123 
130  void writeInStream(const std::string& headerName, std::ostream& outstream, bool addCommaAtEnd) {
131  outstream << "\"" <<headerName << "\": [";
132 
133  std::list< double >::const_iterator it_1 = --_record.end();
134  for (std::list< double >::const_iterator it = _record.begin(); it != _record.end(); ++it)
135  {
136  outstream << *it;
137  if ( it != it_1)
138  outstream << ", ";
139  }
140  if (addCommaAtEnd == true)
141  outstream << "],\n";
142  else
143  outstream << "]\n";
144  }
145 
146 protected:
147  timeval tim;
148 
149  double _initTime;
150 
151  std::list< double > _record;
152 };
153 
154  // end group core
156 
157 
158 }
159 
160 #endif
Contains all the abstract & concrete classes for robotic control with optimization, based on the ocra framework.
const std::list< double > & getSavedTime() const
void writeInStream(const std::string &headerName, std::ostream &outstream, bool addCommaAtEnd)
To get and save time information to collect some data on performances.