-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathProfiler.h
More file actions
106 lines (87 loc) · 3.13 KB
/
Copy pathProfiler.h
File metadata and controls
106 lines (87 loc) · 3.13 KB
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
/*
* SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: LicenseRef-NvidiaProprietary
*
* NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
* property and proprietary rights in and to this material, related
* documentation and any modifications thereto. Any use, reproduction,
* disclosure or distribution of this material and related documentation
* without an express license agreement from NVIDIA CORPORATION or
* its affiliates is strictly prohibited.
*/
#pragma once
#include <nvrhi/nvrhi.h>
#include <chrono>
#include <optional>
#include <queue>
// The AveragingTimerQuery class implements a timer query that is non-blocking using a pool of
// regular NVRHI TimerQueries, and that accumulates the timing results over a set time interval.
class AveragingTimerQuery
{
private:
nvrhi::DeviceHandle m_device;
std::queue<nvrhi::TimerQueryHandle> m_idleQueries;
std::queue<nvrhi::TimerQueryHandle> m_activeQueries;
nvrhi::TimerQueryHandle m_openQuery;
std::vector<float> m_history;
float m_updateIntervalSeconds = 0.5f;
std::chrono::steady_clock::time_point m_lastUpdateTime = std::chrono::steady_clock::now();
std::optional<float> m_averageTime;
public:
AveragingTimerQuery(nvrhi::IDevice* device)
: m_device(device)
{ }
// Takes an available query from the pool and calls commandList->beginQuery with it.
void beginQuery(nvrhi::ICommandList* commandList);
// Calls commandList->endQuery with the currently open timer query.
void endQuery(nvrhi::ICommandList* commandList);
// Polls the active timer queries and retrieves available results, also processes temporal averaging.
// Call update() on every frame.
void update();
// Sets the time interval between updating average time values.
void setUpdateInterval(float seconds);
// Clears the history, such as when changing rendering algorithms.
void clearHistory();
// Returns the latest directly measured time, if any.
std::optional<float> getLatestAvailableTime();
// Returns the latest average time, if any.
std::optional<float> getAverageTime();
};
struct ProfilerRecord
{
double timestamp = 0;
double frameTime = 0;
double renderTime = 0;
double transcodingTime = 0;
uint32_t tilesTotal = 0;
uint32_t tilesAllocated = 0;
uint32_t tilesStandby = 0;
uint32_t tilesTranscoded = 0;
};
class SmoothAxisLimit
{
public:
double GetMaximum() const
{
return m_maximum;
}
void Update(double newMaximum, double lastFrameTimeSeconds);
private:
double m_maximum = 0.0;
};
class Profiler
{
public:
Profiler() = default;
ProfilerRecord& AddRecord();
ProfilerRecord* GetLastRecord();
void TrimHistory();
void BuildUI(bool enableFeedbackStats);
private:
friend class ProfilerGetters;
std::chrono::steady_clock::time_point m_appStartTime = std::chrono::steady_clock::now();
std::vector<ProfilerRecord> m_profilerHistory;
SmoothAxisLimit m_timePlotLimit;
SmoothAxisLimit m_tilesPlotLimit;
double m_profilerHistoryDuration = 2.0;
};