public static void EndTrace() { lock (Locker) { CurrentTraceInfo traceInfo = GetMethodDescription(); traceInfo.IsOpened = false; traceStack.Add(traceInfo); } }
public static void EndTrace() { lock (Locker) { CurrentTraceInfo traceInfo = GetMethodDescription(); traceInfo.IsOpened = false; _traceStack.Add(traceInfo); } //Console.WriteLine("EndTrace {0}", Thread.CurrentThread.ManagedThreadId); }
public static void BeginTrace() { lock (Locker) { CurrentTraceInfo traceInfo = GetMethodDescription(); traceInfo.IsOpened = true; _traceStack.Add(traceInfo); //Console.WriteLine("BeginTrace {0} {1} {2} {3} {4}", traceInfo.threadId, traceInfo.traceTime.Millisecond, traceInfo.methodName, traceInfo.className, traceInfo.fileName); } }
private static CurrentTraceInfo GetMethodDescription() { CurrentTraceInfo tempInfo = new CurrentTraceInfo(); tempInfo.TraceTime = DateTime.UtcNow; int threadid = Thread.CurrentThread.ManagedThreadId; if (threadid > 1) { threadid--; } tempInfo.ThreadId = threadid; try { StackTrace st = new StackTrace(true); StackFrame frame; for (int i = 0; i < st.FrameCount; i++) { frame = st.GetFrame(i); var declaringType = frame.GetMethod().DeclaringType; if (declaringType != null) { string name = declaringType.Name; if (name != typeof(Tracer).Name) { tempInfo.FileName = frame.GetMethod().Module.Name; tempInfo.MethodName = frame.GetMethod().Name; tempInfo.ClassName = declaringType.FullName; return(tempInfo); } } } return(tempInfo); } catch (Exception ex) { Console.WriteLine(ex); return(tempInfo); } }
public static List <TracerLog> Stop() { Console.WriteLine("Stop"); lock (Locker) { _traceStackDict = new Dictionary <int, List <CurrentTraceInfo> >(); _traceStackCount = new Dictionary <int, TimeLaps>(); // выбираем все номера потоков foreach (CurrentTraceInfo cti in _traceStack) { List <CurrentTraceInfo> obj; if (!_traceStackDict.TryGetValue(cti.ThreadId, out obj)) { _traceStackDict.Add(cti.ThreadId, new List <CurrentTraceInfo>()); _traceStackCount.Add(cti.ThreadId, new TimeLaps()); } } // считаем "операторные" скобки foreach (CurrentTraceInfo cti in _traceStack) { _traceStackDict[cti.ThreadId].Add(cti); if (cti.IsOpened) { TimeLaps tempTl = new TimeLaps { BeginCount = _traceStackCount[cti.ThreadId].BeginCount + 1, EndCount = _traceStackCount[cti.ThreadId].EndCount }; _traceStackCount[cti.ThreadId] = tempTl; } else { TimeLaps tempTl = new TimeLaps { BeginCount = _traceStackCount[cti.ThreadId].BeginCount, EndCount = _traceStackCount[cti.ThreadId].EndCount + 1 }; _traceStackCount[cti.ThreadId] = tempTl; } } // балансируем "скобки" foreach (KeyValuePair <int, List <CurrentTraceInfo> > cti in _traceStackDict) { if (_traceStackCount[cti.Key].BeginCount != _traceStackCount[cti.Key].EndCount) { for (var i = 0; i < Math.Abs(_traceStackCount[cti.Key].EndCount - _traceStackCount[cti.Key].BeginCount); i++) { var temp = new CurrentTraceInfo { IsOpened = false, ThreadId = Thread.CurrentThread.ManagedThreadId }; _traceStackDict[cti.Key].Add(temp); } } } // собственно построение дерево _traceLog = new List <TracerLog>(); foreach (KeyValuePair <int, List <CurrentTraceInfo> > kvp in _traceStackDict) { var j = 0; var x = new TracerLog { TraceChilds = new List <TracerLog>() }; AddTreeElement(ref x.TraceChilds, kvp.Value, ref j); _traceLog.Add(x); } _isStarted = false; } return(_traceLog); }
public static List <TracerLog> Stop() { lock (Locker) { traceStackDict = new Dictionary <int, List <CurrentTraceInfo> >(); traceStackCount = new Dictionary <int, TimeLaps>(); foreach (CurrentTraceInfo cti in traceStack) { List <CurrentTraceInfo> obj; if (!traceStackDict.TryGetValue(cti.ThreadId, out obj)) { traceStackDict.Add(cti.ThreadId, new List <CurrentTraceInfo>()); traceStackCount.Add(cti.ThreadId, new TimeLaps()); } } foreach (CurrentTraceInfo cti in traceStack) { traceStackDict[cti.ThreadId].Add(cti); if (cti.IsOpened) { TimeLaps tempTl = new TimeLaps { BeginCount = traceStackCount[cti.ThreadId].BeginCount + 1, EndCount = traceStackCount[cti.ThreadId].EndCount }; traceStackCount[cti.ThreadId] = tempTl; } else { TimeLaps tempTl = new TimeLaps { BeginCount = traceStackCount[cti.ThreadId].BeginCount, EndCount = traceStackCount[cti.ThreadId].EndCount + 1 }; traceStackCount[cti.ThreadId] = tempTl; } } foreach (KeyValuePair <int, List <CurrentTraceInfo> > cti in traceStackDict) { if (traceStackCount[cti.Key].BeginCount != traceStackCount[cti.Key].EndCount) { for (var i = 0; i < Math.Abs(traceStackCount[cti.Key].EndCount - traceStackCount[cti.Key].BeginCount); i++) { var temp = new CurrentTraceInfo { IsOpened = false, ThreadId = Thread.CurrentThread.ManagedThreadId }; traceStackDict[cti.Key].Add(temp); } } } //построения дерева traceLog = new List <TracerLog>(); foreach (KeyValuePair <int, List <CurrentTraceInfo> > kvp in traceStackDict) { var j = 0; var x = new TracerLog { TraceChilds = new List <TracerLog>() }; AddTreeElement(ref x.TraceChilds, kvp.Value, ref j); traceLog.Add(x); } isStarted = false; } return(traceLog); }
public static List<TracerLog> Stop() { Console.WriteLine("Stop"); lock (Locker) { _traceStackDict = new Dictionary<int, List<CurrentTraceInfo>>(); _traceStackCount = new Dictionary<int, TimeLaps>(); // выбираем все номера потоков foreach (CurrentTraceInfo cti in _traceStack) { List<CurrentTraceInfo> obj; if (!_traceStackDict.TryGetValue(cti.ThreadId, out obj)) { _traceStackDict.Add(cti.ThreadId, new List<CurrentTraceInfo>()); _traceStackCount.Add(cti.ThreadId, new TimeLaps()); } } // считаем "операторные" скобки foreach (CurrentTraceInfo cti in _traceStack) { _traceStackDict[cti.ThreadId].Add(cti); if (cti.IsOpened) { TimeLaps tempTl = new TimeLaps { BeginCount = _traceStackCount[cti.ThreadId].BeginCount + 1, EndCount = _traceStackCount[cti.ThreadId].EndCount }; _traceStackCount[cti.ThreadId] = tempTl; } else { TimeLaps tempTl = new TimeLaps { BeginCount = _traceStackCount[cti.ThreadId].BeginCount, EndCount = _traceStackCount[cti.ThreadId].EndCount + 1 }; _traceStackCount[cti.ThreadId] = tempTl; } } // балансируем "скобки" foreach (KeyValuePair<int, List<CurrentTraceInfo>> cti in _traceStackDict) { if (_traceStackCount[cti.Key].BeginCount != _traceStackCount[cti.Key].EndCount) { for (var i = 0; i < Math.Abs(_traceStackCount[cti.Key].EndCount - _traceStackCount[cti.Key].BeginCount); i++) { var temp = new CurrentTraceInfo {IsOpened = false, ThreadId = Thread.CurrentThread.ManagedThreadId}; _traceStackDict[cti.Key].Add(temp); } } } // собственно построение дерево _traceLog = new List<TracerLog>(); foreach (KeyValuePair<int, List<CurrentTraceInfo>> kvp in _traceStackDict) { var j = 0; var x = new TracerLog {TraceChilds = new List<TracerLog>()}; AddTreeElement(ref x.TraceChilds, kvp.Value, ref j); _traceLog.Add(x); } _isStarted = false; } return _traceLog; }
private static CurrentTraceInfo GetMethodDescription() { CurrentTraceInfo tempInfo = new CurrentTraceInfo(); tempInfo.TraceTime = DateTime.UtcNow; tempInfo.ThreadId = Thread.CurrentThread.ManagedThreadId; try { StackTrace st = new StackTrace(true); StackFrame frame; for (int i = 0; i < st.FrameCount; i++) { frame = st.GetFrame(i); var declaringType = frame.GetMethod().DeclaringType; if (declaringType != null) { string name = declaringType.Name; if (name != typeof(Tracer).Name) { //tempInfo.fileName = frame.GetFileName(); tempInfo.FileName = frame.GetMethod().Module.Name; //tempInfo.methodName = frame.GetMethod().ToString(); tempInfo.MethodName = frame.GetMethod().Name; tempInfo.ClassName = declaringType.FullName; return tempInfo; } } } return tempInfo; } catch (Exception ex) { Console.WriteLine(ex); return tempInfo; } }