/// <summary>
        /// Refills the competition targets collection and fills competition limits from the <see cref="PreviousRunLogUri"/>.
        /// </summary>
        /// <param name="competitionTargets">The collection to be filled with competition targets.</param>
        /// <param name="summary">Summary for the run.</param>
        /// <param name="competitionState">State of the run.</param>
        protected override void FillCompetitionTargets(
            CompetitionTargets competitionTargets, Summary summary, CompetitionState competitionState)
        {
            base.FillCompetitionTargets(competitionTargets, summary, competitionState);

            if (string.IsNullOrEmpty(PreviousRunLogUri))
            {
                return;
            }

            var xmlAnnotationDocs = ReadXmlAnnotationDocsFromLog(summary, competitionState);

            if (xmlAnnotationDocs.Length == 0)
            {
                competitionState.WriteMessage(
                    MessageSource.Analyser, MessageSeverity.Warning,
                    $"No XML annotation documents in the log '{PreviousRunLogUri}'.");

                return;
            }

            // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
            if (TryFillCompetitionTargetsFromLog(competitionTargets, xmlAnnotationDocs, competitionState))
            {
                competitionState.WriteMessage(
                    MessageSource.Analyser, MessageSeverity.Informational,
                    $"Competition limits were updated from log file '{PreviousRunLogUri}'.");
            }
            else
            {
                competitionState.WriteMessage(
                    MessageSource.Analyser, MessageSeverity.Informational,
                    $"Competition limits do not require update. Log file: '{PreviousRunLogUri}'.");
            }
        }
        // ReSharper disable once SuggestBaseTypeForParameter
        private bool TryFillCompetitionTargetsFromLog(
            CompetitionTargets competitionTargets, XDocument[] xmlAnnotationDocs, CompetitionState competitionState)
        {
            competitionState.Logger.WriteLineInfo(
                $"{LogVerbosePrefix} Parsing XML annotations ({xmlAnnotationDocs.Length} doc(s)) from log '{PreviousRunLogUri}'.");

            bool updated = false;

            foreach (var competitionTarget in competitionTargets.Values)
            {
                bool hasAnnotations = false;

                foreach (var doc in xmlAnnotationDocs)
                {
                    var parsedLimit = XmlAnnotations.TryParseCompetitionLimit(competitionTarget.Target, doc, competitionState);
                    if (parsedLimit != null)
                    {
                        hasAnnotations = true;
                        updated       |= competitionTarget.UnionWith(parsedLimit);
                    }
                }

                if (!hasAnnotations)
                {
                    competitionState.WriteMessage(
                        MessageSource.Analyser, MessageSeverity.Warning,
                        $"No logged XML annotation for {competitionTarget.Target.MethodTitle} found. Check if the method was renamed.");
                }
            }

            return(updated);
        }
Ejemplo n.º 3
0
        private bool TryInitialize(Summary summary, CompetitionTargets competitionTargets, CompetitionState competitionState)
        {
            if (competitionTargets.Initialized)
            {
                return(true);
            }

            FillCompetitionTargets(competitionTargets, summary, competitionState);
            competitionTargets.SetInitialized();

            return(!competitionState.HasCriticalErrorsInRun);
        }
Ejemplo n.º 4
0
        /// <summary>Refills the competition targets collection.</summary>
        /// <param name="competitionTargets">The collection to be filled with competition targets.</param>
        /// <param name="summary">Summary for the run.</param>
        /// <param name="competitionState">State of the run.</param>
        protected virtual void FillCompetitionTargets(
            CompetitionTargets competitionTargets,
            Summary summary,
            CompetitionState competitionState)
        {
            // DONTTOUCH: DO NOT add return into the if clause.
            // The competitionTargets should be filled with empty limits if IgnoreExistingAnnotations set to false
            if (IgnoreExistingAnnotations)
            {
                competitionState.WriteMessage(
                    MessageSource.Analyser,
                    MessageSeverity.Informational,
                    $"Existing benchmark limits are ignored due to {nameof(IgnoreExistingAnnotations)} setting.");
            }

            bool hasBaseline = false;

            competitionTargets.Clear();

            var targets = summary.GetExecutionOrderBenchmarks()
                          .Select(b => b.Target)
                          .ToHashSet();

            if (targets.Count == 0)
            {
                return;
            }

            var targetType = targets.First().Type;

            var competitionMetadata = AttributeAnnotations.TryGetCompetitionMetadata(targetType);

            foreach (var target in targets)
            {
                hasBaseline |= target.Baseline;

                var competitionTarget = TryParseCompetitionTarget(target, competitionMetadata, competitionState);
                if (competitionTarget != null)
                {
                    competitionTargets.Add(target.Method, competitionTarget);
                }
            }

            if (!hasBaseline && competitionTargets.Any())
            {
                competitionState.WriteMessage(
                    MessageSource.Analyser, MessageSeverity.SetupError,
                    $"The benchmark {targetType.Name} has no baseline.");
            }
        }
Ejemplo n.º 5
0
        private void AnalyseCore(
            Summary summary, CompetitionTargets competitionTargets,
            CompetitionState competitionState, List <IWarning> warnings)
        {
            if (competitionState.HasCriticalErrorsInRun)
            {
                return;
            }

            if (!TryInitialize(summary, competitionTargets, competitionState))
            {
                return;
            }

            if (competitionTargets.Any())
            {
                CheckCompetitionLimitsCore(summary, competitionState, warnings);
            }
            else
            {
                CheckPostconditions(summary, competitionState, warnings);
            }
        }