< 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:222
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;
 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 = Environment.i.messaging.manager as MessagingControllersManage
 120
 0121            int messagesProcessedLastFrame = lastPendingMessages - messagingManager.pendingMessagesCount;
 122
 0123            if (messagesProcessedLastFrame > 0)
 124            {
 0125                sampleCount++;
 0126                mps += 1 / (Time.deltaTime / messagesProcessedLastFrame);
 0127                statsPanel.SetCellText(1, (int) Rows.MESSAGES_PER_SECOND_REAL, (mps / sampleCount).ToString(CultureInfo.
 128            }
 129
 0130            lastPendingMessages = messagingManager.pendingMessagesCount;
 0131        }
 132
 133        private IEnumerator RefreshProfilingData()
 134        {
 0135            while (true)
 136            {
 0137                int sharedCount = 0;
 0138                int sharedAttachCount = 0;
 0139                int componentCount = 0;
 0140                int entityCount = 0;
 0141                int materialCount = 0;
 0142                int meshesCount = 0;
 143
 0144                var loadedScenes = Environment.i.world.state.loadedScenes;
 145
 0146                foreach (var v in loadedScenes)
 147                {
 0148                    ParcelScene scene = v.Value as ParcelScene;
 0149                    if (scene.metricsCounter != null)
 150                    {
 0151                        meshesCount += scene.metricsCounter.GetModel().meshes;
 0152                        materialCount += scene.metricsCounter.GetModel().materials;
 153                    }
 154
 0155                    sharedCount += scene.disposableComponents.Count;
 156
 0157                    foreach (var e in scene.disposableComponents)
 158                    {
 0159                        sharedAttachCount += e.Value.GetAttachedEntities().Count;
 160                    }
 161
 0162                    entityCount += scene.entities.Count;
 163
 0164                    foreach (var e in scene.entities)
 165                    {
 0166                        componentCount += e.Value.components.Count;
 167                    }
 168                }
 169
 0170                statsPanel.SetCellText(1, (int) Rows.SHARED_OBJECTS_COUNT, sharedCount.ToString());
 0171                statsPanel.SetCellText(1, (int) Rows.COMPONENT_OBJECTS_COUNT, componentCount.ToString());
 0172                statsPanel.SetCellText(1, (int) Rows.ENTITY_OBJECTS_COUNT, entityCount.ToString());
 0173                statsPanel.SetCellText(1, (int) Rows.MATERIAL_COUNT, materialCount.ToString());
 0174                statsPanel.SetCellText(1, (int) Rows.MESHES_COUNT, meshesCount.ToString());
 0175                statsPanel.SetCellText(1, (int) Rows.GLTF_BEING_LOADED, UnityGLTF.GLTFComponent.downloadingCount.ToStrin
 0176                statsPanel.SetCellText(1, (int) Rows.AB_BEING_LOADED, AssetPromise_AB.downloadingCount.ToString() + " ..
 0177                statsPanel.SetCellText(1, (int) Rows.RENDERER_UNLOCK_SEGS, RenderingController.firstActivationTime.ToStr
 178
 0179                string busesLog = "";
 0180                Dictionary<string, int> pendingMessagesCount = new Dictionary<string, int>();
 0181                Dictionary<string, int> messagesReplaced = new Dictionary<string, int>();
 182
 0183                MessagingControllersManager messagingManager = Environment.i.messaging.manager as MessagingControllersMa
 184
 0185                using (var controllersIter = messagingManager.messagingControllers.GetEnumerator())
 186                {
 0187                    while (controllersIter.MoveNext())
 188                    {
 0189                        using (var iterator = controllersIter.Current.Value.messagingBuses.GetEnumerator())
 190                        {
 0191                            while (iterator.MoveNext())
 192                            {
 193                                //access to pair using iterator.Current
 0194                                MessagingBusType key = iterator.Current.Key;
 0195                                MessagingBus bus = controllersIter.Current.Value.messagingBuses[key];
 196
 0197                                string keyString = key.ToString();
 198
 0199                                if (!pendingMessagesCount.ContainsKey(keyString))
 0200                                    pendingMessagesCount[keyString] = 0;
 201
 0202                                if (!messagesReplaced.ContainsKey(keyString))
 0203                                    messagesReplaced[keyString] = 0;
 204
 0205                                pendingMessagesCount[keyString] += bus.pendingMessagesCount;
 0206                                messagesReplaced[keyString] += bus.unreliableMessagesReplaced;
 207                            }
 0208                        }
 209                    }
 0210                }
 211
 0212                busesLog += $"{MessagingBusType.UI.ToString()} bus: {pendingMessagesCount[MessagingBusType.UI.ToString()
 0213                busesLog += $"{MessagingBusType.INIT.ToString()} bus: {pendingMessagesCount[MessagingBusType.INIT.ToStri
 0214                busesLog += $"{MessagingBusType.SYSTEM.ToString()} bus: {pendingMessagesCount[MessagingBusType.SYSTEM.To
 215
 0216                statsPanel.SetCellText(1, (int) Rows.MESSAGE_BUSES, busesLog);
 217
 0218                yield return WaitForSecondsCache.Get(0.2f);
 219            }
 220        }
 221    }
 222}