TimeMeasure.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
20 #include <coil/Time.h>
21 #include <math.h>
22 #include <coil/TimeMeasure.h>
23 
24 //#define RDTSC(X) __asm__ __volatile__ ("rdtsc" : "=A" (X))
25 //#define NSEC_PER_SEC 1000000000
26 
27 #ifndef ULLONG_MAX
28 #define ULLONG_MAX 0xffffffffffffffffULL
29 #endif
30 
31 namespace coil
32 {
33 
42  : m_begin(0.0), m_interval(0.0),
43  m_count(0), m_countMax(buflen + 1),
44  m_recurred(false)
45  {
46  m_record.reserve(m_countMax);
47  for (unsigned long i(0); i < m_countMax; ++i)
48  {
49  m_record.push_back(TimeValue(0, 0));
50  }
51  }
52 
61  {
62  m_begin = gettimeofday(); // [TimeValue]
63  }
64 
73  {
74  if (m_begin.sec() == 0) { return; }
75 
78  ++m_count;
79  if (m_count == m_countMax)
80  {
81  m_count = 0;
82  m_recurred = true;
83  }
84  }
85 
94  {
95  return m_interval;
96  }
97 
106  {
107  m_count = 0;
108  m_recurred = false;
109  m_begin = 0.0;
110  }
111 
119  unsigned long int TimeMeasure::count() const
120  {
121  return m_recurred ? m_record.size() : m_count;
122  }
123 
131  bool TimeMeasure::getStatistics(double &max_interval,
132  double &min_interval,
133  double &mean_interval,
134  double &stddev)
135  {
136  max_interval = (double)0;
137  min_interval = (double)ULLONG_MAX;
138 
139  double sum = 0;
140  double sq_sum = 0;
141  unsigned long int len(count());
142 
143  if (len == 0) return false;
144 
145  for (unsigned long int i(0); i < len; ++i)
146  {
147  double trecord(m_record[i]);
148  sum += trecord;
149  sq_sum += trecord * trecord;
150 
151  if (trecord > max_interval) max_interval = trecord;
152  if (trecord < min_interval) min_interval = trecord;
153  }
154 
155  mean_interval = sum / len;
156  stddev = sqrt(sq_sum / len - (mean_interval * mean_interval));
157 
158  return true;
159  }
160 
169  {
170  Statistics s;
173  return s;
174  }
175 
176 }; // namespace coil
#define ULLONG_MAX
Definition: TimeMeasure.cpp:28
Structure for time statistics.
Definition: TimeMeasure.h:63
coil::TimeValue & interval()
Get a interval time.
Definition: TimeMeasure.cpp:93
Statistics getStatistics()
Get statistics result.
TimeValue class.
Definition: TimeValue.h:40
void tack()
Finish time measurement for time statistics.
Definition: TimeMeasure.cpp:72
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get the time and timezone.
Definition: ace/coil/Time.h:57
const unsigned long int m_countMax
Definition: TimeMeasure.h:242
coil::TimeValue m_interval
Definition: TimeMeasure.h:239
void reset()
Initialize for statistics related data.
unsigned long int m_count
Definition: TimeMeasure.h:241
long int sec() const
Get value of second time scale.
Definition: TimeValue.h:110
unsigned long int count() const
Get number of time measurement buffer.
void tick()
Begin time measurement for time statistics.
Definition: TimeMeasure.cpp:60
TimeMeasure(int buflen=100)
Constructor.
Definition: TimeMeasure.cpp:41
coil::TimeValue m_begin
Definition: TimeMeasure.h:238
std::vector< coil::TimeValue > m_record
Definition: TimeMeasure.h:237
Common Object Interface Layer.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:45