Beispiel #1
0
 public StopwatchRecord(StopwatchRecord record)
 {
     this.method            = record.method;
     this.avg               = record.avg;
     this.num               = record.num;
     this.min               = record.min;
     this.max               = record.max;
     this.allocBytes        = record.allocBytes;
     this.allocAvgBytes     = record.allocAvgBytes;
     this.patchesCached     = record.patchesCached;
     this.patchOwnersCached = record.patchOwnersCached;
 }
        // Stop timer and calc avg time
        public static void Patch_Stop(ref StopwatchRecord __state)
        {
            if (!Active || __state == null)
            {
                return;
            }
            __state.Stop();

            // log stacktrace
            if (logMethod != null && logMethod == __state.Method)
            {
                Log.Warning(__state.MethodName);
            }
        }
        // Start timer
        public static void Patch_Start(MethodBase __originalMethod, ref StopwatchRecord __state)
        {
            if (!Active)
            {
                return;
            }
            if (_settings.checkMainThread && !UnityData.IsInMainThread || !_settings.checkMainThread && UnityData.IsInMainThread)
            {
                __state = null;
                return;
            }

            int ptr = __originalMethod.MethodHandle.Value.ToInt32(); // faster then gethashcode?

            if (!_profiledMethods.TryGetValue(ptr, out __state))
            {
                __state = new StopwatchRecord(__originalMethod, _settings.collectMemAlloc);
                _profiledMethods.Add(ptr, __state);
            }
            __state.Start();
        }
        /*   TRANSPILER MODE   */
        public static void Patch_Transpiler_Template(MethodBase __originalMethod)
        {
            StopwatchRecord profiler = null;

            if (Active && (_settings.checkMainThread && UnityData.IsInMainThread || !_settings.checkMainThread && !UnityData.IsInMainThread))
            {
                int ptrKey = 3333;//__originalMethod.MethodHandle.Value.ToInt32();
                if (!_profiledMethods.TryGetValue(ptrKey, out profiler))
                {
                    MethodBase thisMethod = _getMethodByKey[ptrKey];
                    profiler = new StopwatchRecord(thisMethod, _settings.collectMemAlloc);
                    _profiledMethods.Add(ptrKey, profiler);
                }
                // if (logMethod != null && logMethod == __state.Method) // TODO: Release this to ptrKey
                // {
                //     Log.Warning(__state.MethodName);
                // }
                profiler.Start();
            }
            // function random code
            Log.Warning("RANDOM CODE");
            // end profiling
            profiler?.Stop();
        }