< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Init()0%2100%
StartProfiling()0%12300%
StopProfiling()0%6200%
Update()0%6200%
RefreshProfilingData()0%1321100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Globalization;
 5using System.Linq;
 6using DCL.Controllers;
 7using UnityEngine;
 8using UnityGLTF;
 9
 10namespace DCL
 11{
 12    [RequireComponent(typeof(StatsPanel))]
 13    public class MiscBenchmarkController : MonoBehaviour, IBenchmarkController
 14    {
 15        public enum Columns
 16        {
 17            NONE,
 18            VALUE,
 19        }
 20
 21        public enum Rows
 22        {
 23            NONE,
 24            SHARED_OBJECTS_COUNT,
 25            COMPONENT_OBJECTS_COUNT,
 26            ENTITY_OBJECTS_COUNT,
 27            BREAK_0,
 28            MATERIAL_COUNT,
 29            MESHES_COUNT,
 30            BREAK_1,
 31            GLTF_BEING_LOADED,
 32            AB_BEING_LOADED,
 33            MESSAGES_PER_SECOND_REAL,
 34            RENDERER_UNLOCK_SEGS,
 35            MESSAGE_BUSES,
 36        }
 37
 38        const string BREAK_0_TEXT = "";
 39        const string BREAK_1_TEXT = "";
 40
 41        const string RENDERER_UNLOCK_TEXT = "Time Until Renderer Enable";
 42        const string SHARED_OBJECTS_COUNT_TEXT = "Shared Objects Count";
 43        const string COMPONENT_OBJECTS_COUNT_TEXT = "Components Count";
 44        const string ENTITY_OBJECTS_COUNT_TEXT = "Entity Count";
 45        const string MATERIAL_COUNT_TEXT = "Material Count";
 46        const string MESHES_COUNT_TEXT = "Meshes Count";
 47        const string GLTF_BEING_LOADED_TEXT = "GLTFs active requests";
 48        const string AB_BEING_LOADED_TEXT = "Asset bundles active requests";
 49        const string MESSAGES_PER_SECOND_REAL_TEXT = "Messages x sec";
 50        const string MESSAGES_BUSES_TEXT = "Message buses";
 51
 52        StatsPanel statsPanel;
 53        List<Columns> columnsList;
 54        List<Rows> rowsList;
 55
 56        int lastPendingMessages;
 57        int sampleCount = 0;
 58        float mps = 0;
 59
 60        public void Init()
 61        {
 062            this.statsPanel = GetComponent<StatsPanel>();
 63
 064            columnsList = Enum.GetValues(typeof(Columns)).Cast<Columns>().ToList();
 065            rowsList = Enum.GetValues(typeof(Rows)).Cast<Rows>().ToList();
 66
 067            statsPanel.PopulateTable(columnsList.Count, rowsList.Count, 240, 240);
 68
 69            //NOTE(Brian): Top-left cell, unused.
 070            statsPanel.SetCellText(0, 0, "");
 71
 72            //NOTE(Brian): Row stuff (left vertical header)
 073            statsPanel.SetCellText(0, (int) Rows.SHARED_OBJECTS_COUNT, SHARED_OBJECTS_COUNT_TEXT);
 074            statsPanel.SetCellText(0, (int) Rows.COMPONENT_OBJECTS_COUNT, COMPONENT_OBJECTS_COUNT_TEXT);
 075            statsPanel.SetCellText(0, (int) Rows.ENTITY_OBJECTS_COUNT, ENTITY_OBJECTS_COUNT_TEXT);
 076            statsPanel.SetCellText(0, (int) Rows.BREAK_0, BREAK_0_TEXT);
 077            statsPanel.SetCellText(0, (int) Rows.MATERIAL_COUNT, MATERIAL_COUNT_TEXT);
 078            statsPanel.SetCellText(0, (int) Rows.MESHES_COUNT, MESHES_COUNT_TEXT);
 079            statsPanel.SetCellText(0, (int) Rows.BREAK_1, BREAK_1_TEXT);
 080            statsPanel.SetCellText(0, (int) Rows.GLTF_BEING_LOADED, GLTF_BEING_LOADED_TEXT);
 081            statsPanel.SetCellText(0, (int) Rows.AB_BEING_LOADED, AB_BEING_LOADED_TEXT);
 082            statsPanel.SetCellText(0, (int) Rows.MESSAGES_PER_SECOND_REAL, MESSAGES_PER_SECOND_REAL_TEXT);
 083            statsPanel.SetCellText(0, (int) Rows.RENDERER_UNLOCK_SEGS, RENDERER_UNLOCK_TEXT);
 084            statsPanel.SetCellText(0, (int) Rows.MESSAGE_BUSES, MESSAGES_BUSES_TEXT);
 085        }
 86
 87        private Coroutine updateCoroutine;
 88
 89        public void StartProfiling()
 90        {
 091            if (enabled)
 92            {
 093                return;
 94            }
 95
 096            if (statsPanel == null)
 97            {
 098                Init();
 99            }
 100
 0101            updateCoroutine = CoroutineStarter.Start(RefreshProfilingData());
 0102            enabled = true;
 0103        }
 104
 105        public void StopProfiling()
 106        {
 0107            if (!enabled)
 108            {
 0109                return;
 110            }
 111
 0112            CoroutineStarter.Stop(updateCoroutine);
 0113            enabled = false;
 0114        }
 115
 116        static float budgetMax = 0;
 117
 118        void Update()
 119        {
 0120            MessagingControllersManager messagingManager = Environment.i.messaging.manager as MessagingControllersManage
 121
 0122            int messagesProcessedLastFrame = lastPendingMessages - messagingManager.pendingMessagesCount;
 123
 0124            if (messagesProcessedLastFrame > 0)
 125            {
 0126                sampleCount++;
 0127                mps += 1 / (Time.deltaTime / messagesProcessedLastFrame);
 0128                statsPanel.SetCellText(1, (int) Rows.MESSAGES_PER_SECOND_REAL, (mps / sampleCount).ToString(CultureInfo.
 129            }
 130
 0131            lastPendingMessages = messagingManager.pendingMessagesCount;
 0132        }
 133
 134        private IEnumerator RefreshProfilingData()
 135        {
 0136            while (true)
 137            {
 0138                int sharedCount = 0;
 0139                int sharedAttachCount = 0;
 0140                int componentCount = 0;
 0141                int entityCount = 0;
 0142                int materialCount = 0;
 0143                int meshesCount = 0;
 144
 0145                var loadedScenes = Environment.i.world.state.loadedScenes;
 146
 0147                foreach (var v in loadedScenes)
 148                {
 0149                    ParcelScene scene = v.Value as ParcelScene;
 0150                    if (scene.metricsCounter != null)
 151                    {
 0152                        meshesCount += scene.metricsCounter.currentCount.meshes;
 0153                        materialCount += scene.metricsCounter.currentCount.materials;
 154                    }
 155
 0156                    sharedCount += scene.disposableComponents.Count;
 157
 0158                    foreach (var e in scene.disposableComponents)
 159                    {
 0160                        sharedAttachCount += e.Value.GetAttachedEntities().Count;
 161                    }
 162
 0163                    entityCount += scene.entities.Count;
 164
 0165                    foreach (var e in scene.entities)
 166                    {
 0167                        componentCount += e.Value.components.Count;
 168                    }
 169                }
 170
 0171                statsPanel.SetCellText(1, (int) Rows.SHARED_OBJECTS_COUNT, sharedCount.ToString());
 0172                statsPanel.SetCellText(1, (int) Rows.COMPONENT_OBJECTS_COUNT, componentCount.ToString());
 0173                statsPanel.SetCellText(1, (int) Rows.ENTITY_OBJECTS_COUNT, entityCount.ToString());
 0174                statsPanel.SetCellText(1, (int) Rows.MATERIAL_COUNT, materialCount.ToString());
 0175                statsPanel.SetCellText(1, (int) Rows.MESHES_COUNT, meshesCount.ToString());
 0176                statsPanel.SetCellText(1, (int) Rows.GLTF_BEING_LOADED, GLTFComponent.downloadingCount.ToString() + " ..
 0177                statsPanel.SetCellText(1, (int) Rows.AB_BEING_LOADED, AssetPromise_AB.downloadingCount.ToString() + " ..
 0178                statsPanel.SetCellText(1, (int) Rows.RENDERER_UNLOCK_SEGS, RenderingController.firstActivationTime.ToStr
 179
 0180                string busesLog = "";
 0181                Dictionary<string, int> pendingMessagesCount = new Dictionary<string, int>();
 0182                Dictionary<string, int> messagesReplaced = new Dictionary<string, int>();
 183
 0184                MessagingControllersManager messagingManager = Environment.i.messaging.manager as MessagingControllersMa
 185
 0186                using (var controllersIter = messagingManager.messagingControllers.GetEnumerator())
 187                {
 0188                    while (controllersIter.MoveNext())
 189                    {
 0190                        using (var iterator = controllersIter.Current.Value.messagingBuses.GetEnumerator())
 191                        {
 0192                            while (iterator.MoveNext())
 193                            {
 194                                //access to pair using iterator.Current
 0195                                MessagingBusType key = iterator.Current.Key;
 0196                                MessagingBus bus = controllersIter.Current.Value.messagingBuses[key];
 197
 0198                                string keyString = key.ToString();
 199
 0200                                if (!pendingMessagesCount.ContainsKey(keyString))
 0201                                    pendingMessagesCount[keyString] = 0;
 202
 0203                                if (!messagesReplaced.ContainsKey(keyString))
 0204                                    messagesReplaced[keyString] = 0;
 205
 0206                                pendingMessagesCount[keyString] += bus.pendingMessagesCount;
 0207                                messagesReplaced[keyString] += bus.unreliableMessagesReplaced;
 208                            }
 0209                        }
 210                    }
 0211                }
 212
 0213                busesLog += $"{MessagingBusType.UI.ToString()} bus: {pendingMessagesCount[MessagingBusType.UI.ToString()
 0214                busesLog += $"{MessagingBusType.INIT.ToString()} bus: {pendingMessagesCount[MessagingBusType.INIT.ToStri
 0215                busesLog += $"{MessagingBusType.SYSTEM.ToString()} bus: {pendingMessagesCount[MessagingBusType.SYSTEM.To
 216
 0217                statsPanel.SetCellText(1, (int) Rows.MESSAGE_BUSES, busesLog);
 218
 0219                yield return WaitForSecondsCache.Get(0.2f);
 220            }
 221        }
 222    }
 223}