Пример #1
0
        private void ProcessResults(string assemblyFileName, string sessionName, string outputDirectory, Action <string> collectOutputFilesCallback)
        {
            var reader = new CSVMetricReader(Configuration.FileLogPath);
            var fileNameWithoutExtension = $"{sessionName}-{Path.GetFileNameWithoutExtension(assemblyFileName)}";
            var statisticsFileName       = $"{fileNameWithoutExtension}-Statistics";
            var mdFileName = Path.Combine(outputDirectory, $"{statisticsFileName}.md");

            var assemblyModel = AssemblyModel.Create(assemblyFileName, reader);
            var xmlFileName   = Path.Combine(outputDirectory, $"{fileNameWithoutExtension}.xml");

            new AssemblyModelCollection {
                assemblyModel
            }.Serialize(xmlFileName);
            WriteInfoLine($"Performance results saved to \"{xmlFileName}\"");
            collectOutputFilesCallback(xmlFileName);

            var dt      = assemblyModel.GetStatistics();
            var mdTable = MarkdownHelper.GenerateMarkdownTable(dt);

            MarkdownHelper.Write(mdFileName, mdTable);
            WriteInfoLine($"Markdown file saved to \"{mdFileName}\"");
            collectOutputFilesCallback(mdFileName);
            Console.WriteLine(mdTable);

            var csvFileName = Path.Combine(outputDirectory, $"{statisticsFileName}.csv");

            dt.WriteToCSV(csvFileName);
            WriteInfoLine($"Statistics written to \"{csvFileName}\"");
            collectOutputFilesCallback(csvFileName);

            BenchmarkEventSource.Log.Clear();
        }
Пример #2
0
        private void ProcessResults(XUnitPerformanceSessionData xUnitSessionData, XUnitPerformanceMetricData xUnitPerformanceMetricData)
        {
            if (!File.Exists(Configuration.FileLogPath))
            {
                WriteWarningLine($"Results file '{Configuration.FileLogPath}' does not exist. Skipping processing of results.");
                return;
            }

            var reader = new CSVMetricReader(Configuration.FileLogPath);
            var fileNameWithoutExtension = $"{xUnitSessionData.RunId}-{Path.GetFileNameWithoutExtension(xUnitSessionData.AssemblyFileName)}";

            var assemblyModel = AssemblyModel.Create(xUnitSessionData.AssemblyFileName, reader, xUnitPerformanceMetricData);
            var xmlFileName   = Path.Combine(xUnitSessionData.OutputDirectory, $"{fileNameWithoutExtension}.xml");

            new AssemblyModelCollection {
                assemblyModel
            }.Serialize(xmlFileName);
            xUnitSessionData.CollectOutputFilesCallback(xmlFileName);

            var dt         = assemblyModel.GetStatistics();
            var mdTable    = MarkdownHelper.GenerateMarkdownTable(dt);
            var mdFileName = Path.Combine(xUnitSessionData.OutputDirectory, $"{fileNameWithoutExtension}.md");

            MarkdownHelper.Write(mdFileName, mdTable);
            xUnitSessionData.CollectOutputFilesCallback(mdFileName);
            Console.WriteLine(MarkdownHelper.ToTrimmedTable(mdTable));

            var csvFileName = Path.Combine(xUnitSessionData.OutputDirectory, $"{fileNameWithoutExtension}.csv");

            dt.WriteToCSV(csvFileName);
            xUnitSessionData.CollectOutputFilesCallback(csvFileName);

            BenchmarkEventSource.Log.Clear();
        }
Пример #3
0
        internal static AssemblyModel Create(
            string assemblyFileName,
            CSVMetricReader reader,
            XUnitPerformanceMetricData xUnitPerformanceMetricData)
        {
            var assemblyModel = new AssemblyModel
            {
                Name       = Path.GetFileName(assemblyFileName),
                Collection = new List <TestModel>()
            };

            foreach (var(perfTestMsg, metric, values) in GetCollectedData(assemblyFileName, reader, xUnitPerformanceMetricData))
            {
                var testModel = assemblyModel.Collection.FirstOrDefault(test => test.Name == perfTestMsg.TestCase.DisplayName);
                if (testModel == null)
                {
                    testModel = new TestModel
                    {
                        Name        = perfTestMsg.TestCase.DisplayName,
                        Method      = perfTestMsg.TestCase.TestMethod.Method.Name,
                        ClassName   = perfTestMsg.TestCase.TestMethod.TestClass.Class.Name,
                        Performance = new PerformanceModel
                        {
                            Metrics         = new List <MetricModel>(),
                            IterationModels = new List <IterationModel>()
                        },
                    };
                }

                var testMetric = testModel.Performance.Metrics.FirstOrDefault(m => m.DisplayName == metric);
                if (testMetric == null)
                {
                    testModel.Performance.Metrics.Add(new MetricModel
                    {
                        DisplayName = metric,
                        Name        = metric,
                        Unit        = metric == "Duration" ? PerformanceMetricUnits.Milliseconds : "unknown", // We are guessing here.
                    });
                }

                foreach (var value in values)
                {
                    var iterationModel = new IterationModel {
                        Iteration = new Dictionary <string, double>()
                    };
                    iterationModel.Iteration.Add(metric, value);
                    if (iterationModel.Iteration.Count > 0)
                    {
                        testModel.Performance.IterationModels.Add(iterationModel);
                    }
                }

                assemblyModel.Collection.Add(testModel);
            }

            return(assemblyModel);
        }
Пример #4
0
        private static IEnumerable <(PerformanceTestMessage performanceTestMessage, string metric, IEnumerable <double> values)> GetCollectedData(
            string assemblyFileName,
            CSVMetricReader reader,
            XUnitPerformanceMetricData xUnitPerformanceMetricData)
        {
            var testsFoundInAssembly = xUnitPerformanceMetricData.PerformanceTestMessages;

            foreach (var testFoundInAssembly in testsFoundInAssembly)
            {
                foreach (var(testCaseName, metric, values) in GetMeasurements(reader))
                {
                    if (values == null)
                    {
                        continue;
                    }

                    if (testCaseName == testFoundInAssembly.TestCase.DisplayName)
                    {
                        yield return(testFoundInAssembly, metric, values);
                    }
                }
            }
        }
Пример #5
0
        private static IEnumerable <(string testCaseName, string metric, IEnumerable <double> values)> GetMeasurements(CSVMetricReader reader)
        {
            foreach (var testCaseName in reader.TestCases)
            {
                var iterations   = reader.GetValues(testCaseName);
                var measurements = new Dictionary <string, List <double> >();

                foreach (var dict in iterations)
                {
                    foreach (var pair in dict)
                    {
                        if (!measurements.ContainsKey(pair.Key))
                        {
                            measurements[pair.Key] = new List <double>();
                        }
                        measurements[pair.Key].Add(pair.Value);
                    }
                }

                foreach (var measurement in measurements)
                {
                    yield return(testCaseName, measurement.Key, measurement.Value);
                }
            }
        }