Profiler() { _current = new ProfileItem(""); _stopwatch = new Stopwatch(); _current.Start(_stopwatch.Elapsed); _stopwatch.Start(); }
void AfterAction() { lock (this) { _stopwatch.Stop(); var end = _stopwatch.Elapsed; _current.End(end); _current = _stack.Pop(); _current.Resume(end); _stopwatch.Start(); } }
void BeforeAction(string flag, int stackFrameDepth) { lock (this) { _stopwatch.Stop(); var start = _stopwatch.Elapsed; _current.Suspend(start); _stack.Push(_current); var position = Tracer.MethodHeader(stackFrameDepth: stackFrameDepth + 1) + flag; if (!_profileItems.TryGetValue(position, out _current)) { _current = new ProfileItem(position); _profileItems.Add(position, _current); } _current.Start(start); _stopwatch.Start(); } }
void Start(string flag, int stackFrameDepth) { _instance.BeforeAction(flag, stackFrameDepth + 1); _item = _profiler._current; }