| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL; |
| | 4 | | using DCL.FPSDisplay; |
| | 5 | | using MainScripts.DCL.WorldRuntime.Debugging.Performance; |
| | 6 | |
|
| | 7 | | public class FPSDebugMetricModule : IDebugMetricModule |
| | 8 | | { |
| | 9 | | private const string NO_DECIMALS = "##"; |
| | 10 | | private const string TWO_DECIMALS = "##.00"; |
| | 11 | |
|
| | 12 | | private readonly PerformanceMetricsDataVariable performanceData; |
| | 13 | |
|
| | 14 | | private float fps; |
| | 15 | | private string fpsColor; |
| | 16 | |
|
| | 17 | | private Service<IProfilerRecordsService> profilerRecordsService; |
| | 18 | |
|
| 0 | 19 | | public FPSDebugMetricModule(PerformanceMetricsDataVariable performanceData) |
| | 20 | | { |
| 0 | 21 | | this.performanceData = performanceData; |
| 0 | 22 | | } |
| | 23 | |
|
| 0 | 24 | | public void Dispose() { } |
| | 25 | |
|
| | 26 | | public void SetUpModule(Dictionary<DebugValueEnum, Func<string>> updateValueDictionary) |
| | 27 | | { |
| 0 | 28 | | updateValueDictionary.Add(DebugValueEnum.FPS, GetFPSCount); |
| 0 | 29 | | updateValueDictionary.Add(DebugValueEnum.FPS_HiccupsInTheLast1000, () => $"{fpsColor}{performanceData.Get().hicc |
| 0 | 30 | | updateValueDictionary.Add(DebugValueEnum.FPS_HiccupsLoss, GetHiccupsLoss); |
| 0 | 31 | | updateValueDictionary.Add(DebugValueEnum.FPS_BadFramesPercentiles, () => $"{fpsColor}{((performanceData.Get().hi |
| 0 | 32 | | } |
| | 33 | |
|
| | 34 | | public void UpdateModule() |
| | 35 | | { |
| 0 | 36 | | fps = performanceData.Get().fpsCount; |
| 0 | 37 | | fpsColor = FPSColoring.GetDisplayColorString(fps); |
| 0 | 38 | | } |
| | 39 | |
|
| 0 | 40 | | public void EnableModule() { } |
| | 41 | |
|
| 0 | 42 | | public void DisableModule() { } |
| | 43 | |
|
| | 44 | | private string GetFPSCount() |
| | 45 | | { |
| 0 | 46 | | (float FrameTime, float FPS) averageData = profilerRecordsService.Ref.AverageData; |
| | 47 | |
|
| 0 | 48 | | var fpsFormatted = averageData.FPS.ToString("##"); |
| 0 | 49 | | var msFormatted = averageData.FrameTime.ToString("##"); |
| | 50 | |
|
| 0 | 51 | | return $"<b>FPS</b> {fpsColor}{fpsFormatted}</color> {msFormatted} ms"; |
| | 52 | | } |
| | 53 | |
|
| | 54 | | private string GetHiccupsLoss() => |
| 0 | 55 | | $"{fpsColor}{(100.0f * performanceData.Get().hiccupSum / performanceData.Get().totalSeconds).ToString(TWO_DECIMA |
| | 56 | | } |