Example #1
0
        IEnumerator Start()
        {
            var profilerWindowType = typeof(EditorApplication).Assembly.GetType("UnityEditor.ProfilerWindow");

            ProfilerDriver.ClearAllFrames();

            // Skip first frame stutter
#if UNITY_2017_3_OR_NEWER
            ProfilerDriver.enabled = false;
#endif
            yield return(null);

#if UNITY_2017_3_OR_NEWER
            ProfilerDriver.enabled = true;
#endif

            if (showProfilerWindow)
            {
                var window = EditorWindow.GetWindow(profilerWindowType);
                window.maximized = true;
            }

            while (playableDirector.playableGraph.IsValid() && playableDirector.playableGraph.IsPlaying())
            {
                yield return(null);
            }

#if UNITY_2017_3_OR_NEWER
            ProfilerDriver.enabled = false;
#endif
            EditorApplication.isPlaying = false;
        }
Example #2
0
    public IEnumerator OpenProfilerReport()
    {
        ProfilerDriver.ClearAllFrames();
        ProfilerDriver.profileEditor = true;
        yield return(null);

        ProfilerDriver.enabled = true;
        yield return(null);

        ProfilerDriver.enabled = false;
        yield return(null);

        var profileSaveFilePath = ProfilerHelpers.SaveProfileReport(k_ApplicationTickMarker);

        yield return(null);

        EditorWindow profilerWindow = null;

        ProfilerHelpers.OpenProfileReport(profileSaveFilePath, k_ApplicationTickMarker, win =>
        {
            profilerWindow = win;
        });
        yield return(TestUtils.WaitForDelayCall());

        yield return(TestUtils.WaitForDelayCall());

        Assert.IsNotNull(profilerWindow);

        File.Delete(profileSaveFilePath);

        profilerWindow.Close();
    }
Example #3
0
        private void DrawMainToolbar()
        {
            GUILayout.BeginHorizontal(EditorStyles.toolbar, new GUILayoutOption[0]);
            Rect rect = GUILayoutUtility.GetRect(ProfilerWindow.ms_Styles.addArea, EditorStyles.toolbarDropDown, new GUILayoutOption[]
            {
                GUILayout.Width(120f)
            });

            if (EditorGUI.ButtonMouseDown(rect, ProfilerWindow.ms_Styles.addArea, FocusType.Native, EditorStyles.toolbarDropDown))
            {
                int      num    = this.m_Charts.Length;
                string[] array  = new string[num];
                bool[]   array2 = new bool[num];
                for (int i = 0; i < num; i++)
                {
                    array[i]  = ((ProfilerArea)i).ToString();
                    array2[i] = !this.m_Charts[i].active;
                }
                EditorUtility.DisplayCustomMenu(rect, array, array2, null, new EditorUtility.SelectMenuItemFunction(this.AddAreaClick), null);
            }
            GUILayout.FlexibleSpace();
            this.m_Recording = GUILayout.Toggle(this.m_Recording, ProfilerWindow.ms_Styles.profilerRecord, EditorStyles.toolbarButton, new GUILayoutOption[0]);
            Profiler.enabled = this.m_Recording;
            ProfilerWindow.SetProfileDeepScripts(GUILayout.Toggle(ProfilerDriver.deepProfiling, ProfilerWindow.ms_Styles.deepProfile, EditorStyles.toolbarButton, new GUILayoutOption[0]));
            ProfilerDriver.profileEditor = GUILayout.Toggle(ProfilerDriver.profileEditor, ProfilerWindow.ms_Styles.profileEditor, EditorStyles.toolbarButton, new GUILayoutOption[0]);
            this.m_AttachProfilerUI.OnGUILayout(this);
            if (GUILayout.Button(ProfilerWindow.ms_Styles.clearData, EditorStyles.toolbarButton, new GUILayoutOption[0]))
            {
                ProfilerDriver.ClearAllFrames();
            }
            GUILayout.Space(5f);
            GUILayout.FlexibleSpace();
            this.FrameNavigationControls();
            GUILayout.EndHorizontal();
        }
