< Summary

Class:DCL.FPSDisplay.FPSDisplay
Assembly:FPSDisplay
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/Debugging/FPSDisplay/FPSDisplay.cs
Covered lines:29
Uncovered lines:4
Coverable lines:33
Total lines:79
Line coverage:87.8% (29 of 33)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
OnEnable()0%3.033085.71%
OnOtherPlayersModified(...)0%2100%
OnDisable()0%110100%
UpdateLabelLoop()0%330100%
UpdateLabel()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/Debugging/FPSDisplay/FPSDisplay.cs

#LineLine coverage
 1using System.Collections;
 2using UnityEngine;
 3using UnityEngine.UI;
 4
 5namespace DCL.FPSDisplay
 6{
 7
 8    public class FPSDisplay : MonoBehaviour
 9    {
 10        private const float REFRESH_SECONDS = 0.1f;
 11
 12        [SerializeField] private Text label;
 13        [SerializeField] private PerformanceMetricsDataVariable performanceData;
 14
 015        private BaseDictionary<string, Player> otherPlayers => DataStore.i.player.otherPlayers;
 16        private int lastPlayerCount = 0;
 17
 18        private void OnEnable()
 19        {
 120            if (label == null || performanceData == null)
 021                return;
 22
 123            lastPlayerCount = otherPlayers.Count();
 124            otherPlayers.OnAdded += OnOtherPlayersModified;
 125            otherPlayers.OnRemoved += OnOtherPlayersModified;
 26
 127            StartCoroutine(UpdateLabelLoop());
 128        }
 29
 30        private void OnOtherPlayersModified(string playerName, Player player)
 31        {
 032            lastPlayerCount = otherPlayers.Count();
 033        }
 34
 35        private void OnDisable()
 36        {
 137            otherPlayers.OnAdded -= OnOtherPlayersModified;
 138            otherPlayers.OnRemoved -= OnOtherPlayersModified;
 139            StopAllCoroutines();
 140        }
 41
 42        private IEnumerator UpdateLabelLoop()
 43        {
 644            while (true)
 45            {
 746                UpdateLabel();
 47
 748                yield return new WaitForSeconds(REFRESH_SECONDS);
 49            }
 50        }
 51
 52        private void UpdateLabel()
 53        {
 754            float dt = Time.unscaledDeltaTime;
 55
 756            float fps = performanceData.Get().fpsCount;
 57
 758            string fpsFormatted = fps.ToString("##");
 759            string msFormatted = (dt * 1000).ToString("##");
 60
 761            string targetText = string.Empty;
 62
 763            string NO_DECIMALS = "##";
 764            string TWO_DECIMALS = "##.00";
 765            targetText += $"Nearby players: {lastPlayerCount}\n";
 766            targetText += $"Hiccups in the last 1000 frames: {performanceData.Get().hiccupCount}\n";
 767            targetText += $"Hiccup loss: {(100.0f * performanceData.Get().hiccupSum / performanceData.Get().totalSeconds
 768            targetText += $"Bad Frames Percentile: {((performanceData.Get().hiccupCount) / 10.0f).ToString(NO_DECIMALS)}
 769            targetText += $"Current {msFormatted} ms (fps: {fpsFormatted})";
 70
 771            if (label.text != targetText)
 72            {
 673                label.text = targetText;
 74            }
 75
 776            FPSColoring.DisplayColor(label, fps);
 777        }
 78    }
 79}