Ejemplo n.º 1
0
        private static bool CheckBenchmark(
            Benchmark benchmark,
            CompetitionMetricValue metricValue,
            SummaryAnalysis analysis)
        {
            var summary = analysis.Summary;
            var metric  = metricValue.Metric;

            var actualValues = metric.ValuesProvider.TryGetActualValues(benchmark, summary);

            if (actualValues.IsEmpty)
            {
                analysis.AddTestErrorConclusion(
                    benchmark.Target,
                    $"Could not obtain {metric} metric values for {benchmark.DisplayInfo}.",
                    summary[benchmark]);

                return(true);
            }

            if (metricValue.ValuesRange.ContainsWithRounding(actualValues, metricValue.DisplayMetricUnit))
            {
                return(true);
            }

            bool checkPassed;

            if (metricValue.ValuesRange.IsEmpty)
            {
                // Check passed if empty & adjustment is disabled.
                checkPassed = !analysis.Options.Adjustments.AdjustMetrics && !analysis.Options.Adjustments.ForceEmptyMetricsAdjustment;
            }
            else
            {
                analysis.AddTestErrorConclusion(
                    benchmark.Target,
                    $"Metric {metric} {actualValues.ToString(metric.MetricUnits)} is out of limit {metricValue}.",
                    summary[benchmark]);

                checkPassed = false;
            }

            if (PerformAdjustment(analysis, metricValue))
            {
                var limitValues = metric.ValuesProvider.TryGetLimitValues(benchmark, analysis.Summary);
                metricValue.UnionWith(
                    new CompetitionMetricValue(
                        metric,
                        limitValues,
                        metric.MetricUnits[limitValues]),
                    false);
            }

            return(checkPassed);
        }
Ejemplo n.º 2
0
        private static bool PerformAdjustment(Analysis analysis, CompetitionMetricValue metricValue)
        {
            var adjustmentMode = analysis.Options.Adjustments;

            var adjustEmpty = metricValue.ValuesRange.IsEmpty && adjustmentMode.ForceEmptyMetricsAdjustment;

            if (adjustmentMode.AdjustMetrics || adjustEmpty)
            {
                return(analysis.RunState.RunNumber > adjustmentMode.SkipRunsBeforeAdjustment);
            }

            return(false);
        }
Ejemplo n.º 3
0
        /// <summary>Combines metric value with specified one.</summary>
        /// <param name="other">The metric value to merge.</param>
        /// <param name="forceMetricUnitUpdate">
        /// If set to <c>true</c> existing <see cref="DisplayMetricUnit"/> is updated even if it is not empty.
        /// </param>
        /// <returns><c>true</c> if was updated.</returns>
        public bool UnionWith([NotNull] CompetitionMetricValue other, bool forceMetricUnitUpdate)
        {
            if (other.Metric != Metric)
            {
                throw CodeExceptions.Argument(
                          nameof(other),
                          $"Passed value metric {other.Metric} does not match to this one {Metric}.");
            }

            if (other.ValuesRange.IsEmpty)
            {
                return(false);
            }

            var result = false;

            var newValues = ValuesRange.Union(other.ValuesRange);

            if (newValues != ValuesRange)
            {
                ValuesRange       = newValues;
                HasUnsavedChanges = true;

                result = true;
            }

            if (DisplayMetricUnit.IsEmpty || forceMetricUnitUpdate)
            {
                var metricUnit = other.DisplayMetricUnit;
                if (metricUnit.IsEmpty)
                {
                    metricUnit = Metric.MetricUnits[ValuesRange];
                }

                if (DisplayMetricUnit != metricUnit)
                {
                    DisplayMetricUnit = metricUnit;
                    HasUnsavedChanges = true;

                    result = true;
                }
            }

            return(result);
        }