SkePU  1.2
 All Classes Namespaces Files Functions Variables Enumerations Friends Macros Groups Pages
timer_linux.h
Go to the documentation of this file.
1 
5 #ifndef TIMER_LINUX_H
6 #define TIMER_LINUX_H
7 
8 #include <sys/time.h>
9 #include <iostream>
10 #include <vector>
11 
12 namespace skepu
13 {
14 
30 {
31 
32 private:
33  timeval timerStart;
34  timeval timerEnd;
35 
36 
37 
38  std::vector<double> multi_time; // used for estimating multi backends.
39  std::vector<double> time;
40  bool record_multi;
41 
42 
46  void addMultiMaxTime()
47  {
48  double max = 0.0f;
49  if(multi_time.empty())
50  return;
51  for(std::vector<double>::iterator it = multi_time.begin(); it != multi_time.end(); ++it)
52  {
53  if (max < *it)
54  max = *it;
55  }
56  time.push_back( max );
57  multi_time.clear(); // clear it in both cases.
58  }
59 
63  void addMultiMinTime()
64  {
65  double min = 0.0f;
66  if(multi_time.empty())
67  return;
68  for(std::vector<double>::iterator it = multi_time.begin(); it != multi_time.end(); ++it)
69  {
70  if (min > *it)
71  min = *it;
72  }
73  time.push_back( min );
74  multi_time.clear(); // clear it in both cases.
75  }
76 
77 public:
78 
83  {
84  record_multi=true;
85  multi_time.clear(); // clear it in both cases.
86  }
87 
88 
93  {
94  addMultiMaxTime();
95  record_multi=false;
96  }
97 
99  {
100  record_multi=false;
101  }
102 
106  void start()
107  {
108  gettimeofday(&timerStart, NULL);
109  }
110 
114  void stop()
115  {
116  gettimeofday(&timerEnd, NULL);
117  if(record_multi)
118  multi_time.push_back( (((timerEnd.tv_sec - timerStart.tv_sec) * 1000000u + timerEnd.tv_usec - timerStart.tv_usec) / 1.e6) * 1000 );
119  else
120  time.push_back( (((timerEnd.tv_sec - timerStart.tv_sec) * 1000000u + timerEnd.tv_usec - timerStart.tv_usec) / 1.e6) * 1000 );
121  }
122 
126  void reset()
127  {
128  if(!record_multi)
129  {
130  time.clear();
131  }
132  multi_time.clear(); // clear it in both cases.
133  }
134 
135 
136 
137 
143  double getTime(int run = 0)
144  {
145  return time.at(run);
146  }
147 
151  double getTotalTime()
152  {
153  double totalTime = 0.0f;
154 
155  for(std::vector<double>::iterator it = time.begin(); it != time.end(); ++it)
156  {
157  totalTime += *it;
158  }
159 
160  return totalTime;
161  }
162 
166  double getAverageTime()
167  {
168  double totalTime = 0.0f;
169 
170  for(std::vector<double>::iterator it = time.begin(); it != time.end(); ++it)
171  {
172  totalTime += *it;
173  }
174 
175  return (double)(totalTime/time.size());
176  }
177 
181  double getMaxTime()
182  {
183  double max = 0.0f;
184  for(std::vector<double>::iterator it = time.begin(); it != time.end(); ++it)
185  {
186  if (max < *it)
187  max = *it;
188  }
189  return max;
190  }
191 
192 
196  double getMinTime()
197  {
198  double min = 0.0f;
199  for(std::vector<double>::iterator it = time.begin(); it != time.end(); ++it)
200  {
201  if (min > *it)
202  min = *it;
203  }
204 
205  return min;
206  }
207 
212  {
213  double result = 0.0f;
214  timeval tStart;
215  timeval tEnd;
216  gettimeofday(&tStart, NULL);
217  gettimeofday(&tEnd, NULL);
218  int delay = 0;
219 
220  do
221  {
222  delay++;
223  gettimeofday(&tStart, NULL);
224  for(int i = 0; i < delay; ++i) ;
225  gettimeofday(&tEnd, NULL);
226 
227  result = ((((double)tEnd.tv_sec)*1000000.0) + ((double)tEnd.tv_usec)) - ((((double)tStart.tv_sec)*1000000.0) + ((double)tStart.tv_usec));
228 
229  }
230  while(result == 0);
231 
232  return result;
233  }
234 
239  {
240  return time.size();
241  }
242 };
243 
244 }
245 
246 #endif
247 
double getResolutionUs()
Definition: timer_linux.h:211
void reset()
Definition: timer_linux.h:126
double getMinTime()
Definition: timer_linux.h:196
double getTotalTime()
Definition: timer_linux.h:151
double getMaxTime()
Definition: timer_linux.h:181
T min(T a, T b)
Definition: mapoverlap_convol_kernels.h:212
int getNumTimings()
Definition: timer_linux.h:238
void start_record_multi()
Definition: timer_linux.h:82
void stop_record_multi()
Definition: timer_linux.h:92
double getTime(int run=0)
Definition: timer_linux.h:143
double getAverageTime()
Definition: timer_linux.h:166
T max(T a, T b)
Definition: mapoverlap_convol_kernels.h:203
void stop()
Definition: timer_linux.h:114
A class that can be used measure time on Linux systems.
Definition: timer_linux.h:29
void start()
Definition: timer_linux.h:106