public static void Enter(object caller, MethodBase method) { _enabled = true; var tid = System.Threading.Thread.CurrentThread.ManagedThreadId; lock (_threads) { _threads.Add(System.Threading.Thread.CurrentThread); } ChromeProfileData data; lock (_profilesPerThread) { if (_profilesPerThread.TryGetValue(tid, out data) == false) { data = new ChromeProfileData(); _profilesPerThread.Add(tid, data); } } data.callStack.Push(new ChromeProfileData.StackInfo() { methodName = GetProfileName(method), ts = _global_sw.ElapsedTicks * 1000000 / Stopwatch.Frequency, }); }
public static void Leave(object caller, MethodBase method) { var tid = System.Threading.Thread.CurrentThread.ManagedThreadId; ChromeProfileData data; lock (_profilesPerThread) { if (_profilesPerThread.TryGetValue(tid, out data) == false) { data = new ChromeProfileData(); _profilesPerThread.Add(tid, data); } } var curr_ts = _global_sw.ElapsedTicks * 1000000 / Stopwatch.Frequency; var path = string.Join("/", data.callStack.Select(x => x.methodName).Reverse().ToArray()); var stackInfo = data.callStack.Pop(); var dur = curr_ts - stackInfo.ts; if (dur > TracingThreshold) { data.traceEvents.Add(new ChromeProfileData.Record() { name = stackInfo.methodName, ts = stackInfo.ts, pid = _pid, tid = tid, ph = "X", dur = dur, args = { path = path } }); } StratBackgroundSaver(); }