Example #4
0
        public static void OpenProfileReport(string profileDataPath, string searchString = "", Action <EditorWindow> onProfileReportLoaded = null)
        {
            var profilerWindow = OpenProfilerWindow();

            EditorApplication.delayCall += () =>
            {
                EnableProfiler(false);
                ProfilerDriver.ClearAllFrames();
                if (ProfilerDriver.LoadProfile(profileDataPath, false))
                {
                    profilerWindow.titleContent.text = System.IO.Path.GetFileNameWithoutExtension(profileDataPath);
                }

                SwitchToCPUView(profilerWindow);
                profilerWindow.Repaint();
                if (!string.IsNullOrEmpty(searchString))
                {
                    EditorApplication.delayCall += () =>
                    {
                        // Wait till switch to CPU before setting the search field.
                        SetSearchField(profilerWindow, searchString);
                        Debug.Log("Profiler report ready");
                        profilerWindow.Repaint();
                    };
                }
                onProfileReportLoaded?.Invoke(profilerWindow);
            };
        }
 public void SetupTest()
 {
     ProfilerDriver.ClearAllFrames();
     m_SetupData = new FrameSetupData(1, 300, -1, new List <string> {
         "1:Main Thread"
     });
 }
    private void EndSample()
    {
#if UNITY_EDITOR
        m_CanSample = false;
        ProfilerDriver.profileEditor = false;
        ProfilerDriver.enabled       = false;
        ProfilerDriver.ClearAllFrames();
        m_Map.Clear();
#endif
    }
        void Clear()
        {
            m_ProfilerModules[(int)ProfilerArea.CPU].Clear();
            m_ProfilerModules[(int)ProfilerArea.GPU].Clear();

            ProfilerDriver.ClearAllFrames();
            m_LastFrameFromTick = -1;

#pragma warning disable CS0618
            NetworkDetailStats.m_NetworkOperations.Clear();
#pragma warning restore
        }
        public static void Run()
        {
            string[] performanceGraphGUIDs = AssetDatabase.FindAssets("performance* t:WorldGraph");

            //empty log file:
            File.WriteAllText(logFilePath, string.Empty);

            logFile = new StreamWriter(File.OpenWrite(logFilePath));

            var resultsList = new List <PerformanceResultMulti>();

            ProfilerDriver.ClearAllFrames();
            ProfilerDriver.deepProfiling = true;
            Profiler.logFile             = tmpProfilerLogFile;
            Profiler.enabled             = true;

            foreach (var performanceGraphGUID in performanceGraphGUIDs)
            {
                string     path  = AssetDatabase.GUIDToAssetPath(performanceGraphGUID);
                WorldGraph graph = AssetDatabase.LoadAssetAtPath(path, typeof(WorldGraph)) as WorldGraph;

                var results = new PerformanceResultMulti(testIterationCount);

                for (int i = 0; i < testIterationCount; i++)
                {
                    results.results[i] = RunTestForGraph(graph);
                }

                resultsList.Add(results);
            }

            Profiler.enabled             = false;
            ProfilerDriver.deepProfiling = false;

            //this is totally broken in 2017.3 ...
                        #if !UNITY_2017_3
            ProfilerDriver.LoadProfile(tmpProfilerLogFile, false);

            ProfilerDriver.SaveProfile(profilerDataFile);
                        #endif

            string text = SerializeResults(resultsList);

            string reportPerfs = Environment.GetEnvironmentVariable("PW_REPORT_PERFORMANCES");

            if (reportPerfs == "ON")
            {
                ReportPerformaces(resultsList);
            }

            logFile.Write(text);
            logFile.Flush();
        }
