Exemplo n.º 1
0
        void ExecuteSnippet(ProfilingAction action, ProfilingSnippet snippet)
        {
            var preExecutePayload = snippet.PreExecute(m_Options);
            var executePayload    = action.action(preExecutePayload, snippet, m_Options);

            snippet.PostExecute(executePayload, m_Options);
        }
        public static ProfilingSnippet CreateSnippetFromProfilingSnippetActionAttr(MethodInfo mi)
        {
            var attr    = mi.GetCustomAttributes(typeof(ProfilingSnippetActionAttribute), false).Cast <ProfilingSnippetActionAttribute>().First();
            var snippet = new ProfilingSnippet(attr.idStr ?? mi.Name, attr.label, attr.sampleName, attr.markerName);

            try
            {
                snippet.category = attr.category;
                var inputParams = mi.GetParameters();
                if (mi.GetParameters().Length == 3)
                {
                    snippet.executeFunc = Delegate.CreateDelegate(typeof(Action <object, ProfilingSnippet, ProfilingSnippetOptions>), mi) as
                                          Action <object, ProfilingSnippet, ProfilingSnippetOptions>;
                }
                else if (mi.GetParameters().Length == 0)
                {
                    var noParamAction = Delegate.CreateDelegate(typeof(Action), mi) as Action;
                    snippet.executeFunc = (payload, _snippet, options) => noParamAction();
                }
                else
                {
                    Debug.LogError($"Error while creating ProfilingSnippet {snippet.label}. {kSignatureMismatch}");
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Debug.LogError($"Error while creating ProfilingSnippet {snippet.label}. {kSignatureMismatch} - {ex.Message}");
                return(null);
            }
            return(snippet);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
 void HandleSnippetListDoubleClick(ProfilingSnippet snippet)
 {
     foreach (var action in m_Actions)
     {
         if (!action.defaultSet)
         {
             continue;
         }
         EditorApplication.delayCall += () => ExecuteSnippet(action, snippet);
     }
 }
Exemplo n.º 6
0
        private ProfilingSnippet CurrentSnippet()
        {
            ProfilingSnippet selectedSnippet = null;
            var selection = m_SnippetListView.GetSelection();

            if (selection.Count > 0)
            {
                selectedSnippet = m_AllSnippets.FirstOrDefault(snippet => snippet.id == selection[0]);
            }

            return(selectedSnippet);
        }
        static ProfilingSnippet TestProfilingSnippetAttr()
        {
            var snippet = new ProfilingSnippet("Test_something_else_long_id", "Test something else long");

            snippet.category    = "Test";
            snippet.sampleName  = "Test_something_else_long_sample";
            snippet.executeFunc = (preExecutePayload, s, options) =>
            {
                DoSomethingLong();
            };
            return(snippet);
        }
Exemplo n.º 8
0
        void PushHistory(string search, ProfilingSnippet snippet)
        {
            if (m_History.Count > 0 && m_History.Last().search == search && m_History.Last().idStr == snippet.idStr)
            {
                return;
            }

            m_History.Add(new HistoryItem()
            {
                search = search,
                idStr  = snippet.idStr
            });
            m_HistoryCursor = m_History.Count - 1;
        }
        public static ProfilingSnippet CreateSnippetFromStaticMethod(MethodInfo mi)
        {
            var fullName   = $"{mi.Name} ({mi.DeclaringType.FullName})";
            var newSnippet = new ProfilingSnippet($"{mi.DeclaringType.FullName}_{mi.Name}_{mi.GetHashCode()}", fullName);

            newSnippet.category    = "Static";
            newSnippet.executeFunc = (dummy, snippet, options) =>
            {
                mi.Invoke(null, null);
            };
            newSnippet.sampleName = $"static_{mi.Name}";

            return(newSnippet);
        }
Exemplo n.º 10
0
        void SetCurrentFromSnippet(ProfilingSnippet currentSnippet)
        {
            var selectedItems = new List <int>();

            if (currentSnippet != null)
            {
                selectedItems.Add(currentSnippet.id);
            }
            m_SnippetListView.SetSelection(selectedItems);

            if (currentSnippet != null)
            {
                m_SnippetListView.FrameItem(currentSnippet.id);
            }
        }
        public static ProfilingSnippet CreateSnippetFromEditorWindowType(System.Type editorWindowType)
        {
            var newSnippet = new ProfilingSnippet($"repaint_{editorWindowType.FullName}", $"{editorWindowType.Name} ({editorWindowType.Namespace})");

            newSnippet.category       = "Repaint";
            newSnippet.preExecuteFunc = (snippet, options) => SetupWindow(editorWindowType, options);
            newSnippet.executeFunc    = (editorWindowObj, snippet, options) =>
            {
                var editorWindow = editorWindowObj as EditorWindow;
                RepaintImmediatlyWindow(editorWindow);
            };
            newSnippet.sampleName = $"{editorWindowType.Name}_Paint";
            newSnippet.markerName = $"{editorWindowType.Name}.Paint";

            return(newSnippet);
        }
Exemplo n.º 12
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);
            }
        }
        static IEnumerable <ProfilingSnippet> GetMenuSnippets()
        {
            var      outItemNames            = new List <string>();
            var      outItemDefaultShortcuts = new List <string>();
            Assembly assembly    = typeof(Menu).Assembly;
            var      managerType = assembly.GetTypes().First(t => t.Name == "Menu");
            var      method      = managerType.GetMethod("GetMenuItemDefaultShortcuts", BindingFlags.NonPublic | BindingFlags.Static);
            var      arguments   = new object[] { outItemNames, outItemDefaultShortcuts };

            method.Invoke(null, arguments);

            return(outItemNames.Select(menuItemName =>
            {
                var snippet = new ProfilingSnippet($"menu_{menuItemName}", menuItemName, menuItemName.Replace("/", "_"));
                snippet.category = "Menu";
                snippet.executeFunc = (preExecutePayload, s, options) =>
                {
                    EditorApplication.ExecuteMenuItem(s.label);
                };

                return snippet;
            }));
        }
 static void TestProfilingSnippetActionAttr(object preExecutePayload, ProfilingSnippet snippet, ProfilingSnippetOptions options)
 {
     DoSomethingLong();
 }
        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);
        }
Exemplo n.º 16
0
 static void ProfileSnippet(object preExecutePayload, ProfilingSnippet snippet, ProfilingSnippetOptions options)
 {
     ProfileSnippet(preExecutePayload, snippet, options, false);
 }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
0
 static void ProfileMarkerDeep(object preExecutePayload, ProfilingSnippet snippet, ProfilingSnippetOptions options)
 {
     ProfileSnippetMarker(preExecutePayload, snippet, options, true);
 }