Exemple #1
0
        void OnGUI()
        {
            try
            {
                if (Event.current.type == EventType.ExecuteCommand && Event.current.commandName.Equals("AppStarted"))
                {
                    InitNet();

                    var curMode = _modeMgr.GetCurrentMode();
                    if (curMode != null)
                    {
                        curMode.OnAppStarted();
                    }
                }

                _modeMgr.OnGUI();

                // view bar
                //GUILayout.BeginArea(new Rect(0, MemConst.TopBarHeight, position.width - MemConst.InspectorWidth, 30));
                //GUILayout.BeginHorizontal(MemStyles.Toolbar);
                //int selected = GUILayout.SelectionGrid((int)m_selectedView, MemConst.ShowTypes, MemConst.ShowTypes.Length, MemStyles.ToolbarButton);
                //if (m_selectedView != (eShowType)selected)
                //{
                //    m_selectedView = (eShowType)selected;
                //    RefreshView();
                //}
                //GUILayout.EndHorizontal();
                //GUILayout.EndArea();

                // selected view
                float yoffset = MemConst.TopBarHeight /*+ 30*/; // view bar is temporarily disabled
                Rect  view    = new Rect(0f, yoffset, position.width - MemConst.InspectorWidth, position.height - yoffset);
                switch (m_selectedView)
                {
                case eShowType.InTable:
                    if (_tableBrowser != null)
                    {
                        _tableBrowser.Draw(view);
                    }
                    break;

                case eShowType.InTreemap:
                    if (_treeMapView != null)
                    {
                        _treeMapView.Draw(view);
                    }
                    break;

                default:
                    break;
                }

                if (_inspector != null)
                {
                    _inspector.Draw();
                }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
        void OnGUI()
        {
            try
            {
                if (Event.current.type == EventType.ExecuteCommand && Event.current.commandName.Equals("AppStarted"))
                {
                    InitNet();

                    var curMode = _modeMgr.GetCurrentMode();
                    if (curMode != null)
                    {
                        curMode.OnAppStarted();
                    }
                }

                _modeMgr.OnGUI();

                // view bar
                GUILayout.BeginHorizontal(MemStyles.Toolbar);
                GUI.backgroundColor = Color.cyan;
                int selected = GUILayout.SelectionGrid((int)m_selectedView, MemConst.ShowTypes, MemConst.ShowTypes.Length, MemStyles.ToolbarButton);
                if (m_selectedView != (eShowType)selected)
                {
                    m_selectedView = (eShowType)selected;
                    RefreshView();
                }
                GUI.backgroundColor = Color.white;
                GUILayout.EndHorizontal();

                // selected view
                float yoffset = MemConst.TopBarHeight /*+ 30*/; // view bar is temporarily disabled
                Rect  view    = new Rect(0f, yoffset, position.width - MemConst.InspectorWidth, position.height - yoffset);
                switch (m_selectedView)
                {
                case eShowType.InTable:
                    if (_tableBrowser != null)
                    {
                        if (Event.current.type == EventType.KeyDown)
                        {
                            if (Event.current.keyCode == KeyCode.UpArrow)
                            {
                                _tableBrowser.MoveSelectItem(-1);
                            }
                            else if (Event.current.keyCode == KeyCode.DownArrow)
                            {
                                _tableBrowser.MoveSelectItem(1);
                            }
                            else if (Event.current.keyCode == KeyCode.RightArrow || Event.current.keyCode == KeyCode.LeftArrow)
                            {
                                _tableBrowser.ChangeSelectTable();
                            }
                        }
                        _tableBrowser.Draw(view);
                    }
                    break;

                case eShowType.InTreemap:
                    if (_treeMapView != null)
                    {
                        _treeMapView.Draw(view);
                    }
                    break;

                default:
                    break;
                }

                if (_inspector != null)
                {
                    _inspector.Draw();
                }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
        void OnGUI()
        {
            handleCommandEvent();
            // main bar
            GUILayout.BeginHorizontal();
            int connectedIndex = GUI.SelectionGrid(new Rect(0, 0, 180, 20), (int)_selectedProfilerMode, _ConnectedOptions, _ConnectedOptions.Length, MemStyles.ToolbarButton);

            if (connectedIndex != (int)_selectedProfilerMode)
            {
                _isRemoteConnected = false;

                if (_SnapshotChunks.Count > 0 &&
                    !_snapshotIOperator.isSaved(_SnapshotChunks.Count, _selectedProfilerMode, lastLoginIP) &&
                    !switchProfilerModeDialog())
                {
                }
                else
                {
                    clearSnapshotChunk();
                    _selectedProfilerMode = (eProfilerMode)connectedIndex;

                    if (_selectedProfilerMode == (int)eProfilerMode.Editor)
                    {
                        connectEditor();
                    }
                }
            }

            GUILayout.Space(200);
            drawProfilerModeGUI();
            if (GUILayout.Button("Open Dir", GUILayout.MaxWidth(100)))
            {
                EditorUtility.RevealInFinder(MemUtil.SnapshotsDir);
            }
            GUILayout.EndHorizontal();

            // view bar
            GUILayout.BeginArea(new Rect(0, MemConst.TopBarHeight, position.width - MemConst.InspectorWidth, 30));
            GUILayout.BeginHorizontal(MemStyles.Toolbar);
            int selected = GUILayout.SelectionGrid((int)m_selectedView, MemConst.ShowTypes, MemConst.ShowTypes.Length, MemStyles.ToolbarButton);

            if (m_selectedView != (eShowType)selected)
            {
                m_selectedView = (eShowType)selected;
                RefreshCurrentView();
            }

            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            // selected views
            float TabHeight = 30;
            float yoffset   = MemConst.TopBarHeight + TabHeight;
            Rect  view      = new Rect(0f, yoffset, position.width - MemConst.InspectorWidth, position.height - yoffset);

            switch (m_selectedView)
            {
            case eShowType.InTable:
                if (_tableBrowser != null)
                {
                    _tableBrowser.Draw(view);
                }
                break;

            case eShowType.InTreemap:
                if (_treeMapView != null)
                {
                    _treeMapView.Draw(view);
                }
                break;

            default:
                break;
            }

            if (_inspector != null)
            {
                _inspector.Draw();
            }
        }
Exemple #4
0
        void OnGUI()
        {
            // main bar
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Take Snapshot", GUILayout.Width(150)))
                {
                    UnityEditor.MemoryProfiler.MemorySnapshot.RequestNewSnapshot();
                }

                // add time point snapshots
                var snapShotOptArray = _SnapshotOptions.ToArray();
                int currentIndex     = GUI.SelectionGrid(new Rect(200, 0, 900, 20), _SnapshotChunkIndex, snapShotOptArray, snapShotOptArray.Length);
                if (currentIndex != Invalid_Int && currentIndex != _SnapshotChunkIndex)
                {
                    _SnapshotChunkIndex = currentIndex;
                    showSnapshotInfo();
                }

                GUILayout.FlexibleSpace();
                //save
                if (GUILayout.Button("Save Snapshot", GUILayout.MaxWidth(100)))
                {
                    EditorUtility.RevealInFinder(MemUtil.SnapshotsDir);
                }

                //load
                if (GUILayout.Button("Load Snapshot", GUILayout.MaxWidth(100)))
                {
                    EditorUtility.RevealInFinder(MemUtil.SnapshotsDir);
                }

                if (GUILayout.Button("Open Dir", GUILayout.MaxWidth(100)))
                {
                    EditorUtility.RevealInFinder(MemUtil.SnapshotsDir);
                }
                GUILayout.EndHorizontal();
            }

            // view bar
            GUILayout.BeginArea(new Rect(0, MemConst.TopBarHeight, position.width - MemConst.InspectorWidth, 30));
            GUILayout.BeginHorizontal(MemStyles.Toolbar);
            int selected = GUILayout.SelectionGrid((int)m_selectedView, MemConst.ShowTypes, MemConst.ShowTypes.Length, MemStyles.ToolbarButton);

            if (m_selectedView != (eShowType)selected)
            {
                m_selectedView = (eShowType)selected;
                RefreshCurrentView();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            // selected views
            float TabHeight = 30;
            float yoffset   = MemConst.TopBarHeight + TabHeight;
            Rect  view      = new Rect(0f, yoffset, position.width - MemConst.InspectorWidth, position.height - yoffset);

            switch (m_selectedView)
            {
            case eShowType.InTable:
                if (_tableBrowser != null)
                {
                    _tableBrowser.Draw(view);
                }
                break;

            case eShowType.InTreemap:
                if (_treeMapView != null)
                {
                    _treeMapView.Draw(view);
                }
                break;

            default:
                break;
            }

            if (_inspector != null)
            {
                _inspector.Draw();
            }
        }
        void OnGUI()
        {
            GUILayout.BeginHorizontal();

            _enhancedMode = GUILayout.Toggle(_enhancedMode, "Enhanced Mode", GUILayout.MaxWidth(150));

            if (GUILayout.Button("Take Snapshot"))
            {
                UnityEditor.MemoryProfiler.MemorySnapshot.RequestNewSnapshot();

                // the above call (RequestNewSnapshot) is a sync-invoke so we can process it immediately
                if (_enhancedMode && _autoSaveForComparison)
                {
                    string filename = MemUtil.Save(_snapshot);
                    if (!string.IsNullOrEmpty(filename))
                    {
                        Debug.LogFormat("snapshot '{0}' saved.", filename);

                        RefreshSnapshotList();
                    }
                }
            }

            if (_enhancedMode)
            {
                _autoSaveForComparison = GUILayout.Toggle(_autoSaveForComparison, "Auto-Save");
            }

            if (GUILayout.Button("Save Snapshot..."))
            {
                if (_snapshot != 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, _snapshot);
                        }
                    }
                }
                else
                {
                    UnityEngine.Debug.LogWarning("No snapshot to save.  Try taking a snapshot first.");
                }
            }
            if (GUILayout.Button("Load Snapshot..."))
            {
                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);
                    }
                }
            }

            if (_enhancedMode)
            {
                GUILayout.FlexibleSpace();

                {
                    GUILayout.Space(50);
                    EditorGUIUtility.labelWidth = 40;
                    _selectedBegin = EditorGUILayout.Popup(string.Format("Begin"), _selectedBegin, _snapshotFiles, GUILayout.Width(250));

                    GUILayout.Space(50);

                    _selectedEnd = EditorGUILayout.Popup(string.Format("End"), _selectedEnd, _snapshotFiles, GUILayout.Width(250));
                    EditorGUIUtility.labelWidth = 0; // reset to default
                    GUILayout.Space(50);
                }

                if (_selectedBegin == _selectedEnd)
                {
                    GUI.enabled = false;
                }
                if (GUILayout.Button("Compare", GUILayout.MaxWidth(120)))
                {
                    Debug.LogFormat("Compare '{0}' with '{1}'", _snapshotFiles[_selectedBegin], _snapshotFiles[_selectedEnd]);

                    var snapshotBegin = MemUtil.Load(_snapshotFiles[_selectedBegin]);
                    var snapshotEnd   = MemUtil.Load(_snapshotFiles[_selectedEnd]);

                    if (snapshotBegin != null && snapshotEnd != null)
                    {
                        MemCompareTarget.Instance.SetCompareTarget(snapshotBegin);

                        IncomingSnapshot(snapshotEnd);

                        if (_treeMapView != null)
                        {
                            _treeMapView.Setup(this, _unpackedCrawl, MemCompareTarget.Instance.GetNewlyAdded(_unpackedCrawl));
                        }
                    }
                }
                if (_selectedBegin == _selectedEnd)
                {
                    GUI.enabled = true;
                }

                if (GUILayout.Button("Open Dir", GUILayout.MaxWidth(120)))
                {
                    EditorUtility.RevealInFinder(MemUtil.SnapshotsDir);
                }
            }

            GUILayout.EndHorizontal();

            GUILayout.BeginArea(new Rect(0, MemConst.TopBarHeight, position.width - MemConst.InspectorWidth, 30));
            GUILayout.BeginHorizontal(MemStyles.Toolbar);
            int selected = GUILayout.SelectionGrid((int)m_selectedView, MemConst.ShowTypes, MemConst.ShowTypes.Length, MemStyles.ToolbarButton);

            if (m_selectedView != (eShowType)selected)
            {
                m_selectedView = (eShowType)selected;
                RefreshCurrentView();
            }
            GUILayout.EndHorizontal();
            GUILayout.EndArea();

            float TabHeight = 30;
            float yoffset   = MemConst.TopBarHeight + TabHeight;
            Rect  view      = new Rect(0f, yoffset, position.width - MemConst.InspectorWidth, position.height - yoffset);

            switch (m_selectedView)
            {
            case eShowType.InTable:
                if (_tableBrowser != null)
                {
                    _tableBrowser.Draw(view);
                }
                break;

            case eShowType.InTreemap:
                if (_treeMapView != null)
                {
                    _treeMapView.Draw(view);
                }
                break;

            default:
                break;
            }

            if (_inspector != null)
            {
                _inspector.Draw();
            }

            //RenderDebugList();
        }