< Summary

Class:DCL.Helpers.QualitySettingsDumper
Assembly:CrashPayloadUtils
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/CrashPayloadUtils/CrashPayloadUtils.cs
Covered lines:0
Uncovered lines:2
Coverable lines:2
Total lines:278
Line coverage:0% (0 of 2)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Dump(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/CrashPayloadUtils/CrashPayloadUtils.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using DCL.Controllers;
 4using DCL.Interface;
 5using DCL.Models;
 6using DCL.SettingsCommon;
 7using UnityGLTF.Cache;
 8using UnityEngine;
 9using QualitySettings = DCL.SettingsCommon.QualitySettings;
 10
 11namespace DCL.Helpers
 12{
 13    public static class CrashPayloadUtils
 14    {
 15        public static CrashPayload ComputePayload(IEnumerable<KeyValuePair<int, IParcelScene>> allScenes,
 16            List<Vector3> trackedMovements,
 17            List<Vector3> trackedTeleports)
 18        {
 19            CrashPayload result = new CrashPayload();
 20
 21            ScenesDumper.Dump(allScenes, AssetPromiseKeeper_Texture.i.library, PersistentAssetCache.ImageCacheByUri,
 22                result);
 23            PoolManagerDumper.Dump(PoolManager.i, result);
 24            QualitySettingsDumper.Dump(Settings.i.qualitySettings.Data, result);
 25            GltfDumper.Dump(AssetPromiseKeeper_GLTF.i.library, result);
 26            AssetBundleDumper.Dump(AssetPromiseKeeper_AB.i.library, result);
 27            TextureDumper.Dump(AssetPromiseKeeper_Texture.i.library, PersistentAssetCache.ImageCacheByUri, result);
 28            PositionDumper.Dump(trackedMovements, trackedTeleports, result);
 29
 30            return result;
 31        }
 32    }
 33
 34    static class PositionDumper
 35    {
 36        public static void Dump(List<Vector3> movePositions, List<Vector3> teleportPositions, CrashPayload payload)
 37        {
 38            payload.fields.Add(CrashPayload.DumpLiterals.TRAIL, movePositions.ToArray());
 39            payload.fields.Add(CrashPayload.DumpLiterals.TELEPORTS, teleportPositions.ToArray());
 40        }
 41    }
 42
 43    static class GltfDumper
 44    {
 45        [System.Serializable]
 46        public struct AssetInfo
 47        {
 48            public string id;
 49        }
 50
 51        public static void Dump(AssetLibrary_GLTF library, CrashPayload payload)
 52        {
 53            var assets = new AssetInfo[library.masterAssets.Count];
 54
 55            var ids = library.masterAssets
 56                .Select(x =>
 57                    new AssetInfo()
 58                    {
 59                        id = x.Key.ToString()
 60                    })
 61                .ToArray();
 62
 63            payload.fields.Add(CrashPayload.DumpLiterals.GLTFS, ids);
 64        }
 65    }
 66
 67    static class AssetBundleDumper
 68    {
 69        [System.Serializable]
 70        public struct AssetInfo
 71        {
 72            public string id;
 73        }
 74
 75        public static void Dump(AssetLibrary_AB library, CrashPayload payload)
 76        {
 77            var assets = new AssetInfo[library.masterAssets.Count];
 78
 79            var ids = library.masterAssets
 80                .Select(x =>
 81                    new AssetInfo()
 82                    {
 83                        id = x.Key.ToString()
 84                    })
 85                .ToArray();
 86
 87            payload.fields.Add(CrashPayload.DumpLiterals.ASSET_BUNDLES, ids);
 88        }
 89    }
 90
 91    static class TextureDumper
 92    {
 93        public class TextureInfo
 94        {
 95            public string id;
 96            public float width;
 97            public float height;
 98            public int mipmaps;
 99            public string format;
 100            public int refCount;
 101        }
 102
 103        public static void Dump(AssetLibrary_Texture library, Dictionary<string, RefCountedTextureData> textureData,
 104            CrashPayload payload)
 105        {
 106            var apkData = library.masterAssets
 107                .Select(x =>
 108                    new TextureInfo()
 109                    {
 110                        id = x.Key.ToString(),
 111                        width = x.Value.asset.texture.width,
 112                        height = x.Value.asset.texture.height,
 113                        mipmaps = x.Value.asset.texture.mipmapCount,
 114                        format = x.Value.asset.texture.graphicsFormat.ToString(),
 115                        refCount = x.Value.referenceCount
 116                    });
 117
 118            var persistentCacheData = textureData
 119                .Select(x =>
 120                    new TextureInfo()
 121                    {
 122                        id = x.Key,
 123                        height = x.Value.Texture.width,
 124                        mipmaps = x.Value.Texture.mipmapCount,
 125                        format = x.Value.Texture.graphicsFormat.ToString(),
 126                        refCount = x.Value.RefCount
 127                    });
 128
 129            TextureInfo[] finalData = apkData.Union(persistentCacheData).ToArray();
 130
 131            payload.fields.Add(CrashPayload.DumpLiterals.TEXTURES, finalData);
 132        }
 133    }
 134
 135    static class QualitySettingsDumper
 136    {
 137        public static void Dump(QualitySettings settings, CrashPayload payload)
 138        {
 0139            payload.fields.Add(CrashPayload.DumpLiterals.QUALITY_SETTINGS, settings);
 0140        }
 141    }
 142
 143    static class PoolManagerDumper
 144    {
 145        [System.Serializable]
 146        public struct PoolInfo
 147        {
 148            public string id;
 149            public int used;
 150            public int unused;
 151        }
 152
 153        public static void Dump(PoolManager poolManager, CrashPayload payload)
 154        {
 155            PoolInfo[] pools = new PoolInfo[poolManager.pools.Count];
 156
 157            int index = 0;
 158
 159            foreach (KeyValuePair<object, Pool> pool in poolManager.pools)
 160            {
 161                pools[index] = new PoolInfo
 162                {
 163                    id = pool.Value.id.ToString(),
 164                    used = pool.Value.usedObjectsCount,
 165                    unused = pool.Value.unusedObjectsCount
 166                };
 167
 168                index++;
 169            }
 170
 171            payload.fields.Add(CrashPayload.DumpLiterals.POOL_MANAGER, pools);
 172        }
 173    }
 174
 175    static class ScenesDumper
 176    {
 177        [System.Serializable]
 178        public struct LoadedScenesDump
 179        {
 180            public int sceneNumber;
 181        }
 182
 183        [System.Serializable]
 184        public struct ComponentsDump
 185        {
 186            public string type;
 187            public int quantity;
 188        }
 189
 190        public static void Dump(IEnumerable<KeyValuePair<int, IParcelScene>> allScenes, AssetLibrary_Texture library,
 191            Dictionary<string, RefCountedTextureData> textureData, CrashPayload payload)
 192        {
 193            var componentsDump = new List<ComponentsDump>();
 194            var totalSceneLimits = new WebInterface.MetricsModel();
 195
 196            var loadedScenes = allScenes
 197                .Select(x =>
 198                    new LoadedScenesDump
 199                    {
 200                        sceneNumber = x.Key
 201                    }
 202                )
 203                .ToList();
 204
 205            // <class, count>
 206            Dictionary<int, int> sharedComponentsCount = new Dictionary<int, int>();
 207            Dictionary<int, int> entityComponentsCount = new Dictionary<int, int>();
 208
 209            foreach (var kvp in allScenes)
 210            {
 211                IParcelScene scene = kvp.Value;
 212
 213                // Sum operator is overloaded
 214                totalSceneLimits += scene.metricsCounter?.currentCount.ToMetricsModel();
 215
 216                loadedScenes.Add(new LoadedScenesDump
 217                    {
 218                        sceneNumber = kvp.Key
 219                    }
 220                );
 221
 222                foreach ( var kvpComponents in scene.componentsManagerLegacy.GetSceneSharedComponentsDictionary() )
 223                {
 224                    int classId = kvpComponents.Value.GetClassId();
 225
 226                    if (!sharedComponentsCount.ContainsKey(classId))
 227                        sharedComponentsCount.Add(classId, 0);
 228
 229                    sharedComponentsCount[classId]++;
 230                }
 231
 232                foreach (var kvpEntities in kvp.Value.entities)
 233                {
 234                    using (var iterator = scene.componentsManagerLegacy.GetComponents(kvpEntities.Value))
 235                    {
 236                        while (iterator.MoveNext())
 237                        {
 238                            int classId = iterator.Current.GetClassId();
 239
 240                            if ( !entityComponentsCount.ContainsKey(classId) )
 241                                entityComponentsCount.Add( classId, 0 );
 242
 243                            entityComponentsCount[classId]++;
 244                        }
 245                    }
 246                }
 247            }
 248
 249            foreach (var kvp in sharedComponentsCount)
 250            {
 251                componentsDump.Add(new ComponentsDump
 252                    {
 253                        type = ((CLASS_ID) kvp.Key).ToString(),
 254                        quantity = kvp.Value
 255                    }
 256                );
 257            }
 258
 259            foreach (var kvp in entityComponentsCount)
 260            {
 261                componentsDump.Add(new ComponentsDump
 262                    {
 263                        type = ((CLASS_ID_COMPONENT) kvp.Key).ToString(),
 264                        quantity = kvp.Value
 265                    }
 266                );
 267            }
 268
 269            // Materials and textures can be shared between scenes. They can't be inferred by adding up the metrics.
 270            totalSceneLimits.materials = PersistentAssetCache.MaterialCacheByCRC.Count;
 271            totalSceneLimits.textures = library.masterAssets.Count + textureData.Count;
 272
 273            payload.fields.Add(CrashPayload.DumpLiterals.COMPONENTS, componentsDump.ToArray());
 274            payload.fields.Add(CrashPayload.DumpLiterals.LOADED_SCENES, loadedScenes.ToArray());
 275            payload.fields.Add(CrashPayload.DumpLiterals.TOTAL_SCENE_LIMITS, totalSceneLimits);
 276        }
 277    }
 278}