public void StopTrace() { lock (executableQueries) { Thread currentThread = Thread.CurrentThread; Stack <MethodTraceResult> currentStack = executableQueries[currentThread]; MethodTraceResult currentMethodTrace = currentStack.Pop(); currentMethodTrace.Stopwatch.Stop(); if (currentStack.Count > 0) { MethodTraceResult fatherTrace = currentStack.Peek(); if (fatherTrace.methods == null) { fatherTrace.methods = new List <MethodTraceResult>(); } fatherTrace.methods.Add(currentMethodTrace); } else { if (!stoppedQueries.ContainsKey(currentThread)) { stoppedQueries.Add(currentThread, new List <MethodTraceResult>()); } stoppedQueries[currentThread].Add(currentMethodTrace); } } }
public MethodInfo(MethodTraceResult traceResult) { name = traceResult.name; time = traceResult.Stopwatch.ElapsedMilliseconds + "ms"; ClassName = traceResult.clazz; methods = new List <MethodInfo>(); if (traceResult.methods != null) { foreach (var childTraceResult in traceResult.methods) { methods.Add(new MethodInfo(childTraceResult)); } } }
public void StartTrace() { lock (executableQueries) { Thread currentThread = Thread.CurrentThread; if (!executableQueries.ContainsKey(currentThread)) { executableQueries.Add(currentThread, new Stack <MethodTraceResult>()); } StackTrace stackTrace = new StackTrace(); MethodBase callerMethod = stackTrace.GetFrame(1).GetMethod(); MethodTraceResult currentMethodTrace = new MethodTraceResult(); currentMethodTrace.clazz = callerMethod.ReflectedType.Name; currentMethodTrace.name = callerMethod.Name; currentMethodTrace.Stopwatch = new Stopwatch(); currentMethodTrace.Stopwatch.Start(); executableQueries[currentThread].Push(currentMethodTrace); } }