rev |
line source |
nuclear@1
|
1 /************************************************************************************
|
nuclear@1
|
2
|
nuclear@1
|
3 PublicHeader: OVR
|
nuclear@1
|
4 Filename : OVR_Timer.h
|
nuclear@1
|
5 Content : Provides static functions for precise timing
|
nuclear@1
|
6 Created : September 19, 2012
|
nuclear@1
|
7 Notes :
|
nuclear@1
|
8
|
nuclear@1
|
9 Copyright : Copyright 2012 Oculus VR, Inc. All Rights reserved.
|
nuclear@1
|
10
|
nuclear@1
|
11 Use of this software is subject to the terms of the Oculus license
|
nuclear@1
|
12 agreement provided at the time of installation or download, or which
|
nuclear@1
|
13 otherwise accompanies this software in either electronic or hard copy form.
|
nuclear@1
|
14
|
nuclear@1
|
15 ************************************************************************************/
|
nuclear@1
|
16
|
nuclear@1
|
17 #ifndef OVR_Timer_h
|
nuclear@1
|
18 #define OVR_Timer_h
|
nuclear@1
|
19
|
nuclear@1
|
20 #include "OVR_Types.h"
|
nuclear@1
|
21
|
nuclear@1
|
22 namespace OVR {
|
nuclear@1
|
23
|
nuclear@1
|
24 //-----------------------------------------------------------------------------------
|
nuclear@1
|
25 // ***** Timer
|
nuclear@1
|
26
|
nuclear@1
|
27 // Timer class defines a family of static functions used for application
|
nuclear@1
|
28 // timing and profiling.
|
nuclear@1
|
29
|
nuclear@1
|
30 class Timer
|
nuclear@1
|
31 {
|
nuclear@1
|
32 public:
|
nuclear@1
|
33 enum {
|
nuclear@1
|
34 MsPerSecond = 1000, // Milliseconds in one second.
|
nuclear@1
|
35 MksPerMs = 1000, // Microseconds in one millisecond.
|
nuclear@1
|
36 MksPerSecond = MsPerSecond * MksPerMs
|
nuclear@1
|
37 };
|
nuclear@1
|
38
|
nuclear@1
|
39
|
nuclear@1
|
40 // ***** Timing APIs for Application
|
nuclear@1
|
41 // These APIs should be used to guide animation and other program functions
|
nuclear@1
|
42 // that require precision.
|
nuclear@1
|
43
|
nuclear@1
|
44 // Returns ticks in milliseconds, as a 32-bit number. May wrap around every
|
nuclear@1
|
45 // 49.2 days. Use either time difference of two values of GetTicks to avoid
|
nuclear@1
|
46 // wrap-around. GetTicksMs may perform better then GetTicks.
|
nuclear@1
|
47 static UInt32 OVR_STDCALL GetTicksMs();
|
nuclear@1
|
48
|
nuclear@1
|
49 // GetTicks returns general-purpose high resolution application timer value,
|
nuclear@1
|
50 // measured in microseconds (mks, or 1/1000000 of a second). The actual precision
|
nuclear@1
|
51 // is system-specific and may be much lower, such as 1 ms.
|
nuclear@1
|
52 static UInt64 OVR_STDCALL GetTicks();
|
nuclear@1
|
53
|
nuclear@1
|
54
|
nuclear@1
|
55 // ***** Profiling APIs.
|
nuclear@1
|
56 // These functions should be used for profiling, but may have system specific
|
nuclear@1
|
57 // artifacts that make them less appropriate for general system use.
|
nuclear@1
|
58 // On Win32, for example these rely on QueryPerformanceConter may have
|
nuclear@1
|
59 // problems with thread-core switching and power modes.
|
nuclear@1
|
60
|
nuclear@1
|
61 // Return a hi-res timer value in mks (1/1000000 of a sec).
|
nuclear@1
|
62 // Generally you want to call this at the start and end of an
|
nuclear@1
|
63 // operation, and pass the difference to
|
nuclear@1
|
64 // TicksToSeconds() to find out how long the operation took.
|
nuclear@1
|
65 static UInt64 OVR_STDCALL GetProfileTicks();
|
nuclear@1
|
66
|
nuclear@1
|
67 // More convenient zero-based profile timer in seconds. First call initializes
|
nuclear@1
|
68 // the "zero" value; future calls return the difference. Not thread safe for first call.
|
nuclear@1
|
69 // Due to low precision of Double, may malfunction after long runtime.
|
nuclear@1
|
70 static double OVR_STDCALL GetProfileSeconds();
|
nuclear@1
|
71
|
nuclear@1
|
72 // Get the raw cycle counter value, providing the maximum possible timer resolution.
|
nuclear@1
|
73 static UInt64 OVR_STDCALL GetRawTicks();
|
nuclear@1
|
74 static UInt64 OVR_STDCALL GetRawFrequency();
|
nuclear@1
|
75
|
nuclear@1
|
76
|
nuclear@1
|
77 // ***** Tick and time unit conversion.
|
nuclear@1
|
78
|
nuclear@1
|
79 // Convert micro-second ticks value into seconds value.
|
nuclear@1
|
80 static inline double TicksToSeconds(UInt64 ticks)
|
nuclear@1
|
81 {
|
nuclear@1
|
82 return static_cast<double>(ticks) * (1.0 / (double)MksPerSecond);
|
nuclear@1
|
83 }
|
nuclear@1
|
84 // Convert Raw or frequency-unit ticks to seconds based on specified frequency.
|
nuclear@1
|
85 static inline double RawTicksToSeconds(UInt64 rawTicks, UInt64 rawFrequency)
|
nuclear@1
|
86 {
|
nuclear@1
|
87 return static_cast<double>(rawTicks) * rawFrequency;
|
nuclear@1
|
88 }
|
nuclear@1
|
89
|
nuclear@1
|
90 private:
|
nuclear@1
|
91 friend class System;
|
nuclear@1
|
92 // System called during program startup/shutdown.
|
nuclear@1
|
93 static void initializeTimerSystem();
|
nuclear@1
|
94 static void shutdownTimerSystem();
|
nuclear@1
|
95 };
|
nuclear@1
|
96
|
nuclear@1
|
97
|
nuclear@1
|
98 } // Scaleform::Timer
|
nuclear@1
|
99
|
nuclear@1
|
100 #endif
|