ovr_sdk

view LibOVR/Src/CAPI/CAPI_LatencyStatistics.h @ 0:1b39a1b46319

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