Пример #1
0
        static async Task Main(string[] args)
        {
            Console.CancelKeyPress += Console_CancelKeyPress;

            var command = new DATCommand();

            try
            {
                Parser.ParseArguments(command, args);

                using (var logger = new SimpleLogger(command.LoggingLevel, command.LogPath))
                {
                    await RunTest(command, logger, cancellationToken : tokenSource.Token);
                }
            }
            catch (CommandParserException commandExc)
            {
                Console.WriteLine(commandExc.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(command.PrintUsage());
            }
        }
Пример #2
0
        public void Render(DATCommand command, DataCompareResults dataComparisonResult, List <PerformanceResult> performanceResults)
        {
            // data comparison output not supported


            // performance output
            var totalResults      = new List <object[]>();
            var avgResults        = new List <object[]>();
            var percentileResults = new List <object[]>();

            foreach (var performanceResult in performanceResults)
            {
                totalResults.Add(
                    new object[]
                {
                    performanceResult.TestIdentifier,
                    "n/a",
                    performanceResult.Totals.CPUCompileTime,
                    performanceResult.Totals.ElapsedCompileTime,
                    performanceResult.Totals.CPUExecutionTime,
                    performanceResult.Totals.ElapsedExecutionTime,
                    performanceResult.Totals.Scan,
                    performanceResult.Totals.Logical,
                    performanceResult.Totals.Physical,
                    performanceResult.Totals.ReadAhead,
                    performanceResult.Totals.LobLogical,
                    performanceResult.Totals.LobPhysical,
                    performanceResult.Totals.LobReadAhead,
                    performanceResult.Totals.PercentRead
                });

                avgResults.Add(
                    new object[]
                {
                    performanceResult.TestIdentifier,
                    "n/a",
                    performanceResult.Totals.CPUCompileTime,
                    performanceResult.Totals.ElapsedCompileTime,
                    performanceResult.Totals.CPUExecutionTime,
                    performanceResult.Totals.ElapsedExecutionTime,
                    performanceResult.Totals.Scan,
                    performanceResult.Totals.Logical,
                    performanceResult.Totals.Physical,
                    performanceResult.Totals.ReadAhead,
                    performanceResult.Totals.LobLogical,
                    performanceResult.Totals.LobPhysical,
                    performanceResult.Totals.LobReadAhead,
                    performanceResult.Totals.PercentRead
                });

                foreach (var percentileKVP in performanceResult.Percentiles)
                {
                    percentileResults.Add(
                        new object[]
                    {
                        performanceResult.TestIdentifier,
                        percentileKVP.Key / 100D,
                        performanceResult.Totals.CPUCompileTime,
                        performanceResult.Totals.ElapsedCompileTime,
                        performanceResult.Totals.CPUExecutionTime,
                        performanceResult.Totals.ElapsedExecutionTime,
                        performanceResult.Totals.Scan,
                        performanceResult.Totals.Logical,
                        performanceResult.Totals.Physical,
                        performanceResult.Totals.ReadAhead,
                        performanceResult.Totals.LobLogical,
                        performanceResult.Totals.LobPhysical,
                        performanceResult.Totals.LobReadAhead,
                        performanceResult.Totals.PercentRead
                    });
                }
            }

            Console.WriteLine();
            Console.WriteLine("Totals");

            ConsoleTableBuilder
            .From(totalResults)
            .WithOptions(new ConsoleTableBuilderOption
            {
                MetaRowPosition = MetaRowPosition.Bottom,
                MetaRowParams   = new object[]
                {
                    "test value 1",
                    2,
                    AppConstants.MetaRow.COLUMN_COUNT,
                    AppConstants.MetaRow.ROW_COUNT
                },
                TrimColumn = true
            })
            .WithFormat(ConsoleTableBuilderFormat.Minimal)
            .WithColumn(new List <string> {
                "TestRunIdentifier", "Percentile", "CPUCompileTime", "ElapsedCompileTime", "CPUExecutionTime", "ElapsedExecutionTime", "Scan", "Logical", "Physical",
                "ReadAhead", "LobLogical", "LobPhysical", "LobReadAhead", "PercentRead"
            })
            .ExportAndWriteLine();

            Console.WriteLine();
            Console.WriteLine("Averages");

            ConsoleTableBuilder
            .From(avgResults)
            .WithOptions(new ConsoleTableBuilderOption
            {
                MetaRowPosition = MetaRowPosition.Bottom,
                MetaRowParams   = new object[]
                {
                    "test value 1",
                    2,
                    AppConstants.MetaRow.COLUMN_COUNT,
                    AppConstants.MetaRow.ROW_COUNT
                },
                TrimColumn = true
            })
            .WithFormat(ConsoleTableBuilderFormat.Minimal)
            .WithColumn(new List <string> {
                "TestRunIdentifier", "Percentile", "CPUCompileTime", "ElapsedCompileTime", "CPUExecutionTime", "ElapsedExecutionTime", "Scan", "Logical", "Physical",
                "ReadAhead", "LobLogical", "LobPhysical", "LobReadAhead", "PercentRead"
            })
            .ExportAndWriteLine();

            Console.WriteLine();
            Console.WriteLine("Percentiles");

            ConsoleTableBuilder
            .From(percentileResults.OrderBy(i => (double)i[1]).ToList())
            .WithOptions(new ConsoleTableBuilderOption
            {
                MetaRowPosition = MetaRowPosition.Bottom,
                MetaRowParams   = new object[]
                {
                    "test value 1",
                    2,
                    AppConstants.MetaRow.COLUMN_COUNT,
                    AppConstants.MetaRow.ROW_COUNT
                },
                TrimColumn = true
            })
            .WithFormat(ConsoleTableBuilderFormat.Minimal)
            .WithColumn(new List <string> {
                "TestRunIdentifier", "Percentile", "CPUCompileTime", "ElapsedCompileTime", "CPUExecutionTime", "ElapsedExecutionTime", "Scan", "Logical", "Physical",
                "ReadAhead", "LobLogical", "LobPhysical", "LobReadAhead", "PercentRead"
            })
            .ExportAndWriteLine();
        }
Пример #3
0
        private static async Task RunTest(DATCommand command, ILogger logger, CancellationToken cancellationToken)
        {
            logger.Log(LogLevel.Minimal, $"Beginning test with {command.TestRunConfig.ThreadCount} threads, {command.TestRunConfig.Iterations} iterations.");

            // let's get some tests setup in this mug
            var testTasks = command.TestRunConfig.Tests.Select((testRunConfig) =>
            {
                var testRunParams = new DATTestParameters
                {
                    ConnectionString = testRunConfig.ConnectionString,
                    Iterations       = command.TestRunConfig.Iterations,
                    SqlQuery         = ResolveQuery(testRunConfig.SQL)
                };

                return(RunTestGroup(testRunParams, ResolveQuery(testRunConfig.PreSQL), command.TestRunConfig.ThreadCount, logger, cancellationToken: cancellationToken));
            });

            // wait'em'out
            // TODO: How's the order of this work??
            var testResults = await Task.WhenAll(testTasks);

            // now what?
            var dataCompare        = command.DataCompare;
            var performanceProfile = command.PerformanceProfile;

            DataCompareResults dataComparisonResult            = null;
            IEnumerable <PerformanceResult> performanceResults = null;

            // compare the shizzle
            if (dataCompare)
            {
                dataComparisonResult = testResults.ToList().CompareTestResults();
                // heyyy we got some performance data now
            }

            // how'd it perform 'do?
            if (performanceProfile)
            {
                var percentiles = new List <int> {
                    50, 75, 99
                };
                performanceResults = testResults.Select((testResult) =>
                {
                    var test1AggregatedResults = testResult.SelectMany(t => t)
                                                 .SelectMany(t => t.QueryStatistics)
                                                 .Cast <QueryStats>()
                                                 .Select(r => new QueryStatTotals
                    {
                        CPUCompileTime       = r.CompileTimes.Sum(i => i.CPU),
                        ElapsedCompileTime   = r.CompileTimes.Sum(i => i.Elapsed),
                        CPUExecutionTime     = r.ExecutionTimes.Sum(i => i.CPU),
                        ElapsedExecutionTime = r.ExecutionTimes.Sum(i => i.Elapsed),
                        Scan         = r.IOStatistics.Sum(i => i.Scan),
                        Physical     = r.IOStatistics.Sum(i => i.Physical),
                        Logical      = r.IOStatistics.Sum(i => i.Logical),
                        LobLogical   = r.IOStatistics.Sum(i => i.LobLogical),
                        LobPhysical  = r.IOStatistics.Sum(i => i.LobPhysical),
                        LobReadAhead = r.IOStatistics.Sum(i => i.LobReadAhead),
                        PercentRead  = r.IOStatistics.Sum(i => i.PercentRead),
                        ReadAhead    = r.IOStatistics.Sum(i => i.ReadAhead)
                    });

                    var test1Totals = new QueryStatTotals
                    {
                        CPUCompileTime       = test1AggregatedResults.Sum(i => i.CPUCompileTime),
                        ElapsedCompileTime   = test1AggregatedResults.Sum(i => i.ElapsedCompileTime),
                        CPUExecutionTime     = test1AggregatedResults.Sum(i => i.CPUExecutionTime),
                        ElapsedExecutionTime = test1AggregatedResults.Sum(i => i.ElapsedExecutionTime),
                        Scan         = test1AggregatedResults.Sum(i => i.Scan),
                        Physical     = test1AggregatedResults.Sum(i => i.Physical),
                        Logical      = test1AggregatedResults.Sum(i => i.Logical),
                        LobLogical   = test1AggregatedResults.Sum(i => i.LobLogical),
                        LobPhysical  = test1AggregatedResults.Sum(i => i.LobPhysical),
                        LobReadAhead = test1AggregatedResults.Sum(i => i.LobReadAhead),
                        PercentRead  = test1AggregatedResults.Sum(i => i.PercentRead),
                        ReadAhead    = test1AggregatedResults.Sum(i => i.ReadAhead)
                    };

                    var test1Averages = new QueryStatTotals
                    {
                        CPUCompileTime       = test1AggregatedResults.Average(i => i.CPUCompileTime),
                        ElapsedCompileTime   = test1AggregatedResults.Average(i => i.ElapsedCompileTime),
                        CPUExecutionTime     = test1AggregatedResults.Average(i => i.CPUExecutionTime),
                        ElapsedExecutionTime = test1AggregatedResults.Average(i => i.ElapsedExecutionTime),
                        Scan         = test1AggregatedResults.Average(i => i.Scan),
                        Physical     = test1AggregatedResults.Average(i => i.Physical),
                        Logical      = test1AggregatedResults.Average(i => i.Logical),
                        LobLogical   = test1AggregatedResults.Average(i => i.LobLogical),
                        LobPhysical  = test1AggregatedResults.Average(i => i.LobPhysical),
                        LobReadAhead = test1AggregatedResults.Average(i => i.LobReadAhead),
                        PercentRead  = test1AggregatedResults.Average(i => i.PercentRead),
                        ReadAhead    = test1AggregatedResults.Average(i => i.ReadAhead)
                    };

                    var test1Percentiles = new Dictionary <int, QueryStatTotals>();
                    foreach (var percentile in percentiles)
                    {
                        int skipCount = (int)Math.Ceiling(((double)test1AggregatedResults.Count()) * ((double)percentile) / 100D);
                        skipCount     = skipCount >= test1AggregatedResults.Count() ? test1AggregatedResults.Count() - 1 : skipCount;

                        test1Percentiles.Add(
                            percentile,
                            new QueryStatTotals
                        {
                            CPUCompileTime       = test1AggregatedResults.OrderBy(i => i.CPUCompileTime).Skip(skipCount).FirstOrDefault().CPUCompileTime,
                            ElapsedCompileTime   = test1AggregatedResults.OrderBy(i => i.ElapsedCompileTime).Skip(skipCount).FirstOrDefault().ElapsedCompileTime,
                            CPUExecutionTime     = test1AggregatedResults.OrderBy(i => i.CPUExecutionTime).Skip(skipCount).FirstOrDefault().CPUExecutionTime,
                            ElapsedExecutionTime = test1AggregatedResults.OrderBy(i => i.ElapsedExecutionTime).Skip(skipCount).FirstOrDefault().ElapsedExecutionTime,
                            Scan         = test1AggregatedResults.OrderBy(i => i.Scan).Skip(skipCount).FirstOrDefault().Scan,
                            Physical     = test1AggregatedResults.OrderBy(i => i.Physical).Skip(skipCount).FirstOrDefault().Physical,
                            Logical      = test1AggregatedResults.OrderBy(i => i.Logical).Skip(skipCount).FirstOrDefault().Logical,
                            LobLogical   = test1AggregatedResults.OrderBy(i => i.LobLogical).Skip(skipCount).FirstOrDefault().LobLogical,
                            LobPhysical  = test1AggregatedResults.OrderBy(i => i.LobPhysical).Skip(skipCount).FirstOrDefault().LobPhysical,
                            LobReadAhead = test1AggregatedResults.OrderBy(i => i.LobReadAhead).Skip(skipCount).FirstOrDefault().LobReadAhead,
                            PercentRead  = test1AggregatedResults.OrderBy(i => i.PercentRead).Skip(skipCount).FirstOrDefault().PercentRead,
                            ReadAhead    = test1AggregatedResults.OrderBy(i => i.ReadAhead).Skip(skipCount).FirstOrDefault().ReadAhead
                        });
                    }

                    return(new PerformanceResult
                    {
                        Totals = test1Totals,
                        Averages = test1Averages,
                        Percentiles = test1Percentiles
                    });
                });
            }

            // let's get some output goinnnnnnn
            IResultRenderer renderer = new ConsoleResultRenderer();

            renderer.Render(command, dataComparisonResult, performanceResults.ToList());

            Console.ReadLine();
        }