SkePU(integratedwithStarPU)  0.8.1
 All Classes Namespaces Files Functions 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 
43  void addMultiMaxTime() // used to estimate when using multi-Backend
44  {
45  double max = 0.0f;
46  //std::cout<<"AddMultiMaxTime call before"<<time.size()<<"\n";
47  if(multi_time.empty())
48  return;
49  for(std::vector<double>::iterator it = multi_time.begin(); it != multi_time.end(); ++it)
50  {
51  if (max < *it)
52  max = *it;
53  }
54  time.push_back( max );
55  //std::cout<<"MAXXX:"<<max<<" ";
56 
57  multi_time.clear(); // clear it in both cases.
58  //std::cout<<"AddMultiMaxTime call after reset"<<time.size()<<"\n";
59  }
60 
61  void addMultiMinTime() // used to estimate when using multi-Backend
62  {
63  double min = 0.0f;
64  if(multi_time.empty())
65  return;
66  for(std::vector<double>::iterator it = multi_time.begin(); it != multi_time.end(); ++it)
67  {
68  if (min > *it)
69  min = *it;
70  }
71  time.push_back( min );
72 
73  multi_time.clear(); // clear it in both cases.
74  }
75 
76 public:
77 
78 
79  void start_record_multi()
80  {
81  record_multi=true;
82  multi_time.clear(); // clear it in both cases.
83  }
84 
85  void stop_record_multi()
86  {
87  addMultiMaxTime();
88  record_multi=false;
89  }
90 
91  TimerLinux_GTOD() {record_multi=false;}
92 
96  void start()
97  {
98  gettimeofday(&timerStart, NULL);
99  //std::cout<<"start_\n";
100  }
101 
105  void stop()
106  {
107  gettimeofday(&timerEnd, NULL);
108  if(record_multi)
109  multi_time.push_back( (timerEnd.tv_sec - timerStart.tv_sec + (timerEnd.tv_usec - timerStart.tv_usec) / 1000000.0) * 1000 );
110  else
111  time.push_back( (timerEnd.tv_sec - timerStart.tv_sec + (timerEnd.tv_usec - timerStart.tv_usec) / 1000000.0) * 1000 );
112  //std::cout<<"stop_\n";
113  }
114 
118  void reset()
119  {
120  if(!record_multi)
121  {
122 // std::cout<<"Time reset:\n";
123  time.clear();
124  }
125 
126  multi_time.clear(); // clear it in both cases.
127 
128  }
129 
130 
131 
132 
138  double getTime(int run = 0)
139  {
140  return time.at(run);
141  }
142 
146  double getTotalTime()
147  {
148  double totalTime = 0.0f;
149 
150  for(std::vector<double>::iterator it = time.begin(); it != time.end(); ++it)
151  {
152  totalTime += *it;
153  }
154 
155  return totalTime;
156  }
157 
161  double getAverageTime()
162  {
163  double totalTime = 0.0f;
164 
165  for(std::vector<double>::iterator it = time.begin(); it != time.end(); ++it)
166  {
167  totalTime += *it;
168  }
169 
170  return (double)(totalTime/time.size());
171  }
172 
173  double getMaxTime()
174  {
175  double max = 0.0f;
176  for(std::vector<double>::iterator it = time.begin(); it != time.end(); ++it)
177  {
178  if (max < *it)
179  max = *it;
180  }
181  return max;
182  }
183 
184  double getMinTime()
185  {
186  double min = 0.0f;
187  for(std::vector<double>::iterator it = time.begin(); it != time.end(); ++it)
188  {
189  if (min > *it)
190  min = *it;
191  }
192 
193  return min;
194  }
195 
200  {
201  double result = 0.0f;
202  timeval tStart;
203  timeval tEnd;
204  gettimeofday(&tStart, NULL);
205  gettimeofday(&tEnd, NULL);
206  int delay = 0;
207 
208  do
209  {
210  delay++;
211  gettimeofday(&tStart, NULL);
212  for(int i = 0; i < delay; ++i) ;
213  gettimeofday(&tEnd, NULL);
214 
215  result = ((((double)tEnd.tv_sec)*1000000.0) + ((double)tEnd.tv_usec)) - ((((double)tStart.tv_sec)*1000000.0) + ((double)tStart.tv_usec));
216 
217  } while(result == 0);
218 
219  return result;
220  }
221 
226  {
227  return time.size();
228  }
229 };
230 
231 }
232 
233 #endif
234 
double getResolutionUs()
Definition: timer_linux.h:199
void reset()
Definition: timer_linux.h:118
double getTotalTime()
Definition: timer_linux.h:146
int getNumTimings()
Definition: timer_linux.h:225
double getTime(int run=0)
Definition: timer_linux.h:138
double getAverageTime()
Definition: timer_linux.h:161
void stop()
Definition: timer_linux.h:105
A class that can be used measure time on Linux systems.
Definition: timer_linux.h:29
void start()
Definition: timer_linux.h:96