Example #1
0
        protected override void LogResultInternal(PerformanceTestContext context)
        {
            IReadOnlyCollection <Duration> durations = GetDurations();
            double average = Math.Round(durations.Select(d => d.End - d.Start).Average(), 3);

            context.LogMessage($"{Name}: {durations.Count} events with average duration of {average} ms");
        }
Example #2
0
 protected override void LogResultInternal(PerformanceTestContext context)
 {
     if (_startTime == null)
     {
         context.LogError($"Did not find expected start event {StartEvent} from provider {StartEventProvider}.");
     }
     else if (_endTime == null)
     {
         context.LogError($"Did not find expected end event {EndEvent} from provider {EndEventProvider}.");
     }
     else
     {
         double duration = Math.Round(_endTime.Value - _startTime.Value, 3);
         context.LogMessage($"{Name}: {duration}");
     }
 }
        public override TestResult[] Execute(ITestMethod testMethod)
        {
            TestResult[] errorResults = ValidateElevated(testMethod);
            if (errorResults != null)
            {
                return(errorResults);
            }

            Exception signatureException = GetMethodSignatureException(testMethod);

            if (signatureException != null)
            {
                return(testMethod.CreateExceptionResult(signatureException));
            }

            var    runParameters = TestRunParameters.Read();
            string logFolder     = runParameters.LogFolder;
            bool   shouldLog     = !string.IsNullOrEmpty(logFolder);

            if (shouldLog)
            {
                try
                {
                    logFolder = CreateLogFolder(logFolder, testMethod.TestMethodName);
                }
                catch (Exception e)
                {
                    return(testMethod.CreateExceptionResult(e));
                }
            }

            int iterations = runParameters.Iterations;
            var results    = new TestResult[iterations];

            for (int iteration = 1; iteration <= iterations; iteration++)
            {
                string sessionName = $"{testMethod.TestMethodName}-{iteration}";

                using (var session = new TraceEventSession(sessionName))
                {
                    EnableKernelProviders(session, shouldLog);

                    TraceEventDispatcher source;
                    ZippedETLWriter      writer = null;
                    if (shouldLog)
                    {
                        string etlPath = Path.Combine(logFolder, $"Iteration{iteration}.etl");
                        source = new ETWReloggerTraceEventSource(sessionName, TraceEventSourceType.Session, etlPath);
                        writer = new ZippedETLWriter(etlPath);
                    }
                    else
                    {
                        source = session.Source;
                    }

                    EnableProviders(session);
                    PerformanceTestContext context = CreateContext(source);

                    Task <TestResult> testTask = Task.Run(() => testMethod.Invoke(new object[] { context }));

                    // This is a blocking call that in the case of ETWReloggerTraceEventSource, must be run on the same
                    // thread as ETWReloggerTraceEventSource was created on. It will become unblocked when the
                    // PerformanceTestContext calls StopProcessing on the source.
                    source.Process();

                    TestResult result      = testTask.Result;
                    string     displayName = testMethod.TestMethodName;
                    if (iterations > 1)
                    {
                        displayName += $" [{iteration}/{iterations}]";
                    }

                    result.DisplayName = displayName;

                    session.Flush();
                    OnIterationEnded(context);

                    context.LogScenarios();
                    context.LogMemoryDelta();
                    context.LogMessage($"{displayName} completed. {session.EventsLost} events lost.");
                    context.WriteLogsToResult(result, writer);

                    results[iteration - 1] = result;
                }
            }

            return(results);
        }
 protected abstract void OnIterationEnded(PerformanceTestContext context);