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