public void StartTrace() { var curTime = DateTime.Now; int id = Thread.CurrentThread.ManagedThreadId; StackFrame frame = new StackFrame(1); MethodBase method = frame.GetMethod(); var stackInfo = new StackMethodsInfo(curTime, method); StackThreadInfo stackThreadInfo; Stack <StackMethodsInfo> curStack; MethodInfo methodInfo = new MethodInfo(method.Name, method.DeclaringType.FullName, null); stackInfo.MethodInfo = methodInfo; if (cdIdStack.ContainsKey(id)) { cdIdStack.TryGetValue(id, out stackThreadInfo); curStack = stackThreadInfo.Stack; } else { curStack = new Stack <StackMethodsInfo>(); ThreadInfo threadInfo = new ThreadInfo(id); stackThreadInfo = new StackThreadInfo(threadInfo, curStack); cdIdStack.TryAdd(id, stackThreadInfo); threadInfos.Add(threadInfo); } AddToList(stackThreadInfo, methodInfo); curStack.Push(stackInfo); }
public void StopTrace() { DateTime time = DateTime.Now; int id = Thread.CurrentThread.ManagedThreadId; StackThreadInfo stackThreadInfo; if (!cdIdStack.TryGetValue(id, out stackThreadInfo)) { throw new TraceException(EX_MESS_NO_THREAD); } Stack <StackMethodsInfo> stackMethods = stackThreadInfo.Stack; if (stackMethods.Count > 0) { StackMethodsInfo stackMethodsInfo = stackMethods.Pop(); StackFrame frame = new StackFrame(1); ValidateMethod(stackMethodsInfo.MethodBase, frame.GetMethod()); stackMethodsInfo.MethodInfo.Time = (time - stackMethodsInfo.StartTime).TotalMilliseconds; } else { throw new TraceException(EX_MESS_NO_START); } }