ovr_sdk

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/LibOVR/Src/CAPI/CAPI_LatencyStatistics.h	Wed Jan 14 06:51:16 2015 +0200
     1.3 @@ -0,0 +1,178 @@
     1.4 +/************************************************************************************
     1.5 +
     1.6 +Filename    :   CAPI_LatencyStatistics.h
     1.7 +Content     :   Record latency statistics during rendering
     1.8 +Created     :   Sept 23, 2014
     1.9 +Authors     :   Chris Taylor, Kevin Jenkins
    1.10 +
    1.11 +Copyright   :   Copyright 2014 Oculus VR, LLC All Rights reserved.
    1.12 +
    1.13 +Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); 
    1.14 +you may not use the Oculus VR Rift SDK except in compliance with the License, 
    1.15 +which is provided at the time of installation or download, or which 
    1.16 +otherwise accompanies this software in either electronic or hard copy form.
    1.17 +
    1.18 +You may obtain a copy of the License at
    1.19 +
    1.20 +http://www.oculusvr.com/licenses/LICENSE-3.2 
    1.21 +
    1.22 +Unless required by applicable law or agreed to in writing, the Oculus VR SDK 
    1.23 +distributed under the License is distributed on an "AS IS" BASIS,
    1.24 +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.25 +See the License for the specific language governing permissions and
    1.26 +limitations under the License.
    1.27 +
    1.28 +************************************************************************************/
    1.29 +
    1.30 +#ifndef OVR_CAPI_LatencyStatistics_h
    1.31 +#define OVR_CAPI_LatencyStatistics_h
    1.32 +
    1.33 +#include "../OVR_CAPI.h"
    1.34 +#include "../Kernel/OVR_Timer.h"
    1.35 +#include "../Kernel/OVR_Lockless.h"
    1.36 +#include "../Kernel/OVR_SysFile.h"
    1.37 +#include "CAPI_FrameTimeManager.h"
    1.38 +
    1.39 +namespace OVR { namespace CAPI {
    1.40 +
    1.41 +
    1.42 +// Define epoch period for lag statistics
    1.43 +#define OVR_LAG_STATS_EPOCH 1.0 /* seconds */
    1.44 +// Define seconds without frames before resetting stats
    1.45 +#define OVR_LAG_STATS_RESET_LIMIT 2.0 /* seconds */
    1.46 +
    1.47 +
    1.48 +//-------------------------------------------------------------------------------------
    1.49 +// ***** LatencyStatisticsResults
    1.50 +
    1.51 +// Results from statistics collection
    1.52 +struct LatencyStatisticsResults
    1.53 +{
    1.54 +    // Number of seconds of data represented by these statistics.
    1.55 +    double IntervalSeconds;
    1.56 +
    1.57 +    // Frames per second during the epoch.
    1.58 +    double FPS;
    1.59 +
    1.60 +    // Measures average time for EndFrame() call over each of the frames.
    1.61 +    double EndFrameExecutionTime;
    1.62 +
    1.63 +    // Measures the time between first scanline and first pose request before app starts rendering eyes.
    1.64 +    float LatencyRender;
    1.65 +
    1.66 +    // Measures the time between first scanline and distortion/timewarp rendering.
    1.67 +    float LatencyTimewarp;
    1.68 +
    1.69 +    // Time between Present() call and photon emission from first scanline of screen
    1.70 +    float LatencyPostPresent;
    1.71 +
    1.72 +    // Measures the time from receiving the camera frame until vision CPU processing completes.
    1.73 +    double LatencyVisionProc;
    1.74 +
    1.75 +    // Measures the time from exposure until the pose is available for the frame, including processing time.
    1.76 +    double LatencyVisionFrame;
    1.77 +};
    1.78 +
    1.79 +//-----------------------------------------------------------------------------
    1.80 +typedef Delegate1<void, LatencyStatisticsResults*> LatencyStatisticsSlot;
    1.81 +
    1.82 +// ***** LatencyStatisticsObserver
    1.83 +class LatencyStatisticsCSV
    1.84 +{
    1.85 +public:
    1.86 +    LatencyStatisticsCSV();
    1.87 +    ~LatencyStatisticsCSV();
    1.88 +    bool Start(String fileName, String userData1);
    1.89 +    bool Stop();
    1.90 +    void OnResults(LatencyStatisticsResults *results);
    1.91 +
    1.92 +    // Internal
    1.93 +    void WriteHeaderV1();
    1.94 +    void WriteResultsV1(LatencyStatisticsResults *results);
    1.95 +    ObserverScope<LatencyStatisticsSlot>* GetObserver() { return &_Observer; }
    1.96 +
    1.97 +protected:
    1.98 +    ObserverScope<LatencyStatisticsSlot> _Observer;
    1.99 +    String Guid, UserData1;
   1.100 +    String FileName;
   1.101 +    OVR::SysFile _File;
   1.102 +    String OS, OSVersion, ProcessInfo, DisplayDriverVersion, CameraDriverVersion, GPUVersion;
   1.103 +};
   1.104 +
   1.105 +//-----------------------------------------------------------------------------
   1.106 +// ***** LatencyStatisticsCalculator
   1.107 +
   1.108 +// Calculator for latency statistics
   1.109 +class LagStatsCalculator
   1.110 +{
   1.111 +    // Statistics instrumentation inputs:
   1.112 +
   1.113 +    // Timestamp when the EndFrame() call started executing
   1.114 +    double              EndFrameStartTime;
   1.115 +    // Timestamp when the EndFrame() call finished executing
   1.116 +    double              EndFrameEndTime;
   1.117 +
   1.118 +    // Latency statistics for the epoch
   1.119 +    LatencyStatisticsResults latencyStatisticsData;
   1.120 +
   1.121 +    // Last latency data
   1.122 +    // float               LatencyData[3]; // render, timewarp, median post-present
   1.123 +
   1.124 +    // Last vision processing frame counter number
   1.125 +    uint32_t            LastCameraFrameCounter;
   1.126 +
   1.127 +    // Running statistics:
   1.128 +
   1.129 +    void resetPerfStats(double resetTime = 0.);
   1.130 +
   1.131 +    // Start of the current statistics epoch
   1.132 +    double              EpochBegin;
   1.133 +    // Count of frames in this stats epoch, measured at EndFrame()
   1.134 +    int                 FrameCount;
   1.135 +    // Sum of end frame durations for this stats epoch
   1.136 +    //double              EndFrameSum;
   1.137 +
   1.138 +    // Sum of latencies
   1.139 +    // double              LatencySum[3];
   1.140 +
   1.141 +    // Sum of vision processing times
   1.142 +    //double              VisionProcSum;
   1.143 +    // Sum of vision latency times
   1.144 +    //double              VisionLagSum;
   1.145 +    // Count of vision frames
   1.146 +    int                 VisionFrames;
   1.147 +
   1.148 +    // Statistics results:
   1.149 +
   1.150 +    LocklessUpdater<LatencyStatisticsResults, LatencyStatisticsResults> Results;
   1.151 +
   1.152 +    void calculateResults();
   1.153 +
   1.154 +    OVR::ObserverScope<LatencyStatisticsSlot> calculateResultsSubject;
   1.155 +    OVR::Lock calculateResultsLock;
   1.156 +
   1.157 +public:
   1.158 +    LagStatsCalculator();
   1.159 +
   1.160 +    void GetLatestResults(LatencyStatisticsResults* results);
   1.161 +    void AddResultsObserver(ObserverScope<LatencyStatisticsSlot> *calculateResultsObserver);
   1.162 +
   1.163 +public:
   1.164 +    // Internal instrumentation interface:
   1.165 +
   1.166 +    // EndFrame() instrumentation
   1.167 +    void InstrumentEndFrameStart(double timestamp);
   1.168 +    void InstrumentEndFrameEnd(double timestamp);
   1.169 +
   1.170 +    // DK2 latency tester instrumentation
   1.171 +    // Note: This assumes that it is called right before InstrumentEndFrameEnd()
   1.172 +    void InstrumentLatencyTimings(FrameTimeManager& ftm);
   1.173 +
   1.174 +    // Eye pose instrumentation
   1.175 +    void InstrumentEyePose(const ovrTrackingState& state);
   1.176 +};
   1.177 +
   1.178 +
   1.179 +}} // namespace OVR::CAPI
   1.180 +
   1.181 +#endif // OVR_CAPI_LatencyStatistics_h