public static (IEnumerable <ProviderInfo> providers, IEnumerable <PerformanceTestMessage> performanceTestMessages) GetMetadata(string assemblyFileName)
        {
            using (var controller = new XunitFrontController(
                       assemblyFileName: assemblyFileName,
                       shadowCopy: false,
                       appDomainSupport: AppDomainSupport.Denied,
                       diagnosticMessageSink: new ConsoleDiagnosticMessageSink()))
            {
                using (var testMessageVisitor = new PerformanceTestMessageVisitor())
                {
                    controller.Find(
                        includeSourceInformation: false,
                        messageSink: testMessageVisitor,
                        discoveryOptions: TestFrameworkOptions.ForDiscovery());

                    testMessageVisitor.Finished.WaitOne();

                    var providers =
                        from test in testMessageVisitor.Tests
                        from metric in test.Metrics.Cast <PerformanceMetric>()
                        from provider in metric.ProviderInfo
                        select provider;

                    providers = ProviderInfo.Merge(providers);
                    return(ProviderInfo.Merge(RequiredProviders.Concat(providers)), testMessageVisitor.Tests);
                }
            }
        }
Beispiel #2
0
        public static (IEnumerable <ProviderInfo> providers, IEnumerable <PerformanceTestMessage> performanceTestMessages) GetMetadata(string assemblyFileName)
        {
            using (var controller = new XunitFrontController(
                       assemblyFileName: assemblyFileName,
                       shadowCopy: false,
                       appDomainSupport: AppDomainSupport.Denied,
                       diagnosticMessageSink: new ConsoleDiagnosticMessageSink()))
            {
                using (var testMessageVisitor = new PerformanceTestMessageVisitor())
                {
                    controller.Find(
                        includeSourceInformation: false,
                        messageSink: testMessageVisitor,
                        discoveryOptions: TestFrameworkOptions.ForDiscovery());

                    testMessageVisitor.Finished.WaitOne();

                    var providers =
                        from test in testMessageVisitor.Tests
                        from metric in test.Metrics.Cast <PerformanceMetric>()
                        from provider in metric.ProviderInfo
                        select provider;

                    providers = ProviderInfo.Merge(providers);

                    // Create the list of default metrics
                    IEnumerable <PerformanceMetricInfo> defaultMetricInfos =
                        from pmcMetricInfo in PerformanceMetricInfos
                        where pmcMetricInfo.IsValidPmc
                        select pmcMetricInfo;

                    if (AllocatedBytesForCurrentThread.IsAvailable)
                    {
                        defaultMetricInfos = defaultMetricInfos.Concat(new[] { new GCAllocatedBytesForCurrentThreadMetric() });
                    }
                    else
                    {
                        WriteWarningLine(AllocatedBytesForCurrentThread.NoAvailabilityReason);
                        WriteWarningLine($"The '{GCAllocatedBytesForCurrentThreadMetric.GetAllocatedBytesForCurrentThreadDisplayName}' metric will not be collected.");
                    }

                    // Inject implicit pmc counters
                    foreach (var test in testMessageVisitor.Tests)
                    {
                        test.Metrics = test.Metrics.Concat(defaultMetricInfos);
                    }

                    return(ProviderInfo.Merge(RequiredProviders.Concat(providers)), testMessageVisitor.Tests);
                }
            }
        }
Beispiel #3
0
        public static XUnitPerformanceMetricData GetMetadata(
            string assemblyFileName,
            IEnumerable <PerformanceMetric> performanceMetricInfos,
            bool collectDefaultMetrics)
        {
            using (var controller = new XunitFrontController(
                       assemblyFileName: assemblyFileName,
                       shadowCopy: false,
                       appDomainSupport: AppDomainSupport.Denied,
                       diagnosticMessageSink: new ConsoleDiagnosticMessageSink()))
            {
                using (var testMessageVisitor = new PerformanceTestMessageVisitor())
                {
                    controller.Find(
                        includeSourceInformation: false,
                        messageSink: testMessageVisitor,
                        discoveryOptions: TestFrameworkOptions.ForDiscovery());
                    testMessageVisitor.Finished.WaitOne();

                    var testProviders =
                        from test in testMessageVisitor.Tests
                        from metric in test.Metrics.Cast <PerformanceMetric>()
                        from provider in metric.ProviderInfo
                        select provider;
                    testProviders = ProviderInfo.Merge(testProviders);

                    var userProviders = Enumerable.Empty <ProviderInfo>();
                    foreach (var performanceMetricInfo in performanceMetricInfos)
                    {
                        userProviders = ProviderInfo.Merge(userProviders.Concat(performanceMetricInfo.ProviderInfo));
                    }

                    var comparer = new PerformanceMetricInfoComparer();

                    // Inject performance metrics into the tests
                    foreach (var test in testMessageVisitor.Tests)
                    {
                        test.Metrics = collectDefaultMetrics ?
                                       test.Metrics.Union(performanceMetricInfos, comparer) :
                                       performanceMetricInfos;
                    }

                    return(new XUnitPerformanceMetricData {
                        Providers = ProviderInfo.Merge(RequiredProviders.Concat(testProviders).Concat(userProviders)),
                        PerformanceTestMessages = testMessageVisitor.Tests
                    });
                }
            }
        }