Пример #1
0
        private static AssemblyModel GetAssemblyModel(
            string assemblyFileName,
            string etlFileName,
            string sessionName,
            IEnumerable <PerformanceTestMessage> performanceTestMessages)
        {
            using (var reader = GetEtwReader(etlFileName, sessionName, performanceTestMessages))
            {
                var assemblyModel = new AssemblyModel {
                    Name       = Path.GetFileName(assemblyFileName),
                    Collection = new List <TestModel>()
                };

                foreach (var test in performanceTestMessages)
                {
                    var metrics = new List <MetricModel>();
                    foreach (var metric in test.Metrics)
                    {
                        metrics.Add(new MetricModel {
                            DisplayName = metric.DisplayName,
                            Name        = metric.Id,
                            Unit        = metric.Unit,
                        });
                    }

                    var testModel = new TestModel {
                        Name        = test.TestCase.DisplayName,
                        Method      = test.TestCase.TestMethod.Method.Name,
                        ClassName   = test.TestCase.TestMethod.TestClass.Class.Name,
                        Performance = new PerformanceModel {
                            Metrics = metrics, IterationModels = new List <IterationModel>()
                        },
                    };

                    var values = reader.GetValues(testModel.Name);
                    if (values == null)
                    {
                        continue; // If the test was not run, then it will not be found on the trace (e.g. user only ran a subset of all tests).
                    }
                    foreach (var dict in values)
                    {
                        var iterationModel = new IterationModel {
                            Iteration = new Dictionary <string, double>()
                        };
                        foreach (var kvp in dict)
                        {
                            iterationModel.Iteration.Add(kvp.Key, kvp.Value);
                        }
                        if (iterationModel.Iteration.Count > 0)
                        {
                            testModel.Performance.IterationModels.Add(iterationModel);
                        }
                    }

                    assemblyModel.Collection.Add(testModel);
                }

                return(assemblyModel);
            }
        }
Пример #2
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);
        }