void OnGUI() { if (GUILayout.Button("Take Snapshot")) { // 每次执行前先重置数据 ResetAllData(); // 获取快照回调 MemorySnapshot.OnSnapshotReceived += OnSnapshotReceived; // 请求获取内存快照 MemorySnapshot.RequestNewSnapshot(); } if (_snapshotInfo == null) { return; } _tabIndex = GUILayout.Toolbar(_tabIndex, new[] { "NativeObjects", "ManagedType" }); switch (_tabIndex) { case 0: DrawNativeUnityEngineObjectInfo(); break; case 1: break; default: Debug.LogError("Undefine tabIndex: " + _tabIndex); break; } }
protected override void Do_GUI() { GUI.SetNextControlName("LoginIPTextField"); var currentStr = GUILayout.TextField(_IPField, GUILayout.Width(100)); if (!_IPField.Equals(currentStr)) { _IPField = currentStr; } if (GUI.GetNameOfFocusedControl().Equals("LoginIPTextField") && _IPField.Equals(MemConst.RemoteIPDefaultText)) { _IPField = ""; } bool savedState = GUI.enabled; bool connected = /*NetManager.Instance != null && NetManager.Instance.IsConnected &&*/ MemUtil.IsProfilerConnectedRemotely; GUI.enabled = !connected; if (GUILayout.Button("Connect", GUILayout.Width(80))) { _connectPressed = true; } GUI.enabled = connected; if (GUILayout.Button("Take Snapshot", GUILayout.Width(100))) { MemorySnapshot.RequestNewSnapshot(); } GUI.enabled = savedState; GUILayout.Space(DrawIndicesGrid(300, 20)); }
protected override void Do_GUI() { if (GUILayout.Button("Take Snapshot", EditorStyles.toolbarButton, GUILayout.Width(120), GUILayout.Height(20))) { MemorySnapshot.RequestNewSnapshot(); } if (Event.current.type == EventType.Repaint) { _last = GUILayoutUtility.GetLastRect(); } GUILayout.Space(DrawIndicesGrid(_last.xMax + 20, _last.y)); }
void OnGUI() { Init(); EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); //string[] array3 = new string[] { "Editor", "F****r", "Sucker" }; if (GUILayout.Button(new GUIContent("Active Profler"), EditorStyles.toolbarDropDown)) { Rect titleRect2 = EditorGUILayout.GetControlRect(); titleRect2.y += EditorStyles.toolbarDropDown.fixedHeight; connectionGuids = ProfilerDriver.GetAvailableProfilers(); GUIContent[] guiContents = new GUIContent[connectionGuids.Length]; for (int i = 0; i < connectionGuids.Length; i++) { if (connectionGuids[i] == ProfilerDriver.connectedProfiler) { selectedIndex = i; } bool flag = ProfilerDriver.IsIdentifierConnectable(connectionGuids[i]); string text = ProfilerDriver.GetConnectionIdentifier(connectionGuids[i]); if (!flag) { text += " (Version mismatch)";//I don't know what this means... } guiContents[i] = new GUIContent(text); } EditorUtility.DisplayCustomMenu(titleRect2, guiContents, selectedIndex, OnSelectProfilerClick, null); } //EditorGUILayout.Popup(selectedIndex, array3, EditorStyles.toolbarPopup); if (GUILayout.Button("Take Sample: " + ProfilerDriver.GetConnectionIdentifier(ProfilerDriver.connectedProfiler), EditorStyles.toolbarButton)) { //ProfilerDriver.ClearAllFrames(); //ProfilerDriver.deepProfiling = true; ShowNotification(new GUIContent("Waiting for device...")); MemorySnapshot.RequestNewSnapshot(); } if (GUILayout.Button(new GUIContent("Clear Editor References", "Design for profile in editor.\nEditorUtility.UnloadUnusedAssetsImmediate() can be called."), EditorStyles.toolbarButton)) { ClearEditorReferences(); } GUILayout.FlexibleSpace(); //GUILayout.Space(5); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Save Snapshot", EditorStyles.toolbarButton)) { if (data.mSnapshot != null) { string filePath = EditorUtility.SaveFilePanel("Save Snapshot", null, "MemorySnapshot" + System.DateTime.Now.ToString("_MMdd_HHmm"), "memsnap"); if (!string.IsNullOrEmpty(filePath)) { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); using (Stream stream = File.Open(filePath, FileMode.Create)) { bf.Serialize(stream, data.mSnapshot); } } } else { Debug.LogWarning("No snapshot to save. Try taking a snapshot first."); } } if (GUILayout.Button("Load Snapshot", EditorStyles.toolbarButton)) { string filePath = EditorUtility.OpenFilePanel("Load Snapshot", null, "memsnap"); if (!string.IsNullOrEmpty(filePath)) { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); using (Stream stream = File.Open(filePath, FileMode.Open)) { IncomingSnapshot(bf.Deserialize(stream) as PackedMemorySnapshot); } } } GUILayout.FlexibleSpace(); if (GUILayout.Button("Save Snapshot as .txt", EditorStyles.toolbarButton)) { if (memoryRootNode != null) { string filePath = EditorUtility.SaveFilePanel("Save Snapshot as .txt", null, "Mindmap" + System.DateTime.Now.ToString("_MMdd_HHmm"), "txt"); if (!string.IsNullOrEmpty(filePath)) { SaveToMindMap(filePath); } } else { Debug.LogWarning("No snapshot to save. Try taking a snapshot first."); } } if (GUILayout.Button("Load Snapshot from .txt", EditorStyles.toolbarButton)) { string filePath = EditorUtility.OpenFilePanel("Load Snapshot from .txt", null, "txt"); if (!string.IsNullOrEmpty(filePath)) { LoadFromMindMap(filePath); } } canSaveDetails = GUILayout.Toggle(canSaveDetails, "saveDetails"); savedMinSize = EditorGUILayout.IntField("minSize", savedMinSize, EditorStyles.toolbarTextField); if (savedMinSize < 0) { savedMinSize = 0; } EditorGUILayout.EndHorizontal(); //Top tool bar end... EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); memoryFilters = EditorGUILayout.ObjectField(memoryFilters, typeof(MemoryFilterSettings), false) as MemoryFilterSettings; //if (GUILayout.Button(new GUIContent("Save as plist/xml", "TODO in the future..."), EditorStyles.toolbarButton)) //{ //} //if (GUILayout.Button(new GUIContent("Load plist/xml", "TODO in the future..."), EditorStyles.toolbarButton)) //{ //} GUILayout.FlexibleSpace(); GUILayout.Label(new GUIContent("[LastRefreshTime]" + lastRefreshTime.ToShortTimeString(), " enter / exit play mode or change a script,Unity has to reload the mono assemblies , and the GoProfilerWindow has to Refresh immediately")); if (GUILayout.Button(EditorGUIUtility.IconContent("TreeEditor.Refresh"), EditorStyles.toolbarButton, GUILayout.Width(30))) { IncomingSnapshot(data.mSnapshot); Repaint(); } EditorGUILayout.EndHorizontal(); if (!memoryFilters) { EditorGUILayout.HelpBox("Please Select a MemoryFilters object or load it from the .plist/.xml file", MessageType.Warning); } //TODO: handle the selected object. //EditorGUILayout.HelpBox("Watching Texture Detail Data is only for Editor.", MessageType.Warning, true); if (selectedObject != null && selectedObject.childList.Count == 0) { if (selectedObject != null && _prevInstance != selectedObject.instanceID) { objectField = EditorUtility.InstanceIDToObject(selectedObject.instanceID); _prevInstance = selectedObject.instanceID; //Selection.instanceIDs = new int[] { selectedObject.instanceID }; //Hide in inspector. } } if (objectField != null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Selected Object Info:"); EditorGUILayout.ObjectField(objectField, objectField.GetType(), true); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.LabelField("Can't instance object,maybe it was already released."); } //MemoryFilters end... Rect titleRect = EditorGUILayout.GetControlRect(); EditorGUI.DrawRect(titleRect, new Color(0.15f, 0.15f, 0.15f, 1)); EditorGUI.DrawRect(new Rect(titleRect.x + titleRect.width - 200, titleRect.y, 1, Screen.height), new Color(0.15f, 0.15f, 0.15f, 1)); EditorGUI.DrawRect(new Rect(titleRect.x + titleRect.width - 100, titleRect.y, 1, Screen.height), new Color(0.15f, 0.15f, 0.15f, 1)); GUI.Label(new Rect(titleRect.x, titleRect.y, titleRect.width - 200, titleRect.height), "Name", toolBarStyle); GUI.Label(new Rect(titleRect.x + titleRect.width - 175, titleRect.y, 50, titleRect.height), "Size", toolBarStyle); GUI.Label(new Rect(titleRect.x + titleRect.width - 75, titleRect.y, 50, titleRect.height), "RefCount", toolBarStyle); //Title bar end... scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); if (memoryRootNode != null && memoryRootNode.childList != null) { memoryRootNode.DrawGUI(0); } else { Init(); } GUILayout.EndScrollView(); //Contents end... //handle the select event to Repaint if (Event.current.type == EventType.mouseDown) { Repaint(); } }
// [MenuItem("性能分析/捕获快照和原生内存")] public static void CaptureWithNativeMemeory() { MemorySnapshot.OnSnapshotReceived += OnSnapshotCompleteForCrawling; MemorySnapshot.RequestNewSnapshot(); }
public static void Capture() { MemorySnapshot.OnSnapshotReceived += OnSnapshotComplete; MemorySnapshot.RequestNewSnapshot(); }
void OnGUI() { //if put these code to OnEnable function,the EditorStyles.boldLabel is null , and everything is wrong. //Debug.Log("ONGUI"); EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button("Take Sample: " + ProfilerDriver.GetConnectionIdentifier(ProfilerDriver.connectedProfiler), EditorStyles.toolbarButton)) { ProfilerDriver.ClearAllFrames(); ProfilerDriver.deepProfiling = true; MemorySnapshot.RequestNewSnapshot(); } if (GUILayout.Button(new GUIContent("Clear Editor References", "Design for profile in editor.\nEditorUtility.UnloadUnusedAssetsImmediate() can be called."), EditorStyles.toolbarButton)) { ClearEditorReferences(); } if (GUILayout.Button("Save Snapshot", EditorStyles.toolbarButton)) { if (data.mSnapshot != null) { string fileName = EditorUtility.SaveFilePanel("Save Snapshot", null, "MemorySnapshot", "memsnap"); if (!string.IsNullOrEmpty(fileName)) { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); using (Stream stream = File.Open(fileName, FileMode.Create)) { bf.Serialize(stream, data.mSnapshot); } } } else { UnityEngine.Debug.LogWarning("No snapshot to save. Try taking a snapshot first."); } } if (GUILayout.Button("Load Snapshot", EditorStyles.toolbarButton)) { string fileName = EditorUtility.OpenFilePanel("Load Snapshot", null, "memsnap"); if (!string.IsNullOrEmpty(fileName)) { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); using (Stream stream = File.Open(fileName, FileMode.Open)) { IncomingSnapshot(bf.Deserialize(stream) as PackedMemorySnapshot); } } } GUILayout.FlexibleSpace(); //showObjectInspector = EditorGUILayout.Toggle("Show In Inspector", showObjectInspector); //TODO EditorGUILayout.EndHorizontal(); //Top tool bar end... EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); memoryFilters = EditorGUILayout.ObjectField(memoryFilters, typeof(MemoryFilterSettings), false) as MemoryFilterSettings; if (GUILayout.Button(new GUIContent("Save as plist/xml", "TODO in the future..."), EditorStyles.toolbarButton)) { } if (GUILayout.Button(new GUIContent("Load plist/xml", "TODO in the future..."), EditorStyles.toolbarButton)) { } GUILayout.FlexibleSpace(); if (GUILayout.Button(EditorGUIUtility.IconContent("TreeEditor.Refresh"), EditorStyles.toolbarButton, GUILayout.Width(30))) { IncomingSnapshot(data.mSnapshot); Repaint(); } EditorGUILayout.EndHorizontal(); if (!memoryFilters) { EditorGUILayout.HelpBox("Please Select a MemoryFilters object or load it from the .plist/.xml file", MessageType.Warning); } //TODO: handle the selected object. //EditorGUILayout.HelpBox("Watching Texture Detail Data is only for Editor.", MessageType.Warning, true); if (selectedObject != null && selectedObject.childList.Count == 0) { if (selectedObject != null && _prevInstance != selectedObject.instanceID) { objectField = EditorUtility.InstanceIDToObject(selectedObject.instanceID); _prevInstance = selectedObject.instanceID; Selection.instanceIDs = new int[] { selectedObject.instanceID }; } } if (objectField != null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Selected Object Info:"); EditorGUILayout.ObjectField(objectField, objectField.GetType(), true); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.LabelField("Can't instance object,maybe it was already released."); } //MemoryFilters end... Rect titleRect = EditorGUILayout.GetControlRect(); EditorGUI.DrawRect(titleRect, new Color(0.15f, 0.15f, 0.15f, 1)); EditorGUI.DrawRect(new Rect(titleRect.x + titleRect.width - 200, titleRect.y, 1, Screen.height), new Color(0.15f, 0.15f, 0.15f, 1)); EditorGUI.DrawRect(new Rect(titleRect.x + titleRect.width - 100, titleRect.y, 1, Screen.height), new Color(0.15f, 0.15f, 0.15f, 1)); GUI.Label(new Rect(titleRect.x, titleRect.y, titleRect.width - 200, titleRect.height), "Name", toolBarStyle); GUI.Label(new Rect(titleRect.x + titleRect.width - 175, titleRect.y, 50, titleRect.height), "Size", toolBarStyle); GUI.Label(new Rect(titleRect.x + titleRect.width - 75, titleRect.y, 50, titleRect.height), "RefCount", toolBarStyle); //Title bar end... scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); if (memoryRootNode != null && memoryRootNode.childList != null) { memoryRootNode.DrawGUI(0); } else { Init(); } GUILayout.EndScrollView(); //Contents end... //handle the select event to Repaint if (Event.current.type == EventType.mouseDown) { Repaint(); } }