public static EditorWindow SetupWindow(System.Type editorWindowType, ProfilingSnippetOptions options)
        {
            EditorWindow window = null;

            window = options.standaloneWindow ? OpenStandaloneWindow(editorWindowType) : EditorWindow.GetWindow(editorWindowType);

            if (options.maximizeWindow)
            {
                MaximizeWindow(window);
            }

            return(window);
        }
 static void TestProfilingSnippetActionAttr(object preExecutePayload, ProfilingSnippet snippet, ProfilingSnippetOptions options)
 {
     DoSomethingLong();
 }
Exemple #3
0
 private static void LogBenchmark(string title, ProfilerHelpers.BenchmarkResult result, ProfilingSnippetOptions options)
 {
     Debug.Log(ProfilingSnippetUtils.FormatBenchmarkResult(title, result));
     options.Log(ProfilingSnippetUtils.FormatBenchmarkResult(title, result, options.csvLog));
 }
        public static Action GetMarkerEnclosedSnippetAction(object preExecutePayload, ProfilingSnippet snippet, ProfilingSnippetOptions options)
        {
            var snippetAction = snippet.GetSnippetAction(preExecutePayload, options);

            if (!snippet.isValidMarker)
            {
                // Generate marker:
                var markerName = snippet.GetValidMarkerName();
                return(() =>
                {
                    using (new PerformanceTracker(markerName))
                    {
                        snippetAction();
                    }
                });
            }

            return(snippetAction);
        }
Exemple #5
0
        static void BenchmarkSnippet(object preExecutePayload, ProfilingSnippet snippet, ProfilingSnippetOptions options)
        {
            var snippetAction = snippet.GetSnippetAction(preExecutePayload, options);

            #if UNITY_2020_1_OR_NEWER
            if (!snippet.ranOnce && options.warmup)
            {
                snippetAction(); // This execution pass should JIT the code first.
                EditorApplication.CallDelayed(() => {
                    var result = ProfilerHelpers.Benchmark(snippetAction, options.count);
                    LogBenchmark(snippet.label, result, options);
                }, 0);
            }
            else
            #endif
            {
                var result = ProfilerHelpers.Benchmark(snippetAction, options.count);
                LogBenchmark(snippet.label, result, options);
            }
        }
Exemple #6
0
        static void BenchmarMarker(object preExecutePayload, ProfilingSnippet snippet, ProfilingSnippetOptions options)
        {
            var markerName = snippet.GetValidMarkerName();
            var action     = ProfilingSnippetUtils.GetMarkerEnclosedSnippetAction(preExecutePayload, snippet, options);
            var result     = ProfilerHelpers.BenchmarkMarker(markerName, action, options.count);

            LogBenchmark($"Benchmark marker {markerName}", result, options);
        }
Exemple #7
0
        static void ProfileSnippetMarker(object preExecutePayload, ProfilingSnippet snippet, ProfilingSnippetOptions options, bool deepProfile)
        {
            var markerName = snippet.GetValidMarkerName();
            var action     = ProfilingSnippetUtils.GetMarkerEnclosedSnippetAction(preExecutePayload, snippet, options);

            ProfilerHelpers.RecordWithMarkerFilter(markerName, action, true, deepProfile, options.count);
        }
Exemple #8
0
 static void ProfileMarkerDeep(object preExecutePayload, ProfilingSnippet snippet, ProfilingSnippetOptions options)
 {
     ProfileSnippetMarker(preExecutePayload, snippet, options, true);
 }
Exemple #9
0
        static void ProfileSnippet(object preExecutePayload, ProfilingSnippet snippet, ProfilingSnippetOptions options, bool deepProfile)
        {
            var s = snippet.GetSnippetAction(preExecutePayload, options);

            ProfilerHelpers.RecordWithProfileSample(snippet.sampleName, s, true, deepProfile, options.count);
        }
Exemple #10
0
 static void ProfileSnippet(object preExecutePayload, ProfilingSnippet snippet, ProfilingSnippetOptions options)
 {
     ProfileSnippet(preExecutePayload, snippet, options, false);
 }
Exemple #11
0
        void OnEnable()
        {
            titleContent = new GUIContent("Profiling");

            m_AllSnippets = ProfilingSnippetUtils.FetchAllSnippets();
            m_History     = new List <HistoryItem>();
            m_Actions     = GetProfilingSnippetActions().ToList();

            foreach (var action in m_Actions)
            {
                action.defaultSet = EditorPrefs.GetBool(GetKeyName($"action_{action.name}_default_set"), false);
            }

            if (!Directory.Exists(ProfilerHelpers.k_DefaultProfileSaveDirectory))
            {
                Directory.CreateDirectory(ProfilerHelpers.k_DefaultProfileSaveDirectory);
            }
            if (!File.Exists(k_LogFile))
            {
                CreateLogFile();
            }

            m_SnippetListView = new SnippetListView(m_AllSnippets);
            m_SnippetListView.doubleClicked += HandleSnippetListDoubleClick;

            m_Options = new ProfilingSnippetOptions()
            {
                logFile = k_LogFile,
                count   = 1
            };

            m_Options.warmup           = EditorPrefs.GetBool(GetKeyName($"options_{nameof(m_Options.warmup)}"), m_Options.warmup);
            m_Options.maximizeWindow   = EditorPrefs.GetBool(GetKeyName($"options_{nameof(m_Options.maximizeWindow)}"), m_Options.maximizeWindow);
            m_Options.standaloneWindow = EditorPrefs.GetBool(GetKeyName($"options_{nameof(m_Options.standaloneWindow)}"), m_Options.standaloneWindow);
            m_Options.count            = EditorPrefs.GetInt(GetKeyName($"options_{nameof(m_Options.count)}"), m_Options.count);
            m_Options.csvLog           = EditorPrefs.GetBool(GetKeyName($"options_{nameof(m_Options.csvLog)}"), m_Options.csvLog);

            m_SearchValue = EditorPrefs.GetString(GetKeyName(nameof(m_SearchValue)));
            var currentSnippetIdStr = EditorPrefs.GetString(GetKeyName("CurrentSnippetId"));

            SetCurrentFromId(currentSnippetIdStr);

            var historyStr = EditorPrefs.GetString(GetKeyName(nameof(m_History)));

            if (!string.IsNullOrEmpty(historyStr))
            {
                var historyItemTokens = historyStr.Split(';');
                foreach (var historyItemToken in historyItemTokens)
                {
                    var itemTokens = historyItemToken.Split(':');
                    if (itemTokens.Length != 2)
                    {
                        continue;
                    }
                    var possibleSnippetId = itemTokens[1];
                    var possibleSnippet   = m_AllSnippets.FirstOrDefault(snippet => snippet.idStr == possibleSnippetId);
                    if (possibleSnippet != null)
                    {
                        PushHistory(itemTokens[0], possibleSnippet);
                    }
                }
            }
        }