< Summary

Class:DCL.MiscBenchmarkController
Assembly:DCL.Runtime
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/Debugging/Panels/MiscBenchmarkController.cs
Covered lines:0
Uncovered lines:88
Coverable lines:88
Total lines:230
Line coverage:0% (0 of 88)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:5
Method coverage:0% (0 of 5)

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%2101400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/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;
 8
 9namespace DCL
 10{
 11    [RequireComponent(typeof(StatsPanel))]
 12    public class MiscBenchmarkController : MonoBehaviour, IBenchmarkController
 13    {
 14        public enum Columns
 15        {
 16            NONE,
 17            VALUE,
 18        }
 19
 20        public enum Rows
 21        {
 22            NONE,
 23            SHARED_OBJECTS_COUNT,
 24            COMPONENT_OBJECTS_COUNT,
 25            ENTITY_OBJECTS_COUNT,
 26            BREAK_0,
 27            MATERIAL_COUNT,
 28            MESHES_COUNT,
 29            BREAK_1,
 30            GLTF_BEING_LOADED,
 31            AB_BEING_LOADED,
 32            MESSAGES_PER_SECOND_REAL,
 33            RENDERER_UNLOCK_SEGS,
 34            MESSAGE_BUSES,
 35        }
 36
 37        const string BREAK_0_TEXT = "";
 38        const string BREAK_1_TEXT = "";
 39
 40        const string RENDERER_UNLOCK_TEXT = "Time Until Renderer Enable";
 41        const string SHARED_OBJECTS_COUNT_TEXT = "Shared Objects Count";
 42        const string COMPONENT_OBJECTS_COUNT_TEXT = "Components Count";
 43        const string ENTITY_OBJECTS_COUNT_TEXT = "Entity Count";
 44        const string MATERIAL_COUNT_TEXT = "Material Count";
 45        const string MESHES_COUNT_TEXT = "Meshes Count";
 46        const string GLTF_BEING_LOADED_TEXT = "GLTFs active requests";
 47        const string AB_BEING_LOADED_TEXT = "Asset bundles active requests";
 48        const string MESSAGES_PER_SECOND_REAL_TEXT = "Messages x sec";
 49        const string MESSAGES_BUSES_TEXT = "Message buses";
 50
 51        StatsPanel statsPanel;
 52        List<Columns> columnsList;
 53        List<Rows> rowsList;
 54
 55        int lastPendingMessages;
 56        int sampleCount = 0;
 57        float mps = 0;
 58
 59        public void Init()
 60        {
 061            this.statsPanel = GetComponent<StatsPanel>();
 62
 063            columnsList = Enum.GetValues(typeof(Columns)).Cast<Columns>().ToList();
 064            rowsList = Enum.GetValues(typeof(Rows)).Cast<Rows>().ToList();
 65
 066            statsPanel.PopulateTable(columnsList.Count, rowsList.Count, 240, 240);
 67
 68            //NOTE(Brian): Top-left cell, unused.
 069            statsPanel.SetCellText(0, 0, "");
 70
 71            //NOTE(Brian): Row stuff (left vertical header)
 072            statsPanel.SetCellText(0, (int) Rows.SHARED_OBJECTS_COUNT, SHARED_OBJECTS_COUNT_TEXT);
 073            statsPanel.SetCellText(0, (int) Rows.COMPONENT_OBJECTS_COUNT, COMPONENT_OBJECTS_COUNT_TEXT);
 074            statsPanel.SetCellText(0, (int) Rows.ENTITY_OBJECTS_COUNT, ENTITY_OBJECTS_COUNT_TEXT);
 075            statsPanel.SetCellText(0, (int) Rows.BREAK_0, BREAK_0_TEXT);
 076            statsPanel.SetCellText(0, (int) Rows.MATERIAL_COUNT, MATERIAL_COUNT_TEXT);
 077            statsPanel.SetCellText(0, (int) Rows.MESHES_COUNT, MESHES_COUNT_TEXT);
 078            statsPanel.SetCellText(0, (int) Rows.BREAK_1, BREAK_1_TEXT);
 079            statsPanel.SetCellText(0, (int) Rows.GLTF_BEING_LOADED, GLTF_BEING_LOADED_TEXT);
 080            statsPanel.SetCellText(0, (int) Rows.AB_BEING_LOADED, AB_BEING_LOADED_TEXT);
 081            statsPanel.SetCellText(0, (int) Rows.MESSAGES_PER_SECOND_REAL, MESSAGES_PER_SECOND_REAL_TEXT);
 082            statsPanel.SetCellText(0, (int) Rows.RENDERER_UNLOCK_SEGS, RENDERER_UNLOCK_TEXT);
 083            statsPanel.SetCellText(0, (int) Rows.MESSAGE_BUSES, MESSAGES_BUSES_TEXT);
 084        }
 85
 86        private Coroutine updateCoroutine;
 87
 88        public void StartProfiling()
 89        {
 090            if (enabled)
 91            {
 092                return;
 93            }
 94
 095            if (statsPanel == null)
 96            {
 097                Init();
 98            }
 99
 0100            updateCoroutine = CoroutineStarter.Start(RefreshProfilingData());
 0101            enabled = true;
 0102        }
 103
 104        public void StopProfiling()
 105        {
 0106            if (!enabled)
 107            {
 0108                return;
 109            }
 110
 0111            CoroutineStarter.Stop(updateCoroutine);
 0112            enabled = false;
 0113        }
 114
 115        static float budgetMax = 0;
 116
 117        void Update()
 118        {
 0119            MessagingControllersManager messagingManager =
 120                Environment.i.messaging.manager as MessagingControllersManager;
 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,
 129                    (mps / sampleCount).ToString(CultureInfo.InvariantCulture));
 130            }
 131
 0132            lastPendingMessages = messagingManager.pendingMessagesCount;
 0133        }
 134
 135        private IEnumerator RefreshProfilingData()
 136        {
 0137            while (true)
 138            {
 0139                int sharedCount = 0;
 0140                int sharedAttachCount = 0;
 0141                int componentCount = 0;
 0142                int entityCount = 0;
 0143                int materialCount = 0;
 0144                int meshesCount = 0;
 145
 0146                var loadedScenes = Environment.i.world.state.GetLoadedScenes();
 147
 0148                foreach (var v in loadedScenes)
 149                {
 0150                    ParcelScene scene = v.Value as ParcelScene;
 0151                    if (scene.metricsCounter != null)
 152                    {
 0153                        meshesCount += scene.metricsCounter.currentCount.meshes;
 0154                        materialCount += scene.metricsCounter.currentCount.materials;
 155                    }
 156
 0157                    sharedCount += scene.componentsManagerLegacy.GetSceneSharedComponentsDictionary().Count;
 158
 0159                    foreach (var e in scene.componentsManagerLegacy.GetSceneSharedComponentsDictionary())
 160                    {
 0161                        sharedAttachCount += e.Value.GetAttachedEntities().Count;
 162                    }
 163
 0164                    entityCount += scene.entities.Count;
 165
 0166                    foreach (var e in scene.entities)
 167                    {
 0168                        componentCount += scene.componentsManagerLegacy.GetComponentsDictionary(e.Value).Count;
 169                    }
 170                }
 171
 0172                statsPanel.SetCellText(1, (int) Rows.SHARED_OBJECTS_COUNT, sharedCount.ToString());
 0173                statsPanel.SetCellText(1, (int) Rows.COMPONENT_OBJECTS_COUNT, componentCount.ToString());
 0174                statsPanel.SetCellText(1, (int) Rows.ENTITY_OBJECTS_COUNT, entityCount.ToString());
 0175                statsPanel.SetCellText(1, (int) Rows.MATERIAL_COUNT, materialCount.ToString());
 0176                statsPanel.SetCellText(1, (int) Rows.MESHES_COUNT, meshesCount.ToString());
 0177                statsPanel.SetCellText(1, (int) Rows.AB_BEING_LOADED,
 178                    DataStore.i.performance.concurrentABRequests.Get() + " ...  In Queue: " +
 179                    AssetPromise_AB.queueCount);
 0180                statsPanel.SetCellText(1, (int) Rows.RENDERER_UNLOCK_SEGS,
 181                    RenderingController.firstActivationTime.ToString(CultureInfo.InvariantCulture));
 182
 0183                string busesLog = "";
 0184                Dictionary<string, int> pendingMessagesCount = new Dictionary<string, int>();
 0185                Dictionary<string, int> messagesReplaced = new Dictionary<string, int>();
 186
 0187                MessagingControllersManager messagingManager =
 188                    Environment.i.messaging.manager as MessagingControllersManager;
 189
 0190                using (var controllersIter = messagingManager.messagingControllers.GetEnumerator())
 191                {
 0192                    while (controllersIter.MoveNext())
 193                    {
 0194                        using (var iterator = controllersIter.Current.Value.messagingBuses.GetEnumerator())
 195                        {
 0196                            while (iterator.MoveNext())
 197                            {
 198                                //access to pair using iterator.Current
 0199                                MessagingBusType key = iterator.Current.Key;
 0200                                MessagingBus bus = controllersIter.Current.Value.messagingBuses[key];
 201
 0202                                string keyString = key.ToString();
 203
 0204                                if (!pendingMessagesCount.ContainsKey(keyString))
 0205                                    pendingMessagesCount[keyString] = 0;
 206
 0207                                if (!messagesReplaced.ContainsKey(keyString))
 0208                                    messagesReplaced[keyString] = 0;
 209
 0210                                pendingMessagesCount[keyString] += bus.pendingMessagesCount;
 0211                                messagesReplaced[keyString] += bus.unreliableMessagesReplaced;
 212                            }
 0213                        }
 214                    }
 0215                }
 216
 0217                busesLog +=
 218                    $"{MessagingBusType.UI.ToString()} bus: {pendingMessagesCount[MessagingBusType.UI.ToString()]} repla
 0219                busesLog +=
 220                    $"{MessagingBusType.INIT.ToString()} bus: {pendingMessagesCount[MessagingBusType.INIT.ToString()]} r
 0221                busesLog +=
 222                    $"{MessagingBusType.SYSTEM.ToString()} bus: {pendingMessagesCount[MessagingBusType.SYSTEM.ToString()
 223
 0224                statsPanel.SetCellText(1, (int) Rows.MESSAGE_BUSES, busesLog);
 225
 0226                yield return WaitForSecondsCache.Get(0.2f);
 227            }
 228        }
 229    }
 230}