internal ConsensusRulesPerformanceSnapshot(IEnumerable <RuleItem> rulesToTrack)
        {
            this.PerformanceInfo = new Dictionary <IConsensusRuleBase, RulePerformance>();

            foreach (RuleItem rule in rulesToTrack)
            {
                var perf = new RulePerformance(rule);
                this.PerformanceInfo.Add(rule.RuleReferenceInstance, perf);
            }
        }
Example #2
0
        /// <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);
        }