/// <summary>Measures the rule execution time and adds this sample to performance counter.</summary> /// <param name="rule">Rule being measured.</param> /// <returns><see cref="IDisposable"/> that should be disposed after rule has finished it's execution.</returns> public IDisposable MeasureRuleExecutionTime(IConsensusRuleBase rule) { var stopwatch = new StopwatchDisposable(elapsedTicks => { this.currentSnapshot.PerformanceInfo[rule].AddTicks(elapsedTicks); }); return(stopwatch); }
/// <summary>Measures the rule execution time and adds this sample to performance counter.</summary> /// <param name="rule">Rule being measured.</param> /// <returns><see cref="IDisposable"/> that should be disposed after rule has finished it's execution.</returns> public IDisposable MeasureRuleExecutionTime(IConsensusRuleBase rule) { var stopwatch = new StopwatchDisposable(elapsedTicks => { RulePerformance performance = this.currentSnapshot.PerformanceInfo[rule]; Interlocked.Increment(ref performance.CalledTimes); Interlocked.Add(ref performance.ExecutionTimesTicks, elapsedTicks); }); return(stopwatch); }