public static DataCompareResults CompareTestResults(this List <IEnumerable <DATCommandResult>[]> testResults) { // do some stuff var returnResult = new DataCompareResults() { DataSets = new List <DataSetCompareResult>() }; int testIteration = 0; foreach (var testResult in testResults) { returnResult = testResult.CompareTestResults(returnResult, testIteration, testResults.Count); testIteration++; } return(returnResult); }
public static DataCompareResults CompareTestResults(this IEnumerable <DATCommandResult>[] testResults, DataCompareResults existingResults, int testIteration, int testCount) { int dataSetCounter = 0; foreach (var dataSet in testResults.FirstOrDefault().FirstOrDefault().ResultSets) { int dataRowCounter = 0; if (existingResults.DataSets.Count <= dataSetCounter) { existingResults.DataSets.Add(new DataSetCompareResult() { DataRows = new List <DataRowCompareResult>() }); } foreach (var dataRow in dataSet) { DataRowCompareResult dataRowResult = null; if (existingResults.DataSets[dataSetCounter].DataRows.Count <= dataRowCounter) { existingResults.DataSets[dataSetCounter].DataRows.Add(new DataRowCompareResult() { DataPoints = new List <DataPointCompareResult>() }); } dataRowResult = existingResults.DataSets[dataSetCounter].DataRows[dataRowCounter]; // now the fields/columns foreach (var columnKvp in (IDictionary <string, object>)dataRow) { var existingColumn = dataRowResult.DataPoints.FirstOrDefault(i => i.Name == columnKvp.Key); if (existingColumn == null) { dataRowResult.DataPoints.Add(new DataPointCompareResult { Name = columnKvp.Key, TestValues = new object[testCount] }); existingColumn = dataRowResult.DataPoints.FirstOrDefault(i => i.Name == columnKvp.Key); } // add the value of this dude existingColumn.TestValues[testIteration] = columnKvp.Value; existingColumn.TestValueCount++; existingColumn.ValueEquality = existingColumn.TestValueCount == testCount && existingColumn.TestValues.All(i => string.Equals(existingColumn.TestValues.First().ToString(), i.ToString(), StringComparison.InvariantCultureIgnoreCase)); } dataRowCounter++; } dataSetCounter++; } return(existingResults); }
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(); }
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(); }