internal static CompetitionState Run( [NotNull] Type benchmarkType, [NotNull] ICompetitionConfig competitionConfig) { Code.NotNull(benchmarkType, nameof(benchmarkType)); Code.NotNull(competitionConfig, nameof(competitionConfig)); var runStateSlots = competitionConfig.GetValidators().OfType <RunStateSlots>(); if (runStateSlots.Count() != 1) { throw CodeExceptions.Argument( nameof(competitionConfig), $"The competition config should include single instance of {nameof(RunStateSlots)} validator."); } var competitionState = RunState[competitionConfig]; try { competitionState.FirstTimeInit(benchmarkType, competitionConfig); var logger = competitionState.Logger; using (BeginLogImportant(competitionConfig)) { logger.WriteSeparatorLine(benchmarkType.Name, true); logger.WriteLineHelp($"{LogInfoPrefix} {benchmarkType.GetShortAssemblyQualifiedName()}"); } using (var mutex = new Mutex(false, $"Global\\{typeof(CompetitionCore).FullName}")) { var lockTaken = false; try { var timeout = competitionState.Options.RunOptions.Concurrent == ConcurrentRunBehavior.Lock ? TotalWaitTimeout : TimeSpan.Zero; lockTaken = SpinWait(mutex, timeout, SpinWaitRunTimeout, competitionState); if (CheckPreconditions(benchmarkType, lockTaken, competitionState)) { RunCore(benchmarkType, competitionState); } } finally { if (lockTaken) { mutex.ReleaseMutex(); } } } } catch (TargetInvocationException ex) { competitionState.WriteExceptionMessage( MessageSource.Runner, MessageSeverity.ExecutionError, $"Benchmark {benchmarkType.Name} failed.", ex.InnerException ?? ex); } catch (Exception ex) { competitionState.WriteExceptionMessage( MessageSource.Runner, MessageSeverity.ExecutionError, $"Benchmark {benchmarkType.Name} failed.", ex); } finally { LoggerHelpers.FlushLoggers(competitionConfig); } competitionState.CompetitionCompleted(); return(competitionState); }
/// <summary>Override competition validators.</summary> /// <param name="competitionConfig">The competition config.</param> /// <returns>The validators for the competition</returns> protected virtual List <IValidator> OverrideValidators([NotNull] ICompetitionConfig competitionConfig) => competitionConfig.GetValidators().ToList();