Example #9
0
        public static bool StartProfilerRecording(string markerFilter, bool editorProfile, bool deepProfile, Action onProfileEnabled = null)
        {
            if (ProfilerDriver.deepProfiling != deepProfile)
            {
                if (deepProfile)
                {
                    Debug.LogWarning("Enabling deep profiling. Domain reload will occur. Please restart Profiling.");
                }
                else
                {
                    Debug.LogWarning("Disabling deep profiling. Domain reload will occur. Please restart Profiling.");
                }

                SetProfilerDeepProfile(deepProfile);
                return(false);
            }

            var editorProfileStr = editorProfile ? "editor" : "playmode";
            var deepProfileStr   = deepProfile ? " - deep profile" : "";
            var hasMarkerFilter  = !string.IsNullOrEmpty(markerFilter) && SupportsMarkerFiltering();
            var markerStr        = hasMarkerFilter ? $"- MarkerFilter: {markerFilter}" : "";

            Debug.Log($"Start profiler recording: {editorProfileStr} {deepProfileStr} {markerStr}...");

            EnableProfiler(false);

            EditorApplication.delayCall += () =>
            {
                ProfilerDriver.ClearAllFrames();
                ProfilerDriver.profileEditor = editorProfile;
                ProfilerDriver.deepProfiling = deepProfile;
                if (hasMarkerFilter)
                {
                    SetMarkerFiltering(markerFilter);
                }

                EditorApplication.delayCall += () =>
                {
                    EnableProfiler(true);
                    if (onProfileEnabled != null)
                    {
                        EditorApplication.delayCall += () =>
                        {
                            onProfileEnabled();
                        };
                    }
                };
            };

            return(true);
        }
        void CheckForPlatformModuleChange()
        {
            if (m_ActiveNativePlatformSupportModule == null)
            {
                m_ActiveNativePlatformSupportModule = EditorUtility.GetActiveNativePlatformSupportModuleName();
                return;
            }


            if (m_ActiveNativePlatformSupportModule != EditorUtility.GetActiveNativePlatformSupportModuleName())
            {
                ProfilerDriver.ClearAllFrames();
                Initialize();
                m_ActiveNativePlatformSupportModule = EditorUtility.GetActiveNativePlatformSupportModuleName();
            }
        }
Example #11
0
    private void OnGUIRecordMode()
    {
        if (GUILayout.Button("Clear Profiler", GUILayout.Width(120)))
        {
            ProfilerDriver.ClearAllFrames();
            ClearRecordData();
            this.CallProfilerWindow();
        }

        EditorGUILayout.LabelField("Current Target:" + ProfilerDriver.GetConnectionIdentifier(ProfilerDriver.connectedProfiler));


        if (!string.IsNullOrEmpty(lastSaveFile))
        {
            EditorGUILayout.LabelField("Last save:" + lastSaveFile);
        }
    }
Example #12
0
        private void OnGUI()
        {
            using (new EditorGUILayout.VerticalScope())
            {
                EditorGUILayout.Space();

                EditorGUI.BeginDisabledGroup(true);

                // Profilerで選択されている関数のパスを取得
                var selectPath = ProfilerDriver.selectedPropertyPath;
                if (selectPath == string.Empty)
                {
                    selectPath = "not selected.";
                }

                EditorGUILayout.LabelField("selectedPropertyPath", selectPath);

                // Profilerで計測している開始と最後のフレーム数
                var firstFrame = ProfilerDriver.firstFrameIndex;
                var lastFrame  = ProfilerDriver.lastFrameIndex;

                EditorGUILayout.IntField("firstFrameIndex", firstFrame);
                EditorGUILayout.IntField("lastFrameIndex", lastFrame);

                // 計測対象がEditorかどうか
                var isProfileEditor = ProfilerDriver.profileEditor;

                // DeepProfileをしているかどうか
                var isDeepProfile = ProfilerDriver.deepProfiling;

                EditorGUILayout.Toggle("profileEditor", isProfileEditor);
                EditorGUILayout.Toggle("deepProfiling", isDeepProfile);

                var connectedProfilerCount = ProfilerDriver.connectedProfiler;
                EditorGUILayout.IntField("connectedProfiler", connectedProfilerCount);

                EditorGUI.EndDisabledGroup();

                // Profilerの中の情報をクリア
                if (GUILayout.Button("ClearAllFrames"))
                {
                    ProfilerDriver.ClearAllFrames();
                }
            }
        }
Example #13
0
        public static void StartSnapshot(bool silent, string fileName)
        {
            if (m_IsSnapshotting)
            {
                return;
            }

            if (!Directory.Exists(k_ProfilerFolder))
            {
                Directory.CreateDirectory(k_ProfilerFolder);
            }

            if (silent)
            {
                Debug.LogFormat("Profiler Snapshot Started [editorProfile={0} | deepProfile={1}]",
                                ProfilerDriver.profileEditor, ProfilerDriver.deepProfiling);
            }

            ProfilerDriver.ClearAllFrames();
            ProfilerDriver.enabled = true;

            m_IsSilentMode   = silent;
            m_IsSnapshotting = true;
        }
Example #14
0
 private void OnEnterViewerMode()
 {
     ProfilerDriver.ClearAllFrames();
     this.fileList = null;
 }
Example #15
0
 private void OnEnterRecordMode()
 {
     ProfilerDriver.ClearAllFrames();
     ClearRecordData();
 }
Example #16
0
        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();
            }
        }