edits
[iotcloud.git] / version2 / src / C / TimingSingleton.h
1 #ifndef TIMINGSINGLETON_H
2 #define TIMINGSINGLETON_H
3 #include <sys/time.h>
4
5 class TimingSingleton {
6  private:
7         static TimingSingleton singleton = new TimingSingleton( );
8         int64_t startTime = 0;
9         int64_t totalTime = 0;
10         
11  TimingSingleton() : startTime(0),
12                 totalTime(0) {
13         }
14
15         int64_t nanoTime() {
16                 int64_t time;
17                 struct timeval tv;
18                 gettimeofday(&tv, NULL);
19                 return tv.tv_sec*1000000000+tv.tv_usec*1000;
20         }
21         
22  public:
23         void startTime() {
24                 startTime = nanoTime();
25         }
26         
27         void endTime() {
28                 totalTime += nanoTime() - startTime;
29         }
30
31         int64_t getTime() {
32                 return totalTime;
33         }
34 };
35
36 TimingSingleton t_singleton;
37 TimingSingleton * TimingSingleton_getInstance() {
38         return &t_singleton;
39 }
40 #endif