private void ToFormTraceList(List <MethodTraceResultClass> methodTraceList, List <ThreadTraceResultClass> threadsList) { ThreadTraceResultClass bufThreadTraceResult; foreach (MethodTraceResultClass mtr in methodTraceList) { bufThreadTraceResult = _traceList.Find(x => x.id == mtr.threadId); if (bufThreadTraceResult != null) { int ind = bufThreadTraceResult.calledMethods.IndexOf(mtr); if (ind < 0) { bufThreadTraceResult.calledMethods.Add(mtr); } } else { bufThreadTraceResult = new ThreadTraceResultClass { id = mtr.threadId, calledMethods = new List <MethodTraceResultClass>() }; bufThreadTraceResult.calledMethods.Add(mtr); threadsList.Add(bufThreadTraceResult); } } }
public void StopTrace() { lock (locker) { StackFrame frame = new StackFrame(1); MethodTraceResultClass traceResultElem = FindElement(_methodsTraceList, frame.GetMethod().Name, frame.GetMethod().DeclaringType.Name, Thread.CurrentThread.ManagedThreadId); if (traceResultElem != null) { traceResultElem.stopwatch.Stop(); traceResultElem.execTime = traceResultElem.stopwatch.ElapsedMilliseconds; ToFormTraceList(_methodsTraceList, _traceList); ThreadTraceResultClass curThread = _traceList.Find(x => x.id == Thread.CurrentThread.ManagedThreadId); curThread.execTime = CountThreadExecTime(curThread.calledMethods); } } }