Ejemplo n.º 1
0
        /// <summary>
        /// Run the xUnit tests tagged with the [<see cref="BenchmarkAttribute"/>] attribute.
        /// </summary>
        /// <param name="assemblyFileName">Path to the assembly that contains the xUnit performance tests.</param>
        public void RunBenchmarks(string assemblyFileName)
        {
            if (string.IsNullOrEmpty(assemblyFileName))
            {
                throw new ArgumentNullException(nameof(assemblyFileName));
            }
            if (!File.Exists(assemblyFileName))
            {
                throw new FileNotFoundException(assemblyFileName);
            }

            void xUnitAction(string assemblyPath)
            {
                var errCode = XunitRunner.Run(assemblyPath, _typeNames);

                if (errCode != 0)
                {
                    throw new Exception($"{errCode} benchmark(s) failed to execute.");
                }
            }

            var xUnitPerformanceSessionData = new XUnitPerformanceSessionData
            {
                AssemblyFileName           = assemblyFileName,
                CollectOutputFilesCallback = LogFileSaved,
                OutputDirectory            = OutputDirectory,
                RunId = Configuration.RunId
            };

            var xUnitPerformanceMetricData = XunitBenchmark.GetMetadata(
                assemblyFileName,
                _metricCollectionFactory.GetMetrics(),
                _collectDefaultXUnitMetrics);

            if (IsWindowsPlatform && _requireEtw)
            {
                void winRunner()
                {
                    xUnitAction(assemblyFileName);
                }

                ETWProfiler.Record(
                    xUnitPerformanceSessionData,
                    xUnitPerformanceMetricData,
                    winRunner);
            }
            else
            {
                xUnitAction(assemblyFileName);
                ProcessResults(xUnitPerformanceSessionData, xUnitPerformanceMetricData);
            }
        }
Ejemplo n.º 2
0
        static XunitPerformanceHarness()
        {
            Action <string, string, string, Action, Action <string> > etwProfiler = (assemblyPath, runId, outputDirectory, runner, collectOutputFilesCallback) =>
            {
                ETWProfiler.Record(assemblyPath, runId, outputDirectory, runner, collectOutputFilesCallback);
            };
            Action <string, string, string, Action, Action <string> > genericProfiler = (assemblyPath, runId, outputDirectory, runner, collectOutputFilesCallback) =>
            {
                GenericProfiler.Record(assemblyPath, runId, outputDirectory, runner, collectOutputFilesCallback);
            };

            s_profiler = IsWindowsPlatform ? etwProfiler : genericProfiler;
        }
        public void RunBenchmarks(string assemblyFileName)
        {
            Validate(assemblyFileName);

            Action <string> xUnitAction = (assemblyPath) => { XunitRunner.Run(assemblyPath, _typeNames); };
            var             xUnitPerformanceSessionData = new XUnitPerformanceSessionData {
                AssemblyFileName           = assemblyFileName,
                CollectOutputFilesCallback = (fileName) => {
                    // FIXME: This will need safe guards when the client calls RunBenchmarks in different threads.
                    _outputFiles.Add(fileName);
                    WriteInfoLine($"File saved to: \"{fileName}\"");
                },
                OutputDirectory = OutputDirectory,
                RunId           = Configuration.RunId
            };

            var metrics = _metricCollectionFactory.GetMetrics(assemblyFileName);
            var xUnitPerformanceMetricData = XunitBenchmark.GetMetadata(
                assemblyFileName,
                metrics,
                _collectDefaultXUnitMetrics);

            if (IsWindowsPlatform && _requireEtw)
            {
                Action winRunner = () => { xUnitAction(assemblyFileName); };
                ETWProfiler.Record(
                    xUnitPerformanceSessionData,
                    xUnitPerformanceMetricData,
                    winRunner);
            }
            else
            {
                xUnitAction.Invoke(assemblyFileName);
                ProcessResults(xUnitPerformanceSessionData, xUnitPerformanceMetricData);
            }
        }