/// <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)); }
/// <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); } } }
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); }
public TimeMeasurer(Writer writer, CounterDescriptor counter) { this.writer = writer; this.counter = counter; this.sw = System.Diagnostics.Stopwatch.StartNew(); }