| | 1 | | using System.Collections.Generic; |
| | 2 | | using System.Linq; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Interface; |
| | 5 | | using DCL.Models; |
| | 6 | | using DCL.SettingsCommon; |
| | 7 | | using UnityGLTF.Cache; |
| | 8 | | using UnityEngine; |
| | 9 | | using QualitySettings = DCL.SettingsCommon.QualitySettings; |
| | 10 | |
|
| | 11 | | namespace 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 | | { |
| | 19 | | CrashPayload result = new CrashPayload(); |
| | 20 | |
|
| | 21 | | ScenesDumper.Dump(allScenes, AssetPromiseKeeper_Texture.i.library, PersistentAssetCache.ImageCacheByUri, res |
| | 22 | | PoolManagerDumper.Dump(PoolManager.i, result ); |
| | 23 | | QualitySettingsDumper.Dump(Settings.i.qualitySettings.Data, result ); |
| | 24 | | GltfDumper.Dump( AssetPromiseKeeper_GLTF.i.library, result ); |
| | 25 | | AssetBundleDumper.Dump( AssetPromiseKeeper_AB.i.library, result ); |
| | 26 | | TextureDumper.Dump( AssetPromiseKeeper_Texture.i.library, PersistentAssetCache.ImageCacheByUri, result ); |
| | 27 | | PositionDumper.Dump( trackedMovements, trackedTeleports, result ); |
| | 28 | |
|
| | 29 | | 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 | | { |
| 0 | 187 | | var componentsDump = new List<ComponentsDump>(); |
| 0 | 188 | | var totalSceneLimits = new WebInterface.MetricsModel(); |
| | 189 | |
|
| 0 | 190 | | var loadedScenes = allScenes |
| | 191 | | .Select( x => |
| 0 | 192 | | new LoadedScenesDump |
| | 193 | | { |
| | 194 | | id = x.Key |
| | 195 | | } |
| | 196 | | ) |
| | 197 | | .ToList(); |
| | 198 | |
|
| | 199 | | // <class, count> |
| 0 | 200 | | Dictionary<int, int> sharedComponentsCount = new Dictionary<int, int>(); |
| 0 | 201 | | Dictionary<int, int> entityComponentsCount = new Dictionary<int, int>(); |
| | 202 | |
|
| 0 | 203 | | foreach ( var kvp in allScenes ) |
| | 204 | | { |
| 0 | 205 | | IParcelScene scene = kvp.Value; |
| | 206 | |
|
| | 207 | | // Sum operator is overloaded |
| 0 | 208 | | totalSceneLimits += scene.metricsCounter?.currentCount.ToMetricsModel(); |
| | 209 | |
|
| 0 | 210 | | loadedScenes.Add( new LoadedScenesDump |
| | 211 | | { |
| | 212 | | id = kvp.Key |
| | 213 | | } |
| | 214 | | ); |
| | 215 | |
|
| 0 | 216 | | foreach ( var kvpComponents in scene.disposableComponents ) |
| | 217 | | { |
| 0 | 218 | | int classId = kvpComponents.Value.GetClassId(); |
| | 219 | |
|
| 0 | 220 | | if ( !sharedComponentsCount.ContainsKey(classId) ) |
| 0 | 221 | | sharedComponentsCount.Add( classId, 0 ); |
| | 222 | |
|
| 0 | 223 | | sharedComponentsCount[classId]++; |
| | 224 | | } |
| | 225 | |
|
| 0 | 226 | | foreach ( var kvpEntities in kvp.Value.entities ) |
| | 227 | | { |
| 0 | 228 | | foreach ( var kvpComponents in kvpEntities.Value.components ) |
| | 229 | | { |
| 0 | 230 | | int classId = kvpComponents.Value.GetClassId(); |
| | 231 | |
|
| 0 | 232 | | if ( !entityComponentsCount.ContainsKey(classId) ) |
| 0 | 233 | | entityComponentsCount.Add( classId, 0 ); |
| | 234 | |
|
| 0 | 235 | | entityComponentsCount[classId]++; |
| | 236 | | } |
| | 237 | | } |
| | 238 | | } |
| | 239 | |
|
| 0 | 240 | | foreach ( var kvp in sharedComponentsCount ) |
| | 241 | | { |
| 0 | 242 | | componentsDump.Add( new ComponentsDump |
| | 243 | | { |
| | 244 | | type = ((CLASS_ID)kvp.Key).ToString(), |
| | 245 | | quantity = kvp.Value |
| | 246 | | } |
| | 247 | | ); |
| | 248 | | } |
| | 249 | |
|
| 0 | 250 | | foreach ( var kvp in entityComponentsCount ) |
| | 251 | | { |
| 0 | 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. |
| 0 | 261 | | totalSceneLimits.materials = PersistentAssetCache.MaterialCacheByCRC.Count; |
| 0 | 262 | | totalSceneLimits.textures = library.masterAssets.Count + textureData.Count; |
| | 263 | |
|
| 0 | 264 | | payload.fields.Add(CrashPayload.DumpLiterals.COMPONENTS, componentsDump.ToArray()); |
| 0 | 265 | | payload.fields.Add(CrashPayload.DumpLiterals.LOADED_SCENES, loadedScenes.ToArray()); |
| 0 | 266 | | payload.fields.Add(CrashPayload.DumpLiterals.TOTAL_SCENE_LIMITS, totalSceneLimits); |
| 0 | 267 | | } |
| | 268 | | } |
| | 269 | | } |