void SetSnapshot(DataRenderer dataRenderer, PackedMemorySnapshot snapshot) { if (snapshot == null) { m_RawSnapshot = null; m_RawSchema = null; SchemaToDisplay = null; UpdateTableSelectionNames(); return; } m_RawSnapshot = snapshot; ProgressBarDisplay.ShowBar(string.Format("Opening snapshot: {0}", System.IO.Path.GetFileNameWithoutExtension(snapshot.filePath))); var cachedSnapshot = new CachedSnapshot(snapshot); using (Profiling.GetMarker(Profiling.MarkerId.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(); m_RawSchema = new RawSchema(); m_RawSchema.SetupSchema(cachedSnapshot, dataRenderer); SchemaToDisplay = m_RawSchema; if (k_DefaultViewFilePath.Length > 0) { using (ScopeDebugContext.Func(() => { return("File '" + k_DefaultViewFilePath + "'"); })) { Database.View.ViewSchema.Builder builder = null; using (Profiling.GetMarker(Profiling.MarkerId.LoadViewDefinitionFile).Auto()) { builder = Database.View.ViewSchema.Builder.LoadFromXMLFile(k_DefaultViewFilePath); } if (builder != null) { using (Profiling.GetMarker(Profiling.MarkerId.BuildViewDefinitionFile).Auto()) { ViewSchema = builder.Build(m_RawSchema); } if (ViewSchema != null) { SchemaToDisplay = ViewSchema; } } } } UpdateTableSelectionNames(); }
protected SnapshotMode(SnapshotMode copy) : base(copy) { m_RawSnapshot = copy.m_RawSnapshot; m_RawSchema = copy.m_RawSchema; ViewSchema = copy.ViewSchema; SchemaToDisplay = copy.SchemaToDisplay; m_RawSchema.renderer.m_BaseRenderer.PrettyNamesOptionChanged += UpdateTableSelectionNames; }
public override void Clear() { CurrentViewPane.OnClose(); SchemaToDisplay = null; m_RawSchema.Clear(); m_RawSchema = null; if (m_RawSnapshot != null) { m_RawSnapshot.Dispose(); } }
void SetSnapshot(ObjectDataFormatter objectDataFormatter, QueriedMemorySnapshot snapshot) { if (snapshot == null) { m_RawSnapshot = null; m_RawSchema = null; SchemaToDisplay = null; UpdateTableSelectionNames(); return; } m_RawSnapshot = snapshot; ProgressBarDisplay.ShowBar(string.Format("Opening snapshot: {0}", System.IO.Path.GetFileNameWithoutExtension(snapshot.GetReader().FilePath))); var cachedSnapshot = new CachedSnapshot(snapshot); 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(); m_RawSchema = new RawSchema(); m_RawSchema.SetupSchema(cachedSnapshot, objectDataFormatter); SchemaToDisplay = m_RawSchema; if (k_DefaultViewFilePath.Length > 0) { Database.View.ViewSchema.Builder builder = null; builder = Database.View.ViewSchema.Builder.LoadFromXMLFile(k_DefaultViewFilePath); if (builder != null) { ViewSchema = builder.Build(m_RawSchema); if (ViewSchema != null) { SchemaToDisplay = ViewSchema; } } } UpdateTableSelectionNames(); }
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; } }