Exemple #1
0
        public ITimeTracker BeginTiming(string message, IDictionary <string, string> metadata)
        {
            ITimeTracker timer;

            if (!Enabled)
            {
                timer = dummyTimer;
            }
            else
            {
                var c = new TimeCounter(this);
                lock (values) {
                    timer = lastTimer = c;
                    count++;
                    totalCount++;
                    int i = StoreValue(message, lastTimer, metadata);
                    lastTimer.TraceList.ValueIndex = i;
                }
            }
            if (LogMessages && message != null)
            {
                InstrumentationService.LogMessage(message);
            }
            return(timer);
        }
Exemple #2
0
        internal ITimeTracker <T> BeginTiming <T> (string message, T metadata, CancellationToken cancellationToken) where T : CounterMetadata, new()
        {
            if (!Enabled && !LogMessages)
            {
                return(new DummyTimerCounter <T> (metadata));
            }

            var c = new TimeCounter <T> (this, metadata, cancellationToken);

            if (Enabled)
            {
                lock (values) {
                    count++;
                    totalCount++;
                    int i = StoreValue(message, c, metadata?.Properties);
                    ((ITimeCounter)c).TraceList.ValueIndex = i;
                }
            }
            else
            {
                if (message != null)
                {
                    InstrumentationService.LogMessage(message);
                }
                else
                {
                    InstrumentationService.LogMessage("START: " + Name);
                }
            }
            return(c);
        }
Exemple #3
0
 public void EndTiming()
 {
     if (lastTimer != null)
     {
         lastTimer.End();
         lastTimer = null;
     }
 }
Exemple #4
0
        internal int StoreValue(string message, TimeCounter timer, IDictionary <string, string> metadata)
        {
            DateTime now = DateTime.Now;

            if (resolution.Ticks != 0)
            {
                if (now - lastValueTime < resolution)
                {
                    return(-1);
                }
            }
            var val = new CounterValue(count, totalCount, count - lastStoredCount, now, message, timer != null ? timer.TraceList : null, metadata);

            lastStoredCount = count;

            if (storeValues)
            {
                values.Add(val);
            }
            if (Handlers.Count > 0)
            {
                if (timer != null)
                {
                    foreach (var h in handlers)
                    {
                        var t = h.BeginTimer((TimerCounter)this, val);
                        if (t != null)
                        {
                            timer.AddHandlerTracker(t);
                        }
                    }
                }
                else
                {
                    foreach (var h in handlers)
                    {
                        h.ConsumeValue(this, val);
                    }
                }
            }
            return(values.Count - 1);
        }
Exemple #5
0
        public ITimeTracker BeginTiming(string message)
        {
            ITimeTracker timer;

            if (!InstrumentationService.Enabled)
            {
                timer = dummyTimer;
            }
            else
            {
                lock (values) {
                    timer = lastTimer = new TimeCounter(this);
                    count++;
                    int i = StoreValue(message, lastTimer.TraceList);
                    lastTimer.TraceList.ValueIndex = i;
                }
            }
            if (LogMessages && message != null)
            {
                InstrumentationService.LogMessage(message);
            }
            return(timer);
        }
		public ITimeTracker BeginTiming (string message)
		{
			ITimeTracker timer;
			if (!Enabled) {
				timer = dummyTimer;
			} else {
				var c = new TimeCounter (this);
				lock (values) {
					timer = lastTimer = c;
					count++;
					int i = StoreValue (message, lastTimer);
					lastTimer.TraceList.ValueIndex = i;
				}
			}
			if (LogMessages && message != null)
				InstrumentationService.LogMessage (message);
			return timer;
		}
Exemple #7
0
		internal int StoreValue (string message, TimeCounter timer)
		{
			DateTime now = DateTime.Now;
			if (resolution.Ticks != 0) {
				if (now - lastValueTime < resolution)
					return -1;
			}
			var val = new CounterValue (count, totalCount, count - lastStoredCount, now, message, timer != null ? timer.TraceList : null);
			lastStoredCount = count;

			if (storeValues)
				values.Add (val);
			if (Handlers.Count > 0) {
				if (timer != null) {
					foreach (var h in handlers) {
						var t = h.BeginTimer ((TimerCounter)this, val);
						if (t != null)
							timer.AddHandlerTracker (t);
					}
				} else {
					foreach (var h in handlers)
						h.ConsumeValue (this, val);
				}
			}
			return values.Count - 1;
		}