void OnHeapReceivedSaveOnly(UnityEditor.MemoryProfiler.PackedMemorySnapshot snapshot) { UnityEditor.MemoryProfiler.MemorySnapshot.OnSnapshotReceived -= OnHeapReceivedSaveOnly; EditorUtility.DisplayProgressBar(HeGlobals.k_Title, "Saving memory...", 0.5f); try { var args = new MemorySnapshotProcessingArgs(); args.source = snapshot; args.excludeNativeFromConnections = excludeNativeFromConnections; var heap = PackedMemorySnapshot.FromMemoryProfiler(args); heap.SaveToFile(autoSavePath); HeMruFiles.AddPath(autoSavePath); ShowNotification(new GUIContent(string.Format("Memory snapshot saved as\n'{0}'", autoSavePath))); } catch { m_CloseDueToError = true; throw; } finally { m_IsCapturing = false; m_Repaint = true; EditorUtility.ClearProgressBar(); } }
void OnHeapReceivedSaveOnly(string path, bool captureResult) { EditorUtility.DisplayProgressBar(HeGlobals.k_Title, "Saving memory...", 0.5f); try { var args = new MemorySnapshotProcessingArgs(); args.source = UnityEditor.Profiling.Memory.Experimental.PackedMemorySnapshot.Load(path); var heap = PackedMemorySnapshot.FromMemoryProfiler(args); heap.SaveToFile(autoSavePath); HeMruFiles.AddPath(autoSavePath); ShowNotification(new GUIContent(string.Format("Memory snapshot saved as\n'{0}'", autoSavePath))); } catch { m_CloseDueToError = true; throw; } finally { m_IsCapturing = false; m_Repaint = true; EditorUtility.ClearProgressBar(); } }
void SaveToFile() { var path = EditorUtility.SaveFilePanel("Save", "", "memory", "heap"); if (string.IsNullOrEmpty(path)) { return; } HeMruFiles.AddPath(path); m_Heap.SaveToFile(path); snapshotPath = path; }
void DrawMRU() { if (HeMruFiles.count == 0) { return; } using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { GUILayout.Label("Recent", HeEditorStyles.heading2); using (var scrollView = new EditorGUILayout.ScrollViewScope(m_MruScrollPosition)) { m_MruScrollPosition = scrollView.scrollPosition; for (int n = 0, nend = HeMruFiles.count; n < nend; ++n) { using (new GUILayout.HorizontalScope()) { var path = HeMruFiles.GetPath(n); GUILayout.Label(string.Format("{0,2:##}", n + 1), GUILayout.Width(20)); if (GUILayout.Button(new GUIContent(HeEditorStyles.deleteImage, "Remove entry from list"), HeEditorStyles.iconStyle, GUILayout.Width(16), GUILayout.Height(16))) { HeMruFiles.RemovePath(path); break; } if (GUILayout.Button(new GUIContent(string.Format("{0}", path)), HeEditorStyles.hyperlink)) { window.LoadFromFile(path); } if (Event.current.type == EventType.Repaint) { EditorGUIUtility.AddCursorRect(GUILayoutUtility.GetLastRect(), MouseCursor.Link); } } } } } }
public void LoadFromFile(string path) { SaveView(); FreeMem(); HeMruFiles.AddPath(path); Reset(); m_Heap = null; if (useThreads) { var job = new LoadThreadJob { path = path, threadFunc = LoadFromFileThreaded }; ScheduleJob(job); } else { LoadFromFileThreaded(path); } }
void DrawToolbar() { using (new GUILayout.HorizontalScope(EditorStyles.toolbar, GUILayout.ExpandWidth(true))) { EditorGUI.BeginDisabledGroup(!m_GotoHistory.HasBack()); if (GUILayout.Button(new GUIContent(HeEditorStyles.backwardImage, "Navigate Backward"), EditorStyles.toolbarButton, GUILayout.Width(24))) { var cmd = m_GotoHistory.Back(); if (cmd != null) { GotoInternal(cmd, true); } } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(!m_GotoHistory.HasForward()); if (GUILayout.Button(new GUIContent(HeEditorStyles.forwardImage, "Navigate Forward"), EditorStyles.toolbarButton, GUILayout.Width(24))) { var cmd = m_GotoHistory.Forward(); if (cmd != null) { GotoInternal(cmd, false); } } EditorGUI.EndDisabledGroup(); if (GUILayout.Button("File", EditorStyles.toolbarDropDown, GUILayout.Width(60))) { var menu = new GenericMenu(); menu.AddItem(new GUIContent("Open..."), false, LoadFromFile); for (int n = 0; n < HeMruFiles.count; ++n) { var path = HeMruFiles.GetPath(n); if (string.IsNullOrEmpty(path)) { continue; } if (!System.IO.File.Exists(path)) { continue; } menu.AddItem(new GUIContent(string.Format("Recent/{0} {1}", (n + 1), path.Replace('/', '\\'))), false, delegate(System.Object obj) { var p = obj as string; LoadFromFile(p); }, path); } menu.AddSeparator("Recent/"); menu.AddItem(new GUIContent("Recent/Clear list"), false, delegate() { if (EditorUtility.DisplayDialog("Clear list...", "Do you want to clear the most recently used files list?", "Clear", "Cancel")) { HeMruFiles.RemoveAll(); } }); menu.AddSeparator(""); menu.AddItem(new GUIContent("Close Snapshot"), false, CloseFile); menu.AddSeparator(""); if (m_Heap == null) { menu.AddDisabledItem(new GUIContent("Save as...")); } else { menu.AddItem(new GUIContent("Save as..."), false, SaveToFile); } menu.AddSeparator(""); menu.AddItem(new GUIContent("New Window"), false, delegate() { var wnd = EditorWindow.CreateInstance <HeapExplorerWindow>(); wnd.Show(); }); menu.AddSeparator(""); menu.AddItem(new GUIContent("Settings/Use Multi-Threading"), useThreads, delegate() { useThreads = !useThreads; }); menu.AddItem(new GUIContent("Settings/Debug View Menu"), debugViewMenu, delegate() { debugViewMenu = !debugViewMenu; }); menu.AddItem(new GUIContent("Settings/Exclude NativeObject connections when capturing a snapshot (experimental)"), excludeNativeFromConnections, delegate() { excludeNativeFromConnections = !excludeNativeFromConnections; }); menu.AddItem(new GUIContent("Settings/Ignore nested structs (workaround for bug Case 1104590)"), ignoreNestedStructs, delegate() { ignoreNestedStructs = !ignoreNestedStructs; }); menu.AddItem(new GUIContent("Settings/Show unaligned memory sections (removes MonoMemPool sections)"), showInternalMemorySections, delegate() { showInternalMemorySections = !showInternalMemorySections; }); menu.DropDown(m_FileToolbarButtonRect); } if (Event.current.type == EventType.Repaint) { m_FileToolbarButtonRect = GUILayoutUtility.GetLastRect(); } EditorGUI.BeginDisabledGroup(m_Heap == null || m_Heap.isBusy); if (GUILayout.Button("View", EditorStyles.toolbarDropDown, GUILayout.Width(60))) { m_Views.Sort(delegate(HeapExplorerView x, HeapExplorerView y) { var value = x.viewMenuOrder.CompareTo(y.viewMenuOrder); if (value == 0) { value = string.Compare(x.titleContent.text, y.titleContent.text); } return(value); }); var prevOrder = -1; var menu = new GenericMenu(); foreach (var view in m_Views) { if (view.viewMenuOrder < 0) { continue; } if (prevOrder == -1) { prevOrder = view.viewMenuOrder; } var p0 = prevOrder / 100; var p1 = view.viewMenuOrder / 100; if (p1 - p0 >= 1) { var i = view.titleContent.text.LastIndexOf("/"); if (i == -1) { menu.AddSeparator(""); } else { menu.AddSeparator(view.titleContent.text.Substring(0, i)); } } prevOrder = view.viewMenuOrder; var c = new GUIContent(view.titleContent); if (debugViewMenu) { c.text = string.Format("{2} [viewMenuOrder={0}, type={1}]", view.viewMenuOrder, view.GetType().Name, c.text); } menu.AddItem(c, m_ActiveView == view, (GenericMenu.MenuFunction2) delegate(System.Object o) { if (o == m_ActiveView) { return; } var v = o as HeapExplorerView; var c0 = m_ActiveView.GetRestoreCommand(); c0.fromView = m_ActiveView; var c1 = v.GetRestoreCommand(); c1.toView = v; m_GotoHistory.Add(c0, c1); ActivateView(v); }, view); } menu.DropDown(m_ViewToolbarButtonRect); } if (Event.current.type == EventType.Repaint) { m_ViewToolbarButtonRect = GUILayoutUtility.GetLastRect(); } EditorGUI.EndDisabledGroup(); var connectedProfiler = UnityEditorInternal.ProfilerDriver.GetConnectionIdentifier(UnityEditorInternal.ProfilerDriver.connectedProfiler); if (GUILayout.Button(new GUIContent("Capture", HeEditorStyles.magnifyingGlassImage), EditorStyles.toolbarDropDown, GUILayout.Width(80))) { var menu = new GenericMenu(); menu.AddItem(new GUIContent(string.Format("Capture and Save '{0}'...", connectedProfiler)), false, CaptureAndSaveHeap); menu.AddItem(new GUIContent(string.Format("Capture and Analyze '{0}'", connectedProfiler)), false, CaptureAndAnalyzeHeap); menu.AddSeparator(""); menu.AddItem(new GUIContent(string.Format("Open Profiler")), false, delegate() { HeEditorUtility.OpenProfiler(); }); menu.DropDown(m_CaptureToolbarButtonRect); } if (Event.current.type == EventType.Repaint) { m_CaptureToolbarButtonRect = GUILayoutUtility.GetLastRect(); } if (m_ActiveView != null) { m_ActiveView.OnToolbarGUI(); } } }
public override void OnGUI() { base.OnGUI(); using (new EditorGUILayout.HorizontalScope()) { using (new EditorGUILayout.VerticalScope()) { using (new EditorGUILayout.VerticalScope(HeEditorStyles.panel)) { using (new EditorGUILayout.HorizontalScope()) { EditorGUILayout.LabelField("Compare Snapshot (A) with (B)", EditorStyles.boldLabel); if (m_CompareSearchField.OnToolbarGUI()) { m_CompareControl.Search(m_CompareSearchField.text); } } GUILayout.Space(2); using (new EditorGUILayout.HorizontalScope()) { if (GUILayout.Button(new GUIContent("Swap", "Swap snapshot A <> B"), GUILayout.Width(64), GUILayout.ExpandHeight(true))) { SwapSnapshots(); } using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox)) { using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label("(A)", GUILayout.Width(24)); if (!string.IsNullOrEmpty(window.snapshotPath)) { if (window.snapshotPath.EndsWith(".heap", System.StringComparison.OrdinalIgnoreCase)) { GUILayout.Label(System.IO.Path.GetFileName(window.snapshotPath)); } else { GUILayout.Label(window.snapshotPath); } } GUILayout.FlexibleSpace(); } using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label("(B)", GUILayout.Width(24)); if (!string.IsNullOrEmpty(m_SnapshotBPath)) { if (m_SnapshotBPath.EndsWith(".heap", System.StringComparison.OrdinalIgnoreCase)) { GUILayout.Label(System.IO.Path.GetFileName(m_SnapshotBPath)); } else { GUILayout.Label(m_SnapshotBPath); } } if (GUILayout.Button(new GUIContent("Load...", "Load snapshot (B)"), GUILayout.Width(64))) { var menu = new GenericMenu(); menu.AddItem(new GUIContent("Browse..."), false, delegate() { var path = EditorUtility.OpenFilePanel("Load", "", "heap"); if (!string.IsNullOrEmpty(path)) { HeMruFiles.AddPath(path); LoadSnapshotB(path); } }); menu.AddSeparator(""); for (int n = 0; n < HeMruFiles.count; ++n) { var path = HeMruFiles.GetPath(n); if (string.IsNullOrEmpty(path)) { continue; } if (!System.IO.File.Exists(path)) { continue; } menu.AddItem(new GUIContent((n + 1) + " " + path.Replace('/', '\\')), false, delegate(System.Object obj) { var p = obj as string; HeMruFiles.AddPath(p); LoadSnapshotB(p); }, path); } menu.ShowAsContext(); } GUILayout.FlexibleSpace(); } GUILayout.Space(2); } } GUILayout.Space(2); m_CompareControl.OnGUI(); } } } if (m_Job != null) { window.SetBusy(m_Job.stateString); Repaint(); } }
protected override void OnShow() { base.OnShow(); HeMruFiles.Load(); }