Beispiel #1
0
        /// <summary>Retrieves stored info for competition targets from XML annotation docs.</summary>
        /// <param name="competitionTargets">Competition targets the metrics are retrieved for.</param>
        /// <param name="xmlAnnotationDocs">The XML annotation docs.</param>
        /// <param name="analysis">State of the analysis.</param>
        /// <returns>Stored info for competition targets.</returns>
        public static bool TryFillCompetitionTargetsFromLog(
            IReadOnlyCollection <CompetitionTarget> competitionTargets,
            XDocument[] xmlAnnotationDocs,
            Analysis analysis)
        {
            analysis.Logger.WriteVerbose($"Parsing XML annotations ({xmlAnnotationDocs.Length} doc(s)) from log.");

            var updated       = false;
            var targetsToFill = competitionTargets.Select(t => t.Target).ToArray();
            var metrics       = analysis.Config.GetMetrics().ToArray();

            // TODO: common api to write message for multiple target + metrics.

            foreach (var doc in xmlAnnotationDocs)
            {
                var storedTargets = XmlAnnotationHelpers.TryGetStoredTargets(
                    targetsToFill, metrics, doc, true, analysis);

                foreach (var competitionTarget in competitionTargets)
                {
                    var storedTarget = storedTargets.GetValueOrDefault(competitionTarget.Target);
                    if (storedTarget == null)
                    {
                        continue;
                    }

                    var parsedCompetitionTarget = ParseCompetitionTarget(
                        competitionTarget.Target,
                        metrics, storedTarget, analysis);

                    var parsedMetrics = parsedCompetitionTarget.MetricValues.ToDictionary(m => m.Metric);

                    var hasAnnotations = false;
                    foreach (var metricValue in competitionTarget.MetricValues)
                    {
                        if (!parsedMetrics.TryGetValue(metricValue.Metric, out var parsedMetricValue))
                        {
                            continue;
                        }

                        hasAnnotations = true;

                        updated |= metricValue.UnionWith(parsedMetricValue, true);
                    }

                    if (!hasAnnotations && analysis.SafeToContinue && parsedMetrics.Any())
                    {
                        analysis.WriteWarningMessage(
                            $"No logged XML annotation for {competitionTarget.Target.MethodDisplayInfo} found. Check if the method was renamed.");
                    }
                }
            }

            return(updated);
        }
Beispiel #2
0
        /// <summary>Retrieves stored info for competition targets.</summary>
        /// <param name="targets">Competition targets the metrics are retrieved for.</param>
        /// <param name="analysis">State of the analysis.</param>
        /// <returns>Stored info for competition targets.</returns>
        protected override IReadOnlyDictionary <Target, StoredTargetInfo> GetStoredTargets(
            Target[] targets, Analysis analysis)
        {
            var resourceKey = GetResourceKey(analysis.RunState.BenchmarkType);

            var xmlAnnotationDoc = XmlAnnotationHelpers.TryParseXmlAnnotationDoc(resourceKey, analysis);

            if (xmlAnnotationDoc == null)
            {
                return(new Dictionary <Target, StoredTargetInfo>());
            }

            var metrics = analysis.Config.GetMetrics();
            var result  = XmlAnnotationHelpers.TryGetStoredTargets(
                targets, metrics,
                xmlAnnotationDoc,
                UseFullTypeName,
                analysis);

            return(result);
        }