| | 1 | | using DCL.Interface; |
| | 2 | | using DCL.FPSDisplay; |
| | 3 | | using DCL.SettingsCommon; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL |
| | 7 | | { |
| | 8 | | public class PerformanceMetricsController |
| | 9 | | { |
| 0 | 10 | | private LinealBufferHiccupCounter tracker = new LinealBufferHiccupCounter(); |
| | 11 | | private const int SAMPLES_SIZE = 1000; // Send performance report every 1000 samples |
| 0 | 12 | | private char[] encodedSamples = new char[SAMPLES_SIZE]; |
| | 13 | | private int currentIndex = 0; |
| | 14 | |
|
| | 15 | | [SerializeField] private PerformanceMetricsDataVariable performanceMetricsDataVariable; |
| | 16 | |
|
| 0 | 17 | | public PerformanceMetricsController() { performanceMetricsDataVariable = Resources.Load<PerformanceMetricsDataVa |
| | 18 | |
|
| | 19 | | public void Update() |
| | 20 | | { |
| | 21 | | #if !UNITY_EDITOR && UNITY_WEBGL |
| | 22 | | if (!CommonScriptableObjects.focusState.Get()) |
| | 23 | | return; |
| | 24 | | #endif |
| 0 | 25 | | if (!CommonScriptableObjects.rendererState.Get()) |
| 0 | 26 | | return; |
| | 27 | |
|
| 0 | 28 | | var deltaInMs = Time.deltaTime * 1000; |
| | 29 | |
|
| 0 | 30 | | tracker.AddDeltaTime(Time.deltaTime); |
| | 31 | |
|
| 0 | 32 | | performanceMetricsDataVariable.Set(tracker.CurrentFPSCount(), |
| | 33 | | tracker.CurrentHiccupCount(), |
| | 34 | | tracker.HiccupsSum, |
| | 35 | | tracker.GetTotalSeconds()); |
| | 36 | |
|
| 0 | 37 | | encodedSamples[currentIndex++] = (char)deltaInMs; |
| | 38 | |
|
| 0 | 39 | | if (currentIndex == SAMPLES_SIZE) |
| | 40 | | { |
| 0 | 41 | | currentIndex = 0; |
| 0 | 42 | | Report(new string(encodedSamples)); |
| | 43 | | } |
| 0 | 44 | | } |
| | 45 | |
|
| 0 | 46 | | private void Report(string encodedSamples) { WebInterface.SendPerformanceReport(encodedSamples, Settings.i.quali |
| | 47 | | } |
| | 48 | | } |