Example #1
0
        internal Timing(string typeName, string methodName, string timerName, Profiler profiler, Timing parent, int threadId)
        {
            this.typeName = typeName;
            this.methodName = methodName;
            this.timerName = timerName;
            this.profiler = profiler;
            this.parent = parent;
            this.threadId = threadId;
            this.disposed = false;

            if (parent == null)
            {
                stopwatch = Stopwatch.StartNew();
                startMilliseconds = 0;
            }
            else
            {
                if (parent.subTimings == null)
                {
                    parent.subTimings = new List<Timing>();
                }
                parent.subTimings.Add(this);
                stopwatch = parent.stopwatch;
                startMilliseconds = stopwatch.ElapsedMilliseconds;
            }
        }
Example #2
0
        internal void StopTimer(Timing timing)
        {
            var threadId = Thread.CurrentThread.ManagedThreadId;

            if (timing.Parent == null)
            {
                using (var channel = _bus.OpenPublishChannel())
                {
                    channel.Publish(timing.GetResults());
                }

                threadTimings.TryRemove(threadId, out timing);
            }
            else
            {
                threadTimings[threadId] = timing.Parent;
            }
        }
Example #3
0
 internal Timing Timer(string typeName, string methodName, string timerName = null)
 {
     var threadId = Thread.CurrentThread.ManagedThreadId;
     Timing currentTiming = null;
     threadTimings.TryGetValue(threadId, out currentTiming);
     currentTiming = new Timing(typeName, methodName, timerName, this, currentTiming, threadId);
     threadTimings[threadId] = currentTiming;
     return currentTiming;
 }