< Summary

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

Metrics

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

File(s)

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