void SetupGroups() { ProgressBarDisplay.UpdateProgress(0.0f, "Setup groups ..."); for (Int32 snapshotIdx = 0; snapshotIdx < 2; ++snapshotIdx) { CachedSnapshot snapshot = m_Snapshots[snapshotIdx]; int managedObjectsOffset = 0; int managedObjectsCount = snapshot.SortedManagedObjects.Count; int nativeAllocationsOffset = 0; int nativeAllocationsCount = snapshot.SortedNativeAllocations.Count; int nativeObjectsOffset = 0; int nativeObjectsCount = snapshot.SortedNativeObjects.Count; m_GroupsMangedObj[snapshotIdx].Clear(); m_GroupsNativeAlloc[snapshotIdx].Clear(); m_GroupsNativeObj[snapshotIdx].Clear(); EntryRange range; for (int i = 0; i < m_Groups.Count; ++i) { if (i % 1000 == 0) { ProgressBarDisplay.UpdateProgress((float)i / (float)m_Groups.Count); } // Assigning Managed Objects Range while (managedObjectsOffset < managedObjectsCount && m_Groups[i].AddressBegin > snapshot.SortedManagedObjects.Address(managedObjectsOffset)) { managedObjectsOffset++; } range.Begin = managedObjectsOffset; while (managedObjectsOffset < managedObjectsCount && snapshot.SortedManagedObjects.Address(managedObjectsOffset) < m_Groups[i].AddressEnd) { managedObjectsOffset++; } range.End = managedObjectsOffset; m_GroupsMangedObj[snapshotIdx].Add(range); // Assigning Native Allocation Range while (nativeAllocationsOffset < nativeAllocationsCount && m_Groups[i].AddressBegin > snapshot.SortedNativeAllocations.Address(nativeAllocationsOffset)) { nativeAllocationsOffset++; } range.Begin = nativeAllocationsOffset; while (nativeAllocationsOffset < nativeAllocationsCount && snapshot.SortedNativeAllocations.Address(nativeAllocationsOffset) < m_Groups[i].AddressEnd) { nativeAllocationsOffset++; } range.End = nativeAllocationsOffset; m_GroupsNativeAlloc[snapshotIdx].Add(range); // Assigning Native Objects Range while (nativeObjectsOffset < nativeObjectsCount && m_Groups[i].AddressBegin > snapshot.SortedNativeObjects.Address(nativeObjectsOffset)) { nativeObjectsOffset++; } range.Begin = nativeObjectsOffset; while (nativeObjectsOffset < nativeObjectsCount && snapshot.SortedNativeObjects.Address(nativeObjectsOffset) < m_Groups[i].AddressEnd) { nativeObjectsOffset++; } range.End = nativeObjectsOffset; m_GroupsNativeObj[snapshotIdx].Add(range); } } ProgressBarDisplay.UpdateProgress(1.0f); }
public ManagedObjectMetric(CachedSnapshot snapshot, ManagedObjectInfo obj) { m_Snapshot = snapshot; m_Object = obj; }
public NativeObjectMetric(CachedSnapshot snapshot, int objectIndex) { m_Snapshot = snapshot; m_ObjectIndex = objectIndex; }
private void LoadAll() { m_IsReady = false; try { foreach (var filePath in m_List) { if (File.Exists(filePath)) { try { Debug.LogFormat("Loading \"{0}\"", filePath); var rawSnapshot = Unity.MemoryProfilerForExtension.Editor.Format.QueriedMemorySnapshot.Load(filePath); //var rawSnapshot = UnityEditor.Profiling.Memory.Experimental.PackedMemorySnapshot.Load(filePath); if (null == rawSnapshot) { Debug.LogErrorFormat("MemoryProfiler: Unrecognized memory snapshot format '{0}'.", filePath); } Debug.LogFormat("Completed loading \"{0}\"", filePath); Debug.LogFormat("Crawling \"{0}\"", filePath); ProgressBarDisplay.ShowBar(string.Format("Opening snapshot: {0}", System.IO.Path.GetFileNameWithoutExtension(filePath))); var cachedSnapshot = new CachedSnapshot(rawSnapshot); using (s_CrawlManagedData.Auto()) { var crawling = Crawler.Crawl(cachedSnapshot); crawling.MoveNext(); //start execution var status = crawling.Current as EnumerationStatus; float progressPerStep = 1.0f / status.StepCount; while (crawling.MoveNext()) { ProgressBarDisplay.UpdateProgress(status.CurrentStep * progressPerStep, status.StepStatus); } } ProgressBarDisplay.ClearBar(); var rawSchema = new RawSchema(); rawSchema.SetupSchema(cachedSnapshot, new ObjectDataFormatter()); var managedObjcts = rawSchema.GetTableByName("AllManagedObjects") as ObjectListTable; var nativeObjects = rawSchema.GetTableByName("AllNativeObjects") as ObjectListTable; Debug.LogFormat("Completed crawling \"{0}\"", filePath); Debug.LogFormat("Saving \"{0}\"", filePath); var path = Path.GetDirectoryName(filePath); var snapName = Path.GetFileNameWithoutExtension(filePath); string exportPath1 = Path.Combine(path, snapName + "_MANAGEDHEAP_SnapshotExport_" + CsLibrary.DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + ".csv"); if (!String.IsNullOrEmpty(exportPath1)) { System.IO.StreamWriter sw = new System.IO.StreamWriter(exportPath1); sw.WriteLine("Managed_Objects,Size,Address"); int ct = cachedSnapshot.SortedManagedHeapEntries.Count; for (int i = 0; i < ct; i++) { var size = cachedSnapshot.SortedManagedHeapEntries.Size(i); var addr = cachedSnapshot.SortedManagedHeapEntries.Address(i); sw.WriteLine("Managed," + size + "," + addr); ResourceProcessor.Instance.DisplayProgressBar("write managed heap ...", i, ct); } sw.Flush(); sw.Close(); } string exportPath2 = Path.Combine(path, snapName + "_MANAGED_SnapshotExport_" + CsLibrary.DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + ".csv"); if (!String.IsNullOrEmpty(exportPath2)) { m_ManagedGroups.Clear(); System.IO.StreamWriter sw = new System.IO.StreamWriter(exportPath2); sw.WriteLine("Index,Type,RefCount,Size,Address"); int ct = cachedSnapshot.SortedManagedObjects.Count; for (int i = 0; i < ct; i++) { var size = cachedSnapshot.SortedManagedObjects.Size(i); var addr = cachedSnapshot.SortedManagedObjects.Address(i); ManagedObjectInfo objInfo; int index = -1; int refCount = 0; string typeName = string.Empty; if (cachedSnapshot.CrawledData.MangedObjectIndexByAddress.TryGetValue(addr, out index)) { objInfo = cachedSnapshot.CrawledData.ManagedObjects[index]; index = objInfo.ManagedObjectIndex; refCount = objInfo.RefCount; if (objInfo.ITypeDescription >= 0 && objInfo.ITypeDescription < cachedSnapshot.typeDescriptions.Count) { typeName = cachedSnapshot.typeDescriptions.typeDescriptionName[objInfo.ITypeDescription]; } } sw.WriteLine("" + index + ",\"" + typeName + "\"," + refCount + "," + size + "," + addr); ManagedGroupInfo info; if (m_ManagedGroups.TryGetValue(typeName, out info)) { ++info.Count; info.Size += size; } else { string g = string.Empty; int si = typeName.IndexOf('.'); if (si > 0) { g = typeName.Substring(0, si); if (!s_ManagedGroupNames.Contains(g)) { g = string.Empty; } } info = new ManagedGroupInfo { Group = g, Type = typeName, Count = 1, Size = size }; m_ManagedGroups.Add(typeName, info); } if (i % 1000 == 0) { ResourceProcessor.Instance.DisplayProgressBar("write managed objects ...", i, ct); } } sw.Flush(); sw.Close(); string dir = Path.GetDirectoryName(exportPath2); string fn = Path.GetFileNameWithoutExtension(exportPath2); string gpath = Path.Combine(dir, fn + "_groups.csv"); var lastGroup = "A000000"; using (var outsw = new StreamWriter(gpath)) { outsw.WriteLine("group,type,count,size"); int curCt = 0; int totalCt = m_ManagedGroups.Count; foreach (var pair in m_ManagedGroups) { var info = pair.Value; var g = info.Group; if (!string.IsNullOrEmpty(lastGroup) && string.IsNullOrEmpty(info.Group)) { g = lastGroup + "__"; } if (!string.IsNullOrEmpty(info.Group)) { lastGroup = info.Group; } outsw.WriteLine("\"{0}\",\"{1}\",{2},{3}", g, info.Type, info.Count, info.Size); if (curCt % 100 == 0) { ResourceProcessor.Instance.DisplayProgressBar("write managed object group ...", curCt, totalCt); } ++curCt; } } string gpath2 = Path.Combine(dir, fn + "_groups_forcmp.csv"); using (var outsw = new StreamWriter(gpath2)) { outsw.WriteLine("type,count,size"); int curCt = 0; int totalCt = m_ManagedGroups.Count; foreach (var pair in m_ManagedGroups) { var info = pair.Value; outsw.WriteLine("\"{0}\",{1},{2}", info.Type, info.Count, info.Size); if (curCt % 100 == 0) { ResourceProcessor.Instance.DisplayProgressBar("write managed object group for cmp ...", curCt, totalCt); } ++curCt; } } } string exportPath = Path.Combine(path, snapName + "_NATIVE_SnapshotExport_" + CsLibrary.DateTime.Now.ToString("dd_MM_yyyy_hh_mm_ss") + ".csv"); if (!String.IsNullOrEmpty(exportPath)) { m_NativeGroups.Clear(); System.IO.StreamWriter sw = new System.IO.StreamWriter(exportPath); sw.WriteLine("Index,Name,Type,RefCount,InstanceID,Size,Address"); int ct = cachedSnapshot.SortedNativeObjects.Count; for (int i = 0; i < ct; i++) { var size = cachedSnapshot.SortedNativeObjects.Size(i); var addr = cachedSnapshot.SortedNativeObjects.Address(i); var name = cachedSnapshot.SortedNativeObjects.Name(i); var refCount = cachedSnapshot.SortedNativeObjects.Refcount(i); var instanceId = cachedSnapshot.SortedNativeObjects.InstanceId(i); int index; if (!cachedSnapshot.nativeObjects.instanceId2Index.TryGetValue(instanceId, out index)) { index = -1; } var nativeTypeIndex = cachedSnapshot.SortedNativeObjects.NativeTypeArrayIndex(i); string typeName = string.Empty; if (nativeTypeIndex >= 0 && nativeTypeIndex < cachedSnapshot.nativeTypes.Count) { typeName = cachedSnapshot.nativeTypes.typeName[nativeTypeIndex]; } sw.WriteLine("" + index + ",\"" + name + "\",\"" + typeName + "\"," + refCount + "," + instanceId + "," + size + "," + addr); NativeGroupInfo info; if (m_NativeGroups.TryGetValue(typeName, out info)) { ++info.Count; info.Size += size; } else { info = new NativeGroupInfo { Type = typeName, Count = 1, Size = size }; m_NativeGroups.Add(typeName, info); } if (i % 100 == 0) { ResourceProcessor.Instance.DisplayProgressBar("write native objects ...", i, ct); } } sw.Flush(); sw.Close(); string dir = Path.GetDirectoryName(exportPath); string fn = Path.GetFileNameWithoutExtension(exportPath); string gpath = Path.Combine(dir, fn + "_groups.csv"); using (var outsw = new StreamWriter(gpath)) { outsw.WriteLine("type,count,size"); int curCt = 0; int totalCt = m_NativeGroups.Count; foreach (var pair in m_NativeGroups) { var info = pair.Value; outsw.WriteLine("\"{0}\",{1},{2}", info.Type, info.Count, info.Size); ResourceProcessor.Instance.DisplayProgressBar("write native object group ...", curCt, totalCt); ++curCt; } } } Debug.LogFormat("Completed saving \"{0}\"", filePath); } catch (Exception ex) { UnityEngine.Debug.LogErrorFormat("file {0} exception {1}\n{2}", filePath, ex.Message, ex.StackTrace); } } } EditorUtility.ClearProgressBar(); } finally { m_IsReady = true; } }
public ObjectMetric(int objectIndex, CachedSnapshot cachedSnapshot, ObjectMetricType metricType) { MetricType = metricType; ObjectIndex = objectIndex; m_CachedSnapshot = cachedSnapshot; }
public TreeMapView(CachedSnapshot snapshot) { m_Snapshot = snapshot; }
string ITypeRenderer.Render(CachedSnapshot snapshot, ObjectData od) { return(od.managedObjectData.ReadUInt32().ToString()); }
public APITable(Schema schema, CachedSnapshot s, long dataCount) : base(schema) { m_Snapshot = s; m_DataSet = new Soa.SoaDataSet(dataCount, 4 * 1024); }
public APITable(Schema schema, CachedSnapshot s, Soa.SoaDataSet ds) : base(schema) { m_Snapshot = s; m_DataSet = ds; }
public ObjectAllManagedTable(Database.Schema schema, SnapshotObjectDataFormatter formatter, CachedSnapshot snapshot, ManagedData crawledData, ObjectMetaType metaType) : base(schema, formatter, snapshot, crawledData, metaType) { InitObjectList(); }
public ObjectArrayTable(Database.Schema schema, SnapshotObjectDataFormatter formatter, CachedSnapshot snapshot, ManagedData crawledData, ObjectData arrayData, ObjectMetaType metaType) : base(schema, formatter, snapshot, crawledData, metaType) { this.arrayData = arrayData; if (arrayData.isManaged) { arrayInfo = ArrayTools.GetArrayInfo(snapshot, arrayData.managedObjectData, arrayData.managedTypeIndex); } InitObjectList(); }
public ObjectReferenceTable(Database.Schema schema, SnapshotDataRenderer renderer, CachedSnapshot snapshot, ManagedData crawledData, ObjectData obj, ObjectMetaType metaType) : base(schema, renderer, snapshot, crawledData, metaType) { m_Object = obj; m_References = ObjectConnection.GetAllObjectConnectingTo(snapshot, obj); #if DEBUG_VALIDATION int toUnifiedIndex = m_Object.GetUnifiedObjectIndex(snapshot); var toManagedIndex = snapshot.UnifiedObjectIndexToManagedObjectIndex(toUnifiedIndex); for (int k = 0; k != m_References.Length; ++k) { var oFrom = m_References[k]; switch (oFrom.dataType) { case ObjectDataType.ReferenceArray: case ObjectDataType.ReferenceObject: case ObjectDataType.Value: if (oFrom.m_Parent != null) { oFrom = oFrom.m_Parent.obj; } break; } bool connectionFound = false; switch (oFrom.dataType) { case ObjectDataType.Global: { if (snapshot.HasGlobalConnection(toManagedIndex)) { connectionFound = true; } } break; case ObjectDataType.Type: { if (snapshot.HasManagedTypeConnection(oFrom.managedTypeIndex, toManagedIndex)) { connectionFound = true; } } break; case ObjectDataType.Array: case ObjectDataType.BoxedValue: case ObjectDataType.Object: { if (snapshot.HasObjectConnection(oFrom.GetUnifiedObjectIndex(snapshot), toUnifiedIndex)) { connectionFound = true; break; } } break; case ObjectDataType.NativeObject: { if (snapshot.HasObjectConnection(oFrom.GetUnifiedObjectIndex(snapshot), toUnifiedIndex)) { connectionFound = true; break; } } break; } if (!connectionFound) { UnityEngine.Debug.LogError("Connection not found, index =" + k); } } #endif InitObjectList(); }