コード例 #1
0
        public void TestFilteringLoggerImportantArea()
        {
            var lines = LogInput.Split(new[] { "\r\n" }, StringSplitOptions.None);

            var output = new AccumulationLogger();
            var logger = new FilteringLogger(output, FilteringLoggerMode.AllMessages);

            var config = new ManualConfig();

            config.Add(logger);

            using (LoggerHelpers.BeginImportantLogScope(config))
            {
                foreach (var line in lines)
                {
                    logger.WriteLine(line);
                }
                Assert.AreEqual(output.GetLog(), LogInput + "\r\n");

                output = new AccumulationLogger();
                logger = new FilteringLogger(output, FilteringLoggerMode.AllMessages);
                var i = 0;
                foreach (var line in lines)
                {
                    if (i++ % 2 == 0)
                    {
                        logger.WriteLineError(line);
                    }
                    else
                    {
                        logger.WriteLineHint(line);
                    }
                }
                Assert.AreEqual(output.GetLog(), LogInput + "\r\n");

                output = new AccumulationLogger();
                logger = new FilteringLogger(output, FilteringLoggerMode.AllMessages);
                LogMessages(logger);
                // ReSharper disable once StringLiteralTypo
                const string Expected = @"ABCDEFGH
TST0
// !TST1
TST2
// !<--
TST3
// !<--
TST4

TST5
// !-->
TST6
// !-->
TST7
TST8
// !TST9
TST10
";
                Assert.AreEqual(output.GetLog(), Expected);
            }
        }
コード例 #2
0
        private static void LogCompetitionHeader(CompetitionState competitionState)
        {
            var logger        = competitionState.Logger;
            var benchmarkType = competitionState.BenchmarkType;

            using (LoggerHelpers.BeginImportantLogScope(competitionState.Config))
            {
                logger.WriteSeparatorLine(benchmarkType.Name, true);
                logger.WriteHelpHintLine(benchmarkType.GetShortAssemblyQualifiedName());
            }
        }
コード例 #3
0
        private void ProcessRunComplete([NotNull] CompetitionState competitionState)
        {
            var logger  = competitionState.Logger;
            var summary = competitionState.LastRunSummary;

            if (summary == null)
            {
                return;
            }

            logger.WriteVerboseLine($"{competitionState.BenchmarkType.Name} completed.");

            if (competitionState.Options.RunOptions.DetailedLogging)
            {
                var messages = competitionState.GetMessages();

                if (messages.Any())
                {
                    logger.WriteSeparatorLine("All messages");
                    foreach (var message in messages)
                    {
                        logger.LogMessage(message);
                    }
                }
                else
                {
                    logger.WriteSeparatorLine();
                    logger.WriteVerboseLine("No messages in run.");
                }

                logger.WriteLine();
            }
            else
            {
                using (LoggerHelpers.BeginImportantLogScope(summary.Config))
                {
                    var summaryLogger = DumpSummaryToHostLogger
                                                ? logger
                                                : new CompositeLogger(
                        summary.Config
                        .GetLoggers()
                        .Where(l => !(l is HostLogger))
                        .ToArray());

                    // Dumping the benchmark summary
                    summaryLogger.WriteSeparatorLine("Summary");
                    MarkdownExporter.Console.ExportToLog(summary, summaryLogger);

                    logger.WriteLine();
                }
            }
        }
コード例 #4
0
        private static void LogCompetitionRunHeader(CompetitionState competitionState)
        {
            var logger = competitionState.Logger;

            using (LoggerHelpers.BeginImportantLogScope(competitionState.Config))
            {
                var run          = competitionState.RunNumber;
                var runsExpected = competitionState.RunNumber + competitionState.RunsLeft;
                var runMessage   = competitionState.RunLimitExceeded
                                        ? $"Run {run}, total runs (expected): {runsExpected} (rerun limit exceeded, last run)"
                                        : $"Run {run}, total runs (expected): {runsExpected}";
                logger.WriteSeparatorLine(runMessage);
            }
        }
コード例 #5
0
        private CompetitionState RunCore(
            [NotNull] Type benchmarkType,
            [CanBeNull] ICompetitionConfig competitionConfig,
            [CanBeNull] CompetitionFeatures competitionFeatures)
        {
            Code.NotNull(benchmarkType, nameof(benchmarkType));

            competitionConfig = CreateBenchmarkConfig(benchmarkType, competitionConfig, competitionFeatures);
            var hostLogger = competitionConfig.GetLoggers().OfType <HostLogger>().Single();

            var previousDirectory = Environment.CurrentDirectory;
            var currentDirectory  = GetOutputDirectory(benchmarkType.Assembly);

            if (currentDirectory == previousDirectory)
            {
                currentDirectory  = null;
                previousDirectory = null;
            }

            CompetitionState competitionState = null;

            try
            {
                SetCurrentDirectoryIfNotNull(currentDirectory);
                try
                {
                    competitionState = CompetitionCore.Run(benchmarkType, competitionConfig);

                    ProcessRunComplete(competitionState);
                }
                finally
                {
                    ReportHostLogger(hostLogger, competitionState?.LastRunSummary);
                }

                using (LoggerHelpers.BeginImportantLogScope(competitionState.Config))
                {
                    ReportMessagesToUser(competitionState);
                }
            }
            finally
            {
                LoggerHelpers.FlushLoggers(competitionConfig);
                SetCurrentDirectoryIfNotNull(previousDirectory);
            }

            return(competitionState);
        }