public void CleanDifSnapshot(CompareMode compareMode) { if (hasCleanedDifCompare) { return; } hasCleanedDifCompare = true; var memoryTypeList = memoryTypesLookup.list; for (int i = 0; i < memoryTypeList.Count; i++) { MemoryInstanceType memoryInstanceType = memoryTypeList.items[i].value; var instanceList = memoryInstanceType.instances.list; for (int j = 0; j < instanceList.Count; j++) { MemoryObject memoryObject = instanceList.items[j]; CompareResult sCompareResult = memoryObject.compareResult; for (int k = j + 1; k < instanceList.Count; k++) { MemoryObject comMemoryObject = instanceList.items[k]; if (comMemoryObject.compareResult == sCompareResult) { continue; } if (comMemoryObject.name == memoryObject.name) { instanceList.RemoveAt(k); instanceList.RemoveAt(j--); break; } } } if (instanceList.Count == 0) { memoryTypeList.RemoveAt(i--); } } memoryTypesLookup.Sort(compareMode); }
public void ScanMemory(CompareMode compareMode) { tStamp = Time.realtimeSinceStartup; var objects = Resources.FindObjectsOfTypeAll <UnityEngine.Object>(); for (int i = 0; i < objects.Length; i++) { UnityEngine.Object obj = objects[i]; Type type = obj.GetType(); string typeName = type.Name; MemoryInstanceType memoryType; if (!memoryTypesLookup.lookup.TryGetValue(typeName, out memoryType)) { memoryType = new MemoryInstanceType(type); memoryTypesLookup.Add(typeName, memoryType); } int instanceId = obj.GetInstanceID(); memoryType.instances.Add(instanceId, new MemoryObject(obj.name, instanceId, obj.hideFlags, Helper.IsPrefab(obj))); } memoryTypesLookup.Sort(compareMode); }
public static void CompareMemorySnapshots(MemorySnapshot s, MemorySnapshot d, MemorySnapshot difSnapshot, CompareResult compareResult) { var sMemoryTypesLookup = s.memoryTypesLookup; var dMemoryTypesLookup = d.memoryTypesLookup; var sList = sMemoryTypesLookup.list; // Compare s with d for (int i = 0; i < sList.Count; i++) { ItemHolder <string, MemoryInstanceType> item = sList.items[i]; MemoryInstanceType sMemoryInstanceType = item.value; MemoryInstanceType dMemoryInstanceType; MemoryInstanceType difMemoryInstanceType = null; string typeName = item.key; bool allSame = true; if (dMemoryTypesLookup.lookup.TryGetValue(typeName, out dMemoryInstanceType)) { // d Snapshot contains instance of item Type (could be all the same) FastSortedHashSet <int, MemoryObject> sInstances = sMemoryInstanceType.instances; HashSet <int> dInstancesLookup = dMemoryInstanceType.instances.lookup; FastList <MemoryObject> sInstanceList = sInstances.list; for (int j = 0; j < sInstanceList.Count; j++) { MemoryObject sMemoryObject = sInstanceList.items[j]; if (dInstancesLookup.Contains(sMemoryObject.instanceId)) { continue; } // Add when doesn't contain if (allSame) { allSame = false; if (!difSnapshot.memoryTypesLookup.lookup.TryGetValue(typeName, out difMemoryInstanceType)) { difMemoryInstanceType = new MemoryInstanceType(sMemoryInstanceType.type); difSnapshot.memoryTypesLookup.Add(typeName, difMemoryInstanceType); // DrawInfo info = GetObjectDrawInfo(difSnapshot.memoryLookup, typeName, true); } } difMemoryInstanceType.instances.Add(sMemoryObject.instanceId, new MemoryObject(sMemoryObject, compareResult)); } } else { // Add all instances difMemoryInstanceType = new MemoryInstanceType(sMemoryInstanceType.type); difSnapshot.memoryTypesLookup.Add(typeName, difMemoryInstanceType); // DrawInfo info = GetObjectDrawInfo(difSnapshot.memoryLookup, typeName, true); var sInstanceList = sMemoryInstanceType.instances.list; for (int j = 0; j < sInstanceList.Count; j++) { difMemoryInstanceType.instances.Add(sInstanceList.items[j].instanceId, new MemoryObject(sInstanceList.items[j], compareResult)); } } } }