rev |
line source |
nuclear@0
|
1 /************************************************************************************
|
nuclear@0
|
2
|
nuclear@0
|
3 Filename : CAPI_LatencyStatistics.h
|
nuclear@0
|
4 Content : Record latency statistics during rendering
|
nuclear@0
|
5 Created : Sept 23, 2014
|
nuclear@0
|
6 Authors : Chris Taylor, Kevin Jenkins
|
nuclear@0
|
7
|
nuclear@0
|
8 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
|
nuclear@0
|
9
|
nuclear@0
|
10 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
|
nuclear@0
|
11 you may not use the Oculus VR Rift SDK except in compliance with the License,
|
nuclear@0
|
12 which is provided at the time of installation or download, or which
|
nuclear@0
|
13 otherwise accompanies this software in either electronic or hard copy form.
|
nuclear@0
|
14
|
nuclear@0
|
15 You may obtain a copy of the License at
|
nuclear@0
|
16
|
nuclear@0
|
17 http://www.oculusvr.com/licenses/LICENSE-3.2
|
nuclear@0
|
18
|
nuclear@0
|
19 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
|
nuclear@0
|
20 distributed under the License is distributed on an "AS IS" BASIS,
|
nuclear@0
|
21 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
nuclear@0
|
22 See the License for the specific language governing permissions and
|
nuclear@0
|
23 limitations under the License.
|
nuclear@0
|
24
|
nuclear@0
|
25 ************************************************************************************/
|
nuclear@0
|
26
|
nuclear@0
|
27 #ifndef OVR_CAPI_LatencyStatistics_h
|
nuclear@0
|
28 #define OVR_CAPI_LatencyStatistics_h
|
nuclear@0
|
29
|
nuclear@0
|
30 #include "../OVR_CAPI.h"
|
nuclear@0
|
31 #include "../Kernel/OVR_Timer.h"
|
nuclear@0
|
32 #include "../Kernel/OVR_Lockless.h"
|
nuclear@0
|
33 #include "../Kernel/OVR_SysFile.h"
|
nuclear@0
|
34 #include "CAPI_FrameTimeManager.h"
|
nuclear@0
|
35
|
nuclear@0
|
36 namespace OVR { namespace CAPI {
|
nuclear@0
|
37
|
nuclear@0
|
38
|
nuclear@0
|
39 // Define epoch period for lag statistics
|
nuclear@0
|
40 #define OVR_LAG_STATS_EPOCH 1.0 /* seconds */
|
nuclear@0
|
41 // Define seconds without frames before resetting stats
|
nuclear@0
|
42 #define OVR_LAG_STATS_RESET_LIMIT 2.0 /* seconds */
|
nuclear@0
|
43
|
nuclear@0
|
44
|
nuclear@0
|
45 //-------------------------------------------------------------------------------------
|
nuclear@0
|
46 // ***** LatencyStatisticsResults
|
nuclear@0
|
47
|
nuclear@0
|
48 // Results from statistics collection
|
nuclear@0
|
49 struct LatencyStatisticsResults
|
nuclear@0
|
50 {
|
nuclear@0
|
51 // Number of seconds of data represented by these statistics.
|
nuclear@0
|
52 double IntervalSeconds;
|
nuclear@0
|
53
|
nuclear@0
|
54 // Frames per second during the epoch.
|
nuclear@0
|
55 double FPS;
|
nuclear@0
|
56
|
nuclear@0
|
57 // Measures average time for EndFrame() call over each of the frames.
|
nuclear@0
|
58 double EndFrameExecutionTime;
|
nuclear@0
|
59
|
nuclear@0
|
60 // Measures the time between first scanline and first pose request before app starts rendering eyes.
|
nuclear@0
|
61 float LatencyRender;
|
nuclear@0
|
62
|
nuclear@0
|
63 // Measures the time between first scanline and distortion/timewarp rendering.
|
nuclear@0
|
64 float LatencyTimewarp;
|
nuclear@0
|
65
|
nuclear@0
|
66 // Time between Present() call and photon emission from first scanline of screen
|
nuclear@0
|
67 float LatencyPostPresent;
|
nuclear@0
|
68
|
nuclear@0
|
69 // Measures the time from receiving the camera frame until vision CPU processing completes.
|
nuclear@0
|
70 double LatencyVisionProc;
|
nuclear@0
|
71
|
nuclear@0
|
72 // Measures the time from exposure until the pose is available for the frame, including processing time.
|
nuclear@0
|
73 double LatencyVisionFrame;
|
nuclear@0
|
74 };
|
nuclear@0
|
75
|
nuclear@0
|
76 //-----------------------------------------------------------------------------
|
nuclear@0
|
77 typedef Delegate1<void, LatencyStatisticsResults*> LatencyStatisticsSlot;
|
nuclear@0
|
78
|
nuclear@0
|
79 // ***** LatencyStatisticsObserver
|
nuclear@0
|
80 class LatencyStatisticsCSV
|
nuclear@0
|
81 {
|
nuclear@0
|
82 public:
|
nuclear@0
|
83 LatencyStatisticsCSV();
|
nuclear@0
|
84 ~LatencyStatisticsCSV();
|
nuclear@0
|
85 bool Start(String fileName, String userData1);
|
nuclear@0
|
86 bool Stop();
|
nuclear@0
|
87 void OnResults(LatencyStatisticsResults *results);
|
nuclear@0
|
88
|
nuclear@0
|
89 // Internal
|
nuclear@0
|
90 void WriteHeaderV1();
|
nuclear@0
|
91 void WriteResultsV1(LatencyStatisticsResults *results);
|
nuclear@0
|
92 ObserverScope<LatencyStatisticsSlot>* GetObserver() { return &_Observer; }
|
nuclear@0
|
93
|
nuclear@0
|
94 protected:
|
nuclear@0
|
95 ObserverScope<LatencyStatisticsSlot> _Observer;
|
nuclear@0
|
96 String Guid, UserData1;
|
nuclear@0
|
97 String FileName;
|
nuclear@0
|
98 OVR::SysFile _File;
|
nuclear@0
|
99 String OS, OSVersion, ProcessInfo, DisplayDriverVersion, CameraDriverVersion, GPUVersion;
|
nuclear@0
|
100 };
|
nuclear@0
|
101
|
nuclear@0
|
102 //-----------------------------------------------------------------------------
|
nuclear@0
|
103 // ***** LatencyStatisticsCalculator
|
nuclear@0
|
104
|
nuclear@0
|
105 // Calculator for latency statistics
|
nuclear@0
|
106 class LagStatsCalculator
|
nuclear@0
|
107 {
|
nuclear@0
|
108 // Statistics instrumentation inputs:
|
nuclear@0
|
109
|
nuclear@0
|
110 // Timestamp when the EndFrame() call started executing
|
nuclear@0
|
111 double EndFrameStartTime;
|
nuclear@0
|
112 // Timestamp when the EndFrame() call finished executing
|
nuclear@0
|
113 double EndFrameEndTime;
|
nuclear@0
|
114
|
nuclear@0
|
115 // Latency statistics for the epoch
|
nuclear@0
|
116 LatencyStatisticsResults latencyStatisticsData;
|
nuclear@0
|
117
|
nuclear@0
|
118 // Last latency data
|
nuclear@0
|
119 // float LatencyData[3]; // render, timewarp, median post-present
|
nuclear@0
|
120
|
nuclear@0
|
121 // Last vision processing frame counter number
|
nuclear@0
|
122 uint32_t LastCameraFrameCounter;
|
nuclear@0
|
123
|
nuclear@0
|
124 // Running statistics:
|
nuclear@0
|
125
|
nuclear@0
|
126 void resetPerfStats(double resetTime = 0.);
|
nuclear@0
|
127
|
nuclear@0
|
128 // Start of the current statistics epoch
|
nuclear@0
|
129 double EpochBegin;
|
nuclear@0
|
130 // Count of frames in this stats epoch, measured at EndFrame()
|
nuclear@0
|
131 int FrameCount;
|
nuclear@0
|
132 // Sum of end frame durations for this stats epoch
|
nuclear@0
|
133 //double EndFrameSum;
|
nuclear@0
|
134
|
nuclear@0
|
135 // Sum of latencies
|
nuclear@0
|
136 // double LatencySum[3];
|
nuclear@0
|
137
|
nuclear@0
|
138 // Sum of vision processing times
|
nuclear@0
|
139 //double VisionProcSum;
|
nuclear@0
|
140 // Sum of vision latency times
|
nuclear@0
|
141 //double VisionLagSum;
|
nuclear@0
|
142 // Count of vision frames
|
nuclear@0
|
143 int VisionFrames;
|
nuclear@0
|
144
|
nuclear@0
|
145 // Statistics results:
|
nuclear@0
|
146
|
nuclear@0
|
147 LocklessUpdater<LatencyStatisticsResults, LatencyStatisticsResults> Results;
|
nuclear@0
|
148
|
nuclear@0
|
149 void calculateResults();
|
nuclear@0
|
150
|
nuclear@0
|
151 OVR::ObserverScope<LatencyStatisticsSlot> calculateResultsSubject;
|
nuclear@0
|
152 OVR::Lock calculateResultsLock;
|
nuclear@0
|
153
|
nuclear@0
|
154 public:
|
nuclear@0
|
155 LagStatsCalculator();
|
nuclear@0
|
156
|
nuclear@0
|
157 void GetLatestResults(LatencyStatisticsResults* results);
|
nuclear@0
|
158 void AddResultsObserver(ObserverScope<LatencyStatisticsSlot> *calculateResultsObserver);
|
nuclear@0
|
159
|
nuclear@0
|
160 public:
|
nuclear@0
|
161 // Internal instrumentation interface:
|
nuclear@0
|
162
|
nuclear@0
|
163 // EndFrame() instrumentation
|
nuclear@0
|
164 void InstrumentEndFrameStart(double timestamp);
|
nuclear@0
|
165 void InstrumentEndFrameEnd(double timestamp);
|
nuclear@0
|
166
|
nuclear@0
|
167 // DK2 latency tester instrumentation
|
nuclear@0
|
168 // Note: This assumes that it is called right before InstrumentEndFrameEnd()
|
nuclear@0
|
169 void InstrumentLatencyTimings(FrameTimeManager& ftm);
|
nuclear@0
|
170
|
nuclear@0
|
171 // Eye pose instrumentation
|
nuclear@0
|
172 void InstrumentEyePose(const ovrTrackingState& state);
|
nuclear@0
|
173 };
|
nuclear@0
|
174
|
nuclear@0
|
175
|
nuclear@0
|
176 }} // namespace OVR::CAPI
|
nuclear@0
|
177
|
nuclear@0
|
178 #endif // OVR_CAPI_LatencyStatistics_h
|