コード例 #1
0
        public static void OnPostExecution(object __state, MethodBase __originalMethod)
        {
            if (!ProfilerPlugin.Instance.IsProfiling)
            {
                return;
            }

            var sw = __state as Stopwatch;

            if (sw == null)
            {
                return;
            }

            sw.Stop();
            long time = sw.ElapsedMilliseconds;

            if (!s_Registrations.ContainsKey(__originalMethod))
            {
                return;
            }

            MeasurableMethod o = s_Registrations[__originalMethod];

            if (ProfilerPlugin.Instance != null && o.Measurements.Count > ProfilerPlugin.Instance.Configuration.Instance.MaxFrameCount)
            {
                // we might do profiling during a reload, so we need to check if instance is null
                return;
            }

            o.Measurements.Add(time);
        }
コード例 #2
0
        public static void RegisterMethod(MeasurableMethod measurableMethod)
        {
            if (measurableMethod == null)
            {
                throw new ArgumentNullException(nameof(measurableMethod));
            }

            var method = measurableMethod.Method;

            if (!s_PatchedMethods.Contains(method))
            {
                var pluginInstance = ProfilerPlugin.Instance;
                pluginInstance.Harmony.Patch(method, s_PrefixMethod, s_PostfixMethod);
                s_PatchedMethods.Add(method);
            }

            if (!s_Registrations.ContainsKey(method))
            {
                s_Registrations.Add(method, measurableMethod);
            }
            else
            {
                //throw new Exception("Already registered method: " + method.GetFullName());
                s_Registrations[method] = measurableMethod;
            }
        }
コード例 #3
0
        public static void Register(string eventName, Delegate eventDelegate)
        {
            if (eventDelegate == null)
            {
                throw new ArgumentNullException(nameof(eventDelegate));
            }

            foreach (var handler in eventDelegate.GetInvocationList())
            {
                var method = handler.Method;
                var dType  = handler.Method.DeclaringType;

                if (dType == null)
                {
                    Logger.LogWarning("DeclaringType null for: " + method.Name);
                    continue;
                }

                MeasurableMethod o = new MeasurableMethod
                {
                    MeasureType  = eventName,
                    Measurements = new List <decimal>(),
                    Method       = method
                };

                HarmonyProfiling.RegisterMethod(o);
            }
        }
コード例 #4
0
        public static void Register(string measurableType, MethodBase targetMethod)
        {
            if (targetMethod == null)
            {
                throw new ArgumentNullException(nameof(targetMethod));
            }

            MeasurableMethod o = new MeasurableMethod
            {
                MeasureType  = measurableType,
                Measurements = new List <decimal>(),
                Method       = targetMethod
            };

            HarmonyProfiling.RegisterMethod(o);
        }