Esempio n. 1
0
        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();
            }
        }
Esempio n. 3
0
        void SaveToFile()
        {
            var path = EditorUtility.SaveFilePanel("Save", "", "memory", "heap");

            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            HeMruFiles.AddPath(path);

            m_Heap.SaveToFile(path);
            snapshotPath = path;
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        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();
            }
        }