示例#1
0
 /// <summary>
 /// Returns an object whose lifetime is measured and is added
 /// to the counter described by passed
 /// <see cref="CounterDescriptor"/> object.
 /// Time is meaasured in <see cref="TimeSpan"/> ticks.
 /// Can return null if <see cref="Writer"/> is a Null writer.
 /// </summary>
 public IDisposable IncrementTicks(CounterDescriptor counter)
 {
     if (owner == null)
     {
         return(null);
     }
     return(new TimeMeasurer(this, counter));
 }
示例#2
0
 /// <summary>
 /// Increments the value of the counter specified by
 /// <see cref="CounterDescriptor"/> object.
 /// </summary>
 public void Increment(CounterDescriptor counter, long value = 1)
 {
     if (owner != null)
     {
         Interlocked.Add(ref counter.value, value);
         if (counter.reportCount)
         {
             Interlocked.Increment(ref counter.count);
         }
     }
 }
示例#3
0
        public CounterDescriptor AddCounter(
            string name,
            string unit      = null,
            bool reportCount = false
            )
        {
            var counter = new CounterDescriptor
            {
                name        = name,
                unitSuffix  = !string.IsNullOrEmpty(unit) ? $" {unit}" : "",
                reportCount = reportCount
            };

            counters.Add(counter);
            return(counter);
        }
示例#4
0
 public TimeMeasurer(Writer writer, CounterDescriptor counter)
 {
     this.writer  = writer;
     this.counter = counter;
     this.sw      = System.Diagnostics.Stopwatch.StartNew();
 }