private MethodData TryCreateOrGetMethodData(ThreadData thread, FullMethodName name, string methodId) { if (thread == null) { throw new Exception("thread should not be null"); } if (name == null) { throw new Exception("method name should not be null"); } if (thread.currentMethod == null) { bool hasRootMethod = thread.methods.TryGetValue(methodId, out MethodData rootMethod); if (!hasRootMethod) { rootMethod = new MethodData(name, null); thread.methods.Add(methodId, rootMethod); } return(rootMethod); } bool hasMethod = thread.currentMethod.methods.TryGetValue(methodId, out MethodData method); if (!hasMethod) { method = new MethodData(name, thread.currentMethod); thread.currentMethod.methods.Add(methodId, method); } return(method); }
public MethodData(FullMethodName fullName, MethodData parent) { this.name = fullName; this.stopwatch = new Stopwatch(); this.methods = new Dictionary <string, MethodData>(); this.countTimesCalled = 0; this.parentMethod = parent; }
public void StopTrace() { StackFrame frame = new StackFrame(GARBAGE_FRAMES_COUNT); FullMethodName methodName = this.GetFullMethodName(frame); string methodId = this.GetMethodUniqueIdentifier(frame); ThreadData thread = this.TryCreateOrGetThreadData(); this.MoveUpOnMethodData(thread); MethodData currentMethod = this.TryCreateOrGetMethodData(thread, methodName, methodId); currentMethod.stopwatch.Stop(); }