/// <summary> /// Initializes a new instance of the <see cref="DurationPerformanceResult"/> class. /// </summary> public DurationPerformanceResult(DurationPerformanceCalculator calculator, DateTime timestampKey, long sumAvgTicks, long sumMaxTicks, long sumMinTicks) : base(calculator, timestampKey) { this.SumAverageTicks = sumAvgTicks; this.SumMaxTicks = sumMaxTicks; this.SumMinTicks = sumMinTicks; }
/// <summary> /// Executes the given action and measures the time it took in total. /// </summary> /// <param name="activity">The Activity to report to.</param> /// <param name="actionToExecute">The action to be executed and measured.</param> public void ExecuteAndMeasureActivityDuration(string activity, Action actionToExecute) { DurationPerformanceCalculator kpiCalculator = GetKpiCalculator <DurationPerformanceCalculator>(activity); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); try { actionToExecute(); } finally { kpiCalculator.NotifyActivityDuration(stopwatch.ElapsedMilliseconds); } }
/// <summary> /// Notifies that the given activity took the given count of ticks. /// </summary> /// <param name="activity">The Activity to report to.</param> /// <param name="durationTicks">Total count of ticks to be notified.</param> public void NotifyActivityDuration(string activity, long durationTicks) { DurationPerformanceCalculator kpiCalculator = GetKpiCalculator <DurationPerformanceCalculator>(activity); kpiCalculator.NotifyActivityDuration(durationTicks); }