< Summary

Class:DCL.UserBenchmarkController
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/Debugging/Panels/UserBenchmarkController.cs
Covered lines:0
Uncovered lines:67
Coverable lines:67
Total lines:172
Line coverage:0% (0 of 67)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%2100%
OnDestroy()0%2100%
Init()0%2100%
StartProfiling()0%6200%
OnMessageWillDequeue(...)0%2100%
OnMessageWillQueue(...)0%2100%
StopProfiling()0%6200%
RefreshProfilingData()0%56700%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Linq;
 5using DCL.Configuration;
 6using DCL.Controllers;
 7using DCL.Helpers;
 8using UnityEngine;
 9
 10namespace DCL
 11{
 12    [RequireComponent(typeof(StatsPanel))]
 13    public class UserBenchmarkController : MonoBehaviour, IBenchmarkController
 14    {
 15        public enum Columns
 16        {
 17            LABEL,
 18            VALUE,
 19        }
 20
 21        public enum Rows
 22        {
 23            NONE,
 24            PROCESSED_MESSAGES,
 25            PENDING_MESSAGES,
 26            BREAK_0,
 27            CURRENT_SCENE,
 28            POLYGONS_VS_LIMIT,
 29            TEXTURES_VS_LIMIT,
 30            MATERIALS_VS_LIMIT,
 31            ENTITIES_VS_LIMIT,
 32            MESHES_VS_LIMIT,
 33            BODIES_VS_LIMIT,
 34            COMPONENT_OBJECTS_COUNT
 35        }
 36
 37        const string BREAK_0_TEXT = "";
 38
 39        const string PROCESSED_MESSAGES_TEXT = "Processed Messages";
 40        const string PENDING_MESSAGES_TEXT = "Pending on Queue";
 41
 42        const string CURRENT_SCENE_TEST = "Scene Location:";
 43        const string POLYGON_VS_LIMIT_TEXT = "Poly Count";
 44        const string TEXTURES_VS_LIMIT_TEXT = "Textures Count";
 45        const string MATERIALS_VS_LIMIT_TEXT = "Materials Count";
 46        const string ENTITIES_VS_LIMIT_TEXT = "Entities Count";
 47        const string MESHES_VS_LIMIT_TEXT = "Meshes Count";
 48        const string BODIES_VS_LIMIT_TEXT = "Bodies Count";
 49        const string COMPONENT_OBJECTS_COUNT_TEXT = "Components Count";
 50
 51        int totalMessagesCurrent;
 52        int totalMessagesGlobal;
 53
 54        StatsPanel statsPanel;
 55        List<Columns> columnsList;
 56        List<Rows> rowsList;
 57
 058        private void Awake() { StartProfiling(); }
 59
 060        private void OnDestroy() { StopProfiling(); }
 61
 62        public void Init()
 63        {
 064            this.statsPanel = GetComponent<StatsPanel>();
 65
 066            columnsList = Enum.GetValues(typeof(Columns)).Cast<Columns>().ToList();
 067            rowsList = Enum.GetValues(typeof(Rows)).Cast<Rows>().ToList();
 68
 069            statsPanel.PopulateTable(columnsList.Count, rowsList.Count, 240, 240);
 70
 071            statsPanel.SetCellText((int) Columns.LABEL, (int) Columns.LABEL, "");
 72
 73            //Init Labels
 074            statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.PROCESSED_MESSAGES, PROCESSED_MESSAGES_TEXT);
 075            statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.PENDING_MESSAGES, PENDING_MESSAGES_TEXT);
 76
 077            statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.BREAK_0, BREAK_0_TEXT);
 78
 079            statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.CURRENT_SCENE, CURRENT_SCENE_TEST);
 080            statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.POLYGONS_VS_LIMIT, POLYGON_VS_LIMIT_TEXT);
 081            statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.TEXTURES_VS_LIMIT, TEXTURES_VS_LIMIT_TEXT);
 082            statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.MATERIALS_VS_LIMIT, MATERIALS_VS_LIMIT_TEXT);
 083            statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.ENTITIES_VS_LIMIT, ENTITIES_VS_LIMIT_TEXT);
 084            statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.MESHES_VS_LIMIT, MESHES_VS_LIMIT_TEXT);
 085            statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.BODIES_VS_LIMIT, BODIES_VS_LIMIT_TEXT);
 086            statsPanel.SetCellText((int) Columns.LABEL, (int) Rows.COMPONENT_OBJECTS_COUNT, COMPONENT_OBJECTS_COUNT_TEXT
 87
 88            //Init Values
 89
 090            statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.PROCESSED_MESSAGES, "=/=");
 091            statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.PENDING_MESSAGES, "=/=");
 92
 093            statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.CURRENT_SCENE, "=/=");
 094            statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.POLYGONS_VS_LIMIT, "=/=");
 095            statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.TEXTURES_VS_LIMIT, "=/=");
 096            statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.MATERIALS_VS_LIMIT, "=/=");
 097            statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.ENTITIES_VS_LIMIT, "=/=");
 098            statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.MESHES_VS_LIMIT, "=/=");
 099            statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.BODIES_VS_LIMIT, "=/=");
 0100            statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.COMPONENT_OBJECTS_COUNT, "=/=");
 101
 0102            Canvas.ForceUpdateCanvases();
 0103        }
 104
 105        public void StartProfiling()
 106        {
 0107            if (statsPanel == null)
 108            {
 0109                Init();
 110            }
 111
 0112            profilingCoroutine = CoroutineStarter.Start(RefreshProfilingData());
 0113            ProfilingEvents.OnMessageWillQueue += OnMessageWillQueue;
 0114            ProfilingEvents.OnMessageWillDequeue += OnMessageWillDequeue;
 0115        }
 116
 117        private void OnMessageWillDequeue(string obj)
 118        {
 0119            totalMessagesCurrent = Math.Min(totalMessagesCurrent + 1, totalMessagesGlobal);
 0120            statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.PROCESSED_MESSAGES, $"{totalMessagesCurrent} of {tota
 0121            statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.PENDING_MESSAGES, $"{totalMessagesGlobal - totalMessa
 0122        }
 123
 124        private void OnMessageWillQueue(string obj)
 125        {
 0126            totalMessagesGlobal++;
 0127            statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.PROCESSED_MESSAGES, $"{totalMessagesCurrent}:{totalMe
 0128            statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.PENDING_MESSAGES, $"{totalMessagesGlobal - totalMessa
 0129        }
 130
 131        private Coroutine profilingCoroutine;
 132
 133        public void StopProfiling()
 134        {
 0135            if (profilingCoroutine != null)
 0136                CoroutineStarter.Stop(profilingCoroutine);
 137
 0138            ProfilingEvents.OnMessageWillQueue -= OnMessageWillQueue;
 0139            ProfilingEvents.OnMessageWillDequeue -= OnMessageWillDequeue;
 0140        }
 141
 142        private IEnumerator RefreshProfilingData()
 143        {
 0144            while (true)
 145            {
 0146                var currentPos = Utils.WorldToGridPosition(DCLCharacterController.i.characterPosition.worldPosition);
 147
 0148                IWorldState worldState = Environment.i.world.state;
 149
 0150                ParcelScene activeScene = worldState.loadedScenes.Values.FirstOrDefault(
 0151                    x => x.sceneData.parcels != null
 0152                         && x.sceneData.parcels.Any(y => y == currentPos)) as ParcelScene;
 153
 0154                if (activeScene != null && activeScene.metricsCounter != null)
 155                {
 0156                    var metrics = activeScene.metricsCounter.GetModel();
 0157                    var limits = activeScene.metricsCounter.GetLimits();
 0158                    statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.CURRENT_SCENE, $"{activeScene.sceneData.id}")
 0159                    statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.POLYGONS_VS_LIMIT, $"{metrics.triangles} of {
 0160                    statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.TEXTURES_VS_LIMIT, $"{metrics.textures} of {l
 0161                    statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.MATERIALS_VS_LIMIT, $"{metrics.materials} of 
 0162                    statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.ENTITIES_VS_LIMIT, $"{metrics.entities} of {l
 0163                    statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.MESHES_VS_LIMIT, $"{metrics.meshes} of {limit
 0164                    statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.BODIES_VS_LIMIT, $"{metrics.bodies} of {limit
 0165                    statsPanel.SetCellText((int) Columns.VALUE, (int) Rows.COMPONENT_OBJECTS_COUNT, activeScene.disposab
 166                }
 167
 0168                yield return WaitForSecondsCache.Get(0.2f);
 169            }
 170        }
 171    }
 172}