Project
Loading...
Searching...
No Matches
timer.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#include "timer.h"
16#ifdef _WIN32
17#include <windows.h>
18#include <winbase.h>
19#elif defined(__MACH__) || defined(__APPLE__)
20#include <mach/clock.h>
21#include <mach/mach.h>
22#else
23#include <ctime>
24#endif
25
27{
28 if (start) {
29 ResetStart();
30 }
31}
32
33inline double HighResTimer::GetTime()
34{
35#ifdef _WIN32
36 __int64 istart;
37 QueryPerformanceCounter((LARGE_INTEGER*)&istart);
38 return ((double)istart);
39#elif defined(__MACH__) || defined(__APPLE__)
40 clock_serv_t cclock;
41 mach_timespec_t mts;
42 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
43 clock_get_time(cclock, &mts);
44 mach_port_deallocate(mach_task_self(), cclock);
45 return ((double)mts.tv_sec * 1.0e9 + (double)mts.tv_nsec);
46#else
47 timespec tv;
48 clock_gettime(CLOCK_REALTIME, &tv);
49 return ((double)tv.tv_sec * 1.0e9 + (double)tv.tv_nsec);
50#endif
51}
52
53inline double HighResTimer::GetFrequency()
54{
55#ifdef _WIN32
56 __int64 ifreq;
57 QueryPerformanceFrequency((LARGE_INTEGER*)&ifreq);
58 return ((double)ifreq);
59#else
60 return (1.0e9);
61#endif
62}
63
65{
66 StartTime = GetTime();
67 running = 1;
68}
69
71{
72 ElapsedTime = 0;
73 Start();
74}
75
77{
78 if (running == 0) {
79 return;
80 }
81 running = 0;
82 double EndTime = 0;
83 EndTime = GetTime();
84 ElapsedTime += EndTime - StartTime;
85 StartTime = 0;
86}
87
89{
90 StartTime = 0.;
91 running = 0;
92}
93
95{
96 if (running == 0) {
97 return;
98 }
99 running = 0;
100 double EndTime = 0;
101 EndTime = GetTime();
102 ElapsedTime += EndTime - StartTime;
103 StartTime = 0;
104 startTimer.StartTime = EndTime;
105 startTimer.running = 1;
106}
107
109{
110 ElapsedTime = 0;
111 StartTime = 0;
112 running = 0;
113}
114
115double HighResTimer::GetElapsedTime() { return ElapsedTime / Frequency; }
116
118{
119 if (running == 0) {
120 double retVal = GetElapsedTime();
121 if (reset) {
122 Reset();
123 }
124 return (retVal);
125 }
126 double CurrentTime = GetTime();
127 double retVal = (CurrentTime - StartTime + ElapsedTime) / Frequency;
128 if (reset) {
129 ElapsedTime = 0;
130 Start();
131 }
132 return (retVal);
133}
134
135void HighResTimer::AddTime(double t) { ElapsedTime += t * Frequency; }
136
137double HighResTimer::Frequency = HighResTimer::GetFrequency();
int32_t retVal
HighResTimer()=default
void AddTime(double t)
Definition timer.cxx:135
void Reset()
Definition timer.cxx:108
void Start()
Definition timer.cxx:64
double GetCurrentElapsedTime(bool reset=false)
Definition timer.cxx:117
double GetElapsedTime()
Definition timer.cxx:115
void Abort()
Definition timer.cxx:88
void StopAndStart(HighResTimer &startTimer)
Definition timer.cxx:94
void Stop()
Definition timer.cxx:76
void ResetStart()
Definition timer.cxx:70
GLuint start
Definition glcorearb.h:469