Example #1
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);
        }
Example #2
0
 public override void Trace(string message)
 {
     if (Enabled)
     {
         if (lastTimer != null)
         {
             lastTimer.Trace(message);
         }
         else
         {
             lock (values) {
                 StoreValue(message, null, null);
             }
         }
     }
     else if (LogMessages)
     {
         if (lastTimer != null)
         {
             lastTimer.Trace(message);
         }
         else if (message != null)
         {
             InstrumentationService.LogMessage(message);
         }
     }
 }
Example #3
0
 public void Trace(string message)
 {
     if (traceList != null)
     {
         TimerTrace t = new TimerTrace();
         t.Timestamp = DateTime.Now;
         t.Message   = message;
         if (lastTrace == null)
         {
             lastTrace = traceList.FirstTrace = t;
         }
         else
         {
             lastTrace.Next = t;
             lastTrace      = t;
         }
         traceList.TotalTime = t.Timestamp - traceList.FirstTrace.Timestamp;
     }
     else
     {
         var time = stopWatch.ElapsedMilliseconds;
         InstrumentationService.LogMessage(string.Format("[{0} (+{1})] {2}", time, (time - lastTraceTime), message));
         lastTraceTime = time;
     }
 }
Example #4
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);
        }
Example #5
0
 public virtual void Trace(string message)
 {
     if (Enabled)
     {
         lock (values) {
             StoreValue(message, null, null);
         }
     }
     if (logMessages && message != null)
     {
         InstrumentationService.LogMessage(message);
     }
 }
Example #6
0
 public void Dec(int n, string message, IDictionary <string, object> metadata)
 {
     if (Enabled)
     {
         lock (values) {
             count -= n;
             StoreValue(message, null, metadata);
         }
     }
     if (logMessages && message != null)
     {
         InstrumentationService.LogMessage(message);
     }
 }
Example #7
0
 public void SetValue(int value, string message)
 {
     if (InstrumentationService.Enabled)
     {
         lock (values) {
             count = value;
             StoreValue(message, null);
         }
     }
     if (logMessages && message != null)
     {
         InstrumentationService.LogMessage(message);
     }
 }
Example #8
0
        public void End()
        {
            if (!stopWatch.IsRunning)
            {
                Console.WriteLine("Timer already finished");
                return;
            }

            stopWatch.Stop();
            Duration = stopWatch.Elapsed;

            if (metadata != null && cancellationToken != CancellationToken.None && cancellationToken.IsCancellationRequested)
            {
                metadata.Result = CounterResult.UserCancel;
            }

            if (counter.LogMessages)
            {
                var time = stopWatch.ElapsedMilliseconds;
                InstrumentationService.LogMessage(string.Format("[{0} (+{1})] END: {2}", time, (time - lastTraceTime), counter.Name));
            }

            if (traceList != null)
            {
                traceList.TotalTime = TimeSpan.FromMilliseconds(stopWatch.ElapsedMilliseconds);
                if (traceList.TotalTime.TotalSeconds < counter.MinSeconds)
                {
                    counter.RemoveValue(traceList.ValueIndex);
                }
                else
                {
                    counter.AddTime(traceList.TotalTime);
                }
            }

            counter = null;

            if (linkedTrackers is List <IDisposable> )
            {
                foreach (var t in (List <IDisposable>)linkedTrackers)
                {
                    t.Dispose();
                }
            }
            else if (linkedTrackers != null)
            {
                ((IDisposable)linkedTrackers).Dispose();
            }
            stopWatch.Reset();
        }
Example #9
0
 public void Dec(int n, string message)
 {
     if (enabled)
     {
         lock (values) {
             count -= n;
             StoreValue(message, null);
         }
     }
     if (logMessages && message != null)
     {
         InstrumentationService.LogMessage(message);
     }
 }
Example #10
0
 public void SetValue(int value, string?message, IDictionary <string, object>?metadata)
 {
     if (Enabled)
     {
         lock (values) {
             count = value;
             StoreValue(message, null, metadata);
         }
     }
     if (logMessages && message != null)
     {
         InstrumentationService.LogMessage(message);
     }
 }
Example #11
0
 public void Inc(int n, string message, IDictionary <string, string> metadata)
 {
     if (enabled)
     {
         lock (values) {
             count      += n;
             totalCount += n;
             StoreValue(message, null, metadata);
         }
     }
     if (logMessages && message != null)
     {
         InstrumentationService.LogMessage(message);
     }
 }
Example #12
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 IEnumerable <CounterCategory> GetCategories()
 {
     return(InstrumentationService.GetCategories());
 }
 public CounterCategory GetCategory(string name)
 {
     return(InstrumentationService.GetCategory(name));
 }
 public Counter GetCounter(string name)
 {
     return(InstrumentationService.GetCounter(name));
 }
 public IEnumerable <Counter> GetCounters()
 {
     return(InstrumentationService.GetCounters());
 }
Example #17
0
 internal void UpdateStatus()
 {
     InstrumentationService.InitializeHandlers();
 }
Example #18
0
 internal void UpdateStatus()
 {
     InstrumentationService.InitializeHandlers();
     enabled     = InstrumentationService.Enabled || Handlers.Count > 0;
     storeValues = InstrumentationService.Enabled;
 }