Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
DiskUtilizationTracker.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#ifndef TRACK_DISK_UTILIZATION
6#define TRACK_DISK_UTILIZATION 0
7#endif
8
9#include "CoreTypes.h"
10
12#include "HAL/PlatformMisc.h"
13#include "HAL/ThreadSafeBool.h"
14#include "ProfilingDebugging/CsvProfiler.h"
15
16#include <nn/nn_Log.h>
17
18CSV_DECLARE_CATEGORY_EXTERN(DiskIO);
19
20#ifndef SPEW_DISK_UTILIZATION
21#define SPEW_DISK_UTILIZATION 0
22#endif // SPEW_DISK_UTILIZATION
23
24struct FDiskUtilizationTracker
25{
26 struct UtilizationStats
27 {
28 UtilizationStats() :
29 TotalReads(0),
30 TotalSeeks(0),
31 TotalBytesRead(0),
32 TotalSeekDistance(0),
33 TotalIOTime(0.0),
34 TotalIdleTime(0.0)
35 {}
36
37 double GetOverallThroughputBS() const
38 {
39 return (TotalIOTime + TotalIdleTime) > 0.0 ? double(TotalBytesRead) / (TotalIOTime + TotalIdleTime) : 0.0;
40 }
41
42 double GetOverallThroughputMBS() const
43 {
44 return GetOverallThroughputBS() / (1024.0 * 1024.0);
45 }
46
47 double GetReadThrougputBS() const
48 {
49 return TotalIOTime > 0.0 ? double(TotalBytesRead) / TotalIOTime : 0.0;
50 }
51
52 double GetReadThrougputMBS() const
53 {
54 return GetReadThrougputBS() / (1024.0 * 1024.0);
55 }
56
57 double GetTotalIdleTimeInSeconds() const
58 {
59 return TotalIdleTime;
60 }
61
62 double GetTotalIOTimeInSeconds() const
63 {
64 return TotalIOTime;
65 }
66
67 double GetPercentTimeIdle() const
68 {
69 double TotalTime = TotalIOTime + TotalIdleTime;
70
71 return TotalTime > 0.0 ? (100.0f * TotalIdleTime) / TotalTime : 0.0;
72 }
73
74 void Reset()
75 {
76 TotalReads = 0;
77 TotalSeeks = 0;
78 TotalBytesRead = 0;
79 TotalSeekDistance = 0;
80 TotalIOTime = 0.0;
81 TotalIdleTime = 0.0;
82 }
83
84 void Dump() const;
85
86 uint64 TotalReads;
87 uint64 TotalSeeks;
88
89 uint64 TotalBytesRead;
90 uint64 TotalSeekDistance;
91
92 double TotalIOTime;
93 double TotalIdleTime;
94 };
95
96 UtilizationStats LongTermStats;
97 UtilizationStats ShortTermStats;
98
99 FCriticalSection CriticalSection;
100
101 uint64 IdleStartCycle;
102 uint64 ReadStartCycle;
103
104 uint64 InFlightBytes;
105 int32 InFlightReads;
106
107 FThreadSafeBool bResetShortTermStats;
108
109 FDiskUtilizationTracker() :
110 IdleStartCycle(0),
111 ReadStartCycle(0),
112 InFlightBytes(0),
113 InFlightReads(0)
114 {
115 }
116
117 void StartRead(uint64 InReadBytes, uint64 InSeekDistance = 0);
118 void FinishRead();
119
120 uint32 GetOutstandingRequests() const
121 {
122 return InFlightReads;
123 }
124
125 const struct UtilizationStats& GetLongTermStats() const
126 {
127 return LongTermStats;
128 }
129
130 const struct UtilizationStats& GetShortTermStats() const
131 {
132 return ShortTermStats;
133 }
134
135 void ResetShortTermStats()
136 {
137 bResetShortTermStats = true;
138 }
139
140private:
141 static float GetThrottleRateMBS();
142 static constexpr float PrintFrequencySeconds = 0.5f;
143
144 void MaybePrint();
145};
146
147extern FDiskUtilizationTracker GDiskUtilizationTracker;
148
149struct FScopedDiskUtilizationTracker
150{
151 FScopedDiskUtilizationTracker(uint64 InReadBytes, uint64 InSeekDistance)
152 {
153 GDiskUtilizationTracker.StartRead(InReadBytes, InSeekDistance);
154 }
155
156 ~FScopedDiskUtilizationTracker()
157 {
158 GDiskUtilizationTracker.FinishRead();
159 }
160};
161
162#else
163
165{
166 FScopedDiskUtilizationTracker(uint64 Size, uint64 SeekDistance)
167 {
168 }
169};
170
171#endif // TRACK_DISK_UTILIZATION
#define TRACK_DISK_UTILIZATION
FScopedDiskUtilizationTracker(uint64 Size, uint64 SeekDistance)