Exemplo n.º 1
0
        public void StopTrace()
        {
            long endTime  = GetTimeInMs();
            int  threadId = Thread.CurrentThread.ManagedThreadId;
            TracingThreadInfo tracingThreadInfo = TryGetTracingThreadInfo(threadId);
            MethodBase        parentMethod      = GetParentMethod();

            TrySaveTraceResults(tracingThreadInfo, parentMethod, endTime);
        }
Exemplo n.º 2
0
        public void StartTrace()
        {
            int threadId = Thread.CurrentThread.ManagedThreadId;
            TracingThreadInfo tracingThreadInfo = GetOrCreateTracingTreadInfo(threadId);
            MethodBase        parentMethod      = GetParentMethod();
            long startTime = GetTimeInMs();

            AddStartTraceData(tracingThreadInfo, parentMethod, startTime);
        }
Exemplo n.º 3
0
        private TracingThreadInfo GetOrCreateTracingTreadInfo(int threadId)
        {
            if (threadsMap.ContainsKey(threadId))
            {
                return(threadsMap[threadId]);
            }

            ThreadTraceResult threadTraceResult = new ThreadTraceResult(threadId);
            TracingThreadInfo tracingThreadInfo = new TracingThreadInfo(threadTraceResult);

            return(threadsMap[threadId] = tracingThreadInfo);
        }
Exemplo n.º 4
0
        private void AddStartTraceData(TracingThreadInfo tracingThreadInfo, MethodBase parentMethod, long startTime)
        {
            MethodTraceResult methodTraceResult = new MethodTraceResult(parentMethod.Name, parentMethod.ReflectedType.Name);
            TracingMethodInfo tracingMethodInfo = new TracingMethodInfo(startTime, parentMethod, methodTraceResult);

            if (tracingThreadInfo.TracingStack.Count != 0)
            {
                TracingMethodInfo parentTracingMethodInfo = tracingThreadInfo.TracingStack.Peek();
                if (parentTracingMethodInfo.MethodTraceResult.Methods == null)
                {
                    parentTracingMethodInfo.MethodTraceResult.Methods = new List <MethodTraceResult>();
                }
                parentTracingMethodInfo.MethodTraceResult.Methods.Add(methodTraceResult);
            }
            tracingThreadInfo.TracingStack.Push(tracingMethodInfo);
        }
Exemplo n.º 5
0
        private void TrySaveTraceResults(TracingThreadInfo tracingThreadInfo, MethodBase parentMethod, long endTime)
        {
            if ((tracingThreadInfo.TracingStack.Count == 0) || (tracingThreadInfo.TracingStack.Peek().MethodBase != parentMethod))
            {
                throw new OrderViolationException();
            }

            TracingMethodInfo tracingMethodInfo = tracingThreadInfo.TracingStack.Pop();

            tracingMethodInfo.MethodTraceResult.Time = (int)(endTime - tracingMethodInfo.StartTime);
            if (tracingThreadInfo.TracingStack.Count == 0)
            {
                tracingThreadInfo.ThreadTraceResult.Methods.Add(tracingMethodInfo.MethodTraceResult);
                tracingThreadInfo.IsEmptyThread = false;

                isThreadResultCreated = false;
            }
        }