public static CompetitionTarget[] TryAnnotateBenchmarkFiles( [NotNull] CompetitionTarget[] targetsToAnnotate, [NotNull] CompetitionState competitionState) { Code.NotNull(targetsToAnnotate, nameof(targetsToAnnotate)); Code.NotNull(competitionState, nameof(competitionState)); var annotatedTargets = new List <CompetitionTarget>(); var annContext = new AnnotateContext(); var logger = competitionState.Logger; foreach (var targetToAnnotate in targetsToAnnotate) { var target = targetToAnnotate.Target; var targetMethodTitle = target.MethodTitle; logger.WriteLineInfo( $"{LogVerbosePrefix} Method {targetMethodTitle}: updating time limits {targetToAnnotate}."); // DONTTOUCH: the source should be loaded for checksum validation even if target uses resource annotation. string fileName; int firstCodeLine; bool hasSource = SymbolHelpers.TryGetSourceInfo(target.Method, competitionState, out fileName, out firstCodeLine); if (!hasSource) { continue; } var competitionMetadata = targetToAnnotate.CompetitionMetadata; if (competitionMetadata != null) { var resourceFileName = GetResourceFileName(fileName, competitionMetadata); logger.WriteLineInfo( $"{LogVerbosePrefix} Method {targetMethodTitle}: annotating resource file '{resourceFileName}'."); var annotated = TryFixBenchmarkXmlAnnotation(annContext, resourceFileName, targetToAnnotate, competitionState); if (!annotated) { competitionState.WriteMessage( MessageSource.Analyser, MessageSeverity.Warning, $"Method {targetMethodTitle}: could not annotate resource file '{resourceFileName}'.", null); continue; } } else { logger.WriteLineInfo( $"{LogVerbosePrefix} Method {targetMethodTitle}: annotating file '{fileName}', line {firstCodeLine}."); var annotated = TryFixBenchmarkAttribute(annContext, fileName, firstCodeLine, targetToAnnotate, competitionState); if (!annotated) { competitionState.WriteMessage( MessageSource.Analyser, MessageSeverity.Warning, $"Method {targetMethodTitle}: could not annotate source file '{fileName}'."); continue; } } logger.WriteLineInfo( $"{LogImportantInfoPrefix} Method {targetMethodTitle} updated time limits: {targetToAnnotate}."); annotatedTargets.Add(targetToAnnotate); } annContext.Save(); return(annotatedTargets.ToArray()); }
private void AnnotateBenchmarkFiles( Summary summary, CompetitionAnalyser competitionAnalyser, ILogger logger, List <IWarning> warnings) { var annContext = new AnnotateContext(); var competitionTargets = competitionAnalyser.GetCompetitionTargets(summary); var newTargets = competitionAnalyser.GetNewCompetitionTargets(summary); if (newTargets.Length == 0) { logger.WriteLineInfo("All competition benchmarks are in boundary."); return; } foreach (var newTarget in newTargets) { var targetMethodName = newTarget.CandidateName; logger.WriteLineInfo($"Method {targetMethodName}: new boundary [{newTarget.MinText},{newTarget.MaxText}]."); int firstCodeLine; string fileName; bool hasSource = TryGetSourceInfo(newTarget, out fileName, out firstCodeLine); if (!hasSource) { throw new InvalidOperationException($"Method {targetMethodName}: could not annotate. Source file not found."); } if (newTarget.UsesResourceAnnotation) { var resourceFileName = Path.ChangeExtension(fileName, ".xml"); logger.WriteLineInfo( $"Method {targetMethodName}: annotate resource file {resourceFileName}."); bool annotated = TryFixBenchmarkResource(annContext, resourceFileName, newTarget); if (!annotated) { throw new InvalidOperationException( $"Method {targetMethodName}: could not annotate resource file {resourceFileName}."); } } else { logger.WriteLineInfo($"Method {targetMethodName}: annotate at line {firstCodeLine}, file {fileName}."); bool annotated = TryFixBenchmarkAttribute(annContext, fileName, firstCodeLine, newTarget); if (!annotated) { throw new InvalidOperationException($"Method {targetMethodName}: could not annotate. Source file {fileName}."); } } if (RerunIfModified && !competitionAnalyser.LastRun) { var message = $"Method {targetMethodName} annotation updated, benchmark has to be restarted"; logger.WriteLineInfo(message); warnings.Add(new Warning(nameof(AnnotateSourceAnalyser), message, null)); competitionTargets[newTarget.Target] = newTarget; competitionAnalyser.RerunRequested = true; } else { var message = $"Method {targetMethodName} annotation updated."; logger.WriteLineInfo(message); warnings.Add(new Warning(nameof(AnnotateSourceAnalyser), message, null)); } } annContext.Save(); }