1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
/*############################################################################
# Copyright (C) 2005 Intel Corporation
#
# SPDX-License-Identifier: MIT
############################################################################*/
#pragma once
#include <stdio.h>
#include <vector>
#include "math.h"
#include "vm/strings_defs.h"
#include "vm/time_defs.h"
#include "vpl/mfxstructures.h"
class CTimeStatisticsReal {
public:
CTimeStatisticsReal() {
ResetStatistics();
start = 0;
m_bNeedDumping = false;
}
static msdk_tick GetFrequency() {
if (!frequency) {
frequency = msdk_time_get_frequency();
}
return frequency;
}
static mfxF64 ConvertToSeconds(msdk_tick elapsed) {
return MSDK_GET_TIME(elapsed, 0, GetFrequency());
}
inline void StartTimeMeasurement() {
start = msdk_time_get_tick();
}
inline void StopTimeMeasurement() {
mfxF64 delta = GetDeltaTime();
totalTime += delta;
totalTimeSquares += delta * delta;
// dump in ms:
if (m_bNeedDumping)
m_time_deltas.push_back(delta * 1000);
if (delta < minTime) {
minTime = delta;
}
if (delta > maxTime) {
maxTime = delta;
}
numMeasurements++;
}
inline void StopTimeMeasurementWithCheck() {
if (start) {
StopTimeMeasurement();
}
}
inline mfxF64 GetDeltaTime() {
return MSDK_GET_TIME(msdk_time_get_tick(), start, GetFrequency());
}
inline mfxF64 GetDeltaTimeInMiliSeconds() {
return GetDeltaTime() * 1000;
}
inline void TurnOnDumping() {
m_bNeedDumping = true;
}
inline void TurnOffDumping() {
m_bNeedDumping = false;
}
inline void PrintStatistics(const char* prefix) {
printf("%s Total:%.3lfms(%llu smpls),Avg %.3lfms,StdDev:%.3lfms,Min:%.3lfms,Max:%.3lfms\n",
prefix,
(double)totalTime,
(unsigned long long int)numMeasurements,
(double)GetAvgTime(false),
(double)GetTimeStdDev(false),
(double)GetMinTime(false),
(double)GetMaxTime(false));
}
inline mfxU64 GetNumMeasurements() {
return numMeasurements;
}
inline mfxF64 GetAvgTime(bool inSeconds = true) {
if (inSeconds) {
return (numMeasurements ? totalTime / numMeasurements : 0);
}
else {
return (numMeasurements ? totalTime / numMeasurements : 0) * 1000;
}
}
inline mfxF64 GetTimeStdDev(bool inSeconds = true) {
mfxF64 avg = GetAvgTime();
mfxF64 ftmp =
(numMeasurements ? sqrt(totalTimeSquares / numMeasurements - avg * avg) : 0.0);
return inSeconds ? ftmp : ftmp * 1000;
}
inline mfxF64 GetMinTime(bool inSeconds = true) {
return inSeconds ? minTime : minTime * 1000;
}
inline mfxF64 GetMaxTime(bool inSeconds = true) {
return inSeconds ? maxTime : maxTime * 1000;
}
inline mfxF64 GetTotalTime(bool inSeconds = true) {
return inSeconds ? totalTime : totalTime * 1000;
}
inline void ResetStatistics() {
totalTime = 0;
totalTimeSquares = 0;
minTime = 1E100;
maxTime = -1;
numMeasurements = 0;
m_time_deltas.clear();
TurnOffDumping();
}
protected:
static msdk_tick frequency;
msdk_tick start;
mfxF64 totalTime;
mfxF64 totalTimeSquares;
mfxF64 minTime;
mfxF64 maxTime;
mfxU64 numMeasurements;
std::vector<mfxF64> m_time_deltas;
bool m_bNeedDumping;
};
class CTimeStatisticsDummy {
public:
static msdk_tick GetFrequency() {
if (!frequency) {
frequency = msdk_time_get_frequency();
}
return frequency;
}
static mfxF64 ConvertToSeconds(msdk_tick /*elapsed*/) {
return 0;
}
inline void StartTimeMeasurement() {}
inline void StopTimeMeasurement() {}
inline void StopTimeMeasurementWithCheck() {}
inline mfxF64 GetDeltaTime() {
return 0;
}
inline mfxF64 GetDeltaTimeInMiliSeconds() {
return 0;
}
inline void TurnOnDumping() {}
inline void TurnOffDumping() {}
inline void PrintStatistics(const char* /*prefix*/) {}
inline mfxU64 GetNumMeasurements() {
return 0;
}
inline mfxF64 GetAvgTime(bool) {
return 0;
}
inline mfxF64 GetTimeStdDev(bool) {
return 0;
}
inline mfxF64 GetMinTime(bool) {
return 0;
}
inline mfxF64 GetMaxTime(bool) {
return 0;
}
inline mfxF64 GetTotalTime(bool) {
return 0;
}
inline void ResetStatistics() {}
protected:
static msdk_tick frequency;
};
#ifdef TIME_STATS
typedef CTimeStatisticsReal CTimeStatistics;
#else
typedef CTimeStatisticsDummy CTimeStatistics;
#endif
|