Example #1
0
        private MethodData TryCreateOrGetMethodData(ThreadData thread, FullMethodName name, string methodId)
        {
            if (thread == null)
            {
                throw new Exception("thread should not be null");
            }

            if (name == null)
            {
                throw new Exception("method name should not be null");
            }

            if (thread.currentMethod == null)
            {
                bool hasRootMethod = thread.methods.TryGetValue(methodId, out MethodData rootMethod);

                if (!hasRootMethod)
                {
                    rootMethod = new MethodData(name, null);
                    thread.methods.Add(methodId, rootMethod);
                }

                return(rootMethod);
            }

            bool hasMethod = thread.currentMethod.methods.TryGetValue(methodId, out MethodData method);

            if (!hasMethod)
            {
                method = new MethodData(name, thread.currentMethod);
                thread.currentMethod.methods.Add(methodId, method);
            }

            return(method);
        }
Example #2
0
 public MethodData(FullMethodName fullName, MethodData parent)
 {
     this.name             = fullName;
     this.stopwatch        = new Stopwatch();
     this.methods          = new Dictionary <string, MethodData>();
     this.countTimesCalled = 0;
     this.parentMethod     = parent;
 }
Example #3
0
        public void StopTrace()
        {
            StackFrame     frame      = new StackFrame(GARBAGE_FRAMES_COUNT);
            FullMethodName methodName = this.GetFullMethodName(frame);
            string         methodId   = this.GetMethodUniqueIdentifier(frame);
            ThreadData     thread     = this.TryCreateOrGetThreadData();

            this.MoveUpOnMethodData(thread);
            MethodData currentMethod = this.TryCreateOrGetMethodData(thread, methodName, methodId);

            currentMethod.stopwatch.Stop();
        }