< Summary

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

Metrics

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

File(s)

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

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using System.Linq;
 4using DCL;
 5using DCL.Controllers;
 6using DCL.Interface;
 7using DCL.Models;
 8using DCL.SettingsData;
 9using UnityGLTF.Cache;
 10using UnityEngine;
 11
 12namespace DCL.Helpers
 13{
 14    public static class CrashPayloadUtils
 15    {
 16        public static CrashPayload ComputePayload(Dictionary<string, IParcelScene> allScenes,
 17            List<Vector3> trackedMovements,
 18            List<Vector3> trackedTeleports)
 19        {
 20            CrashPayload result = new CrashPayload();
 21
 22            ScenesDumper.Dump(allScenes, AssetPromiseKeeper_Texture.i.library, PersistentAssetCache.ImageCacheByUri, res
 23            PoolManagerDumper.Dump(PoolManager.i, result );
 24            QualitySettingsDumper.Dump(Settings.i.currentQualitySettings, 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        {
 077            var assets = new AssetInfo[ library.masterAssets.Count ];
 78
 079            var ids = library.masterAssets
 80                .Select( x =>
 081                    new AssetInfo()
 82                    {
 83                        id = x.Key.ToString()
 84                    } )
 85                .ToArray();
 86
 087            payload.fields.Add( CrashPayload.DumpLiterals.ASSET_BUNDLES, ids );
 088        }
 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, Cra
 104        {
 105            var apkData = library.masterAssets
 106                .Select( x =>
 107                    new TextureInfo()
 108                    {
 109                        id = x.Key.ToString(),
 110                        width = x.Value.asset.texture.width,
 111                        height = x.Value.asset.texture.height,
 112                        mipmaps = x.Value.asset.texture.mipmapCount,
 113                        format = x.Value.asset.texture.graphicsFormat.ToString(),
 114                        refCount = x.Value.referenceCount
 115                    } );
 116
 117            var persistentCacheData = textureData
 118                .Select( x =>
 119                    new TextureInfo()
 120                    {
 121                        id = x.Key,
 122                        height = x.Value.Texture.width,
 123                        mipmaps = x.Value.Texture.mipmapCount,
 124                        format = x.Value.Texture.graphicsFormat.ToString(),
 125                        refCount = x.Value.RefCount
 126                    } );
 127
 128            TextureInfo[] finalData = apkData.Union( persistentCacheData ).ToArray();
 129
 130            payload.fields.Add( CrashPayload.DumpLiterals.TEXTURES, finalData );
 131        }
 132    }
 133
 134    static class QualitySettingsDumper
 135    {
 136        public static void Dump(DCL.SettingsData.QualitySettings settings, CrashPayload payload) { payload.fields.Add( C
 137    }
 138
 139    static class PoolManagerDumper
 140    {
 141        [System.Serializable]
 142        public struct PoolInfo
 143        {
 144            public string id;
 145            public int used;
 146            public int unused;
 147        }
 148
 149        public static void Dump(PoolManager poolManager, CrashPayload payload)
 150        {
 151            PoolInfo[] pools = new PoolInfo[ poolManager.pools.Count ];
 152
 153            int index = 0;
 154
 155            foreach ( KeyValuePair<object, Pool> pool in poolManager.pools )
 156            {
 157                pools[index] = new PoolInfo
 158                {
 159                    id = pool.Value.id.ToString(),
 160                    used = pool.Value.usedObjectsCount,
 161                    unused = pool.Value.unusedObjectsCount
 162                };
 163
 164                index++;
 165            }
 166
 167            payload.fields.Add( CrashPayload.DumpLiterals.POOL_MANAGER, pools );
 168        }
 169    }
 170
 171    static class ScenesDumper
 172    {
 173        [System.Serializable]
 174        public struct LoadedScenesDump
 175        {
 176            public string id;
 177        }
 178
 179        [System.Serializable]
 180        public struct ComponentsDump
 181        {
 182            public string type;
 183            public int quantity;
 184        }
 185
 186        public static void Dump(Dictionary<string, IParcelScene> allScenes, AssetLibrary_Texture library, Dictionary<str
 187        {
 188            var componentsDump = new List<ComponentsDump>();
 189            var totalSceneLimits = new WebInterface.MetricsModel();
 190
 191            var loadedScenes = allScenes
 192                .Select( x =>
 193                    new LoadedScenesDump
 194                    {
 195                        id = x.Key
 196                    }
 197                )
 198                .ToList();
 199
 200            // <class, count>
 201            Dictionary<int, int> sharedComponentsCount = new Dictionary<int, int>();
 202            Dictionary<int, int> entityComponentsCount = new Dictionary<int, int>();
 203
 204            foreach ( var kvp in allScenes )
 205            {
 206                IParcelScene scene = kvp.Value;
 207
 208                // Sum operator is overloaded
 209                totalSceneLimits += scene.metricsController.GetModel().ToMetricsModel();
 210
 211                loadedScenes.Add( new LoadedScenesDump
 212                    {
 213                        id = kvp.Key
 214                    }
 215                );
 216
 217                foreach ( var kvpComponents in scene.disposableComponents )
 218                {
 219                    int classId = kvpComponents.Value.GetClassId();
 220
 221                    if ( !sharedComponentsCount.ContainsKey(classId) )
 222                        sharedComponentsCount.Add( classId, 0 );
 223
 224                    sharedComponentsCount[classId]++;
 225                }
 226
 227                foreach ( var kvpEntities in kvp.Value.entities )
 228                {
 229                    foreach ( var kvpComponents in kvpEntities.Value.components )
 230                    {
 231                        int classId = kvpComponents.Value.GetClassId();
 232
 233                        if ( !entityComponentsCount.ContainsKey(classId) )
 234                            entityComponentsCount.Add( classId, 0 );
 235
 236                        entityComponentsCount[classId]++;
 237                    }
 238                }
 239            }
 240
 241            foreach ( var kvp in sharedComponentsCount )
 242            {
 243                componentsDump.Add( new ComponentsDump
 244                    {
 245                        type = ((CLASS_ID)kvp.Key).ToString(),
 246                        quantity = kvp.Value
 247                    }
 248                );
 249            }
 250
 251            foreach ( var kvp in entityComponentsCount )
 252            {
 253                componentsDump.Add( new ComponentsDump
 254                    {
 255                        type = ((CLASS_ID_COMPONENT)kvp.Key).ToString(),
 256                        quantity = kvp.Value
 257                    }
 258                );
 259            }
 260
 261            // Materials and textures can be shared between scenes. They can't be inferred by adding up the metrics.
 262            totalSceneLimits.materials = PersistentAssetCache.MaterialCacheByCRC.Count;
 263            totalSceneLimits.textures = library.masterAssets.Count + textureData.Count;
 264
 265            payload.fields.Add(CrashPayload.DumpLiterals.COMPONENTS, componentsDump.ToArray());
 266            payload.fields.Add(CrashPayload.DumpLiterals.LOADED_SCENES, loadedScenes.ToArray());
 267            payload.fields.Add(CrashPayload.DumpLiterals.TOTAL_SCENE_LIMITS, totalSceneLimits);
 268        }
 269    }
 270}