using Xunit;
using Xunit.Abstractions;
using System.Threading;
-using Microsoft.Diagnostics.Tools.RuntimeClient;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using EventPipe.UnitTests.Common;
+using Microsoft.Diagnostics.NETCore.Client;
using Microsoft.Diagnostics.Tracing;
namespace EventPipe.UnitTests.ContentionValidation
}
}
}
- public class ProviderTests
+ public class ContentionEventsTests
{
private readonly ITestOutputHelper output;
- public ProviderTests(ITestOutputHelper outputHelper)
+ public ContentionEventsTests(ITestOutputHelper outputHelper)
{
output = outputHelper;
}
{ "Microsoft-Windows-DotNETRuntimeRundown", -1 }
};
- var providers = new List<Provider>()
+ var providers = new List<EventPipeProvider>()
{
//ContentionKeyword (0x4000): 0b100_0000_0000_0000
- new Provider("Microsoft-Windows-DotNETRuntime", 0b100_0000_0000_0000, EventLevel.Informational)
+ new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational, 0b100_0000_0000_0000)
};
Action _eventGeneratingAction = () =>
return ContentionStartEvents > 0 && ContentionStopEvents > 0 ? 100 : -1;
};
};
- var config = new SessionConfiguration(circularBufferSizeMB: (uint)Math.Pow(2, 10), format: EventPipeSerializationFormat.NetTrace, providers: providers);
-
- var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, config, _DoesTraceContainEvents);
+ var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, _DoesTraceContainEvents);
Assert.Equal(100, ret);
}, output);
}
<PackageReference Include="Microsoft.DotNet.RemoteExecutor" Version="$(MicrosoftDotNetRemoteExecutorVersion)" />
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="$(MicrosoftDiagnosticsTracingTraceEventVersion)" />
<PackageReference Include="xunit.abstractions" Version="$(XUnitAbstractionsVersion)" />
- <ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Microsoft.Diagnostics.Tools.RuntimeClient\Microsoft.Diagnostics.Tools.RuntimeClient.csproj" />
+ <ProjectReference Include="$(MSBuildThisFileDirectory)..\..\Microsoft.Diagnostics.NETCore.Client\Microsoft.Diagnostics.NETCore.Client.csproj" />
</ItemGroup>
</Project>
using System;
using Xunit;
using Xunit.Abstractions;
-using Microsoft.Diagnostics.Tools.RuntimeClient;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using EventPipe.UnitTests.Common;
+using Microsoft.Diagnostics.NETCore.Client;
using Microsoft.Diagnostics.Tracing;
-using System.Threading;
namespace EventPipe.UnitTests.GCEventsValidation
{
b = "";
}
}
- public class ProviderTests
+ public class GCEventsTests
{
private readonly ITestOutputHelper output;
- public ProviderTests(ITestOutputHelper outputHelper)
+ public GCEventsTests(ITestOutputHelper outputHelper)
{
output = outputHelper;
}
{ "Microsoft-DotNETCore-SampleProfiler", -1 }
};
- var providers = new List<Provider>()
+ var GCProviders = new List<EventPipeProvider>()
{
- new Provider("Microsoft-DotNETCore-SampleProfiler"),
+ new EventPipeProvider("Microsoft-DotNETCore-SampleProfiler", EventLevel.Informational),
//GCKeyword (0x1): 0b1
- new Provider("Microsoft-Windows-DotNETRuntime", 0b1, EventLevel.Informational)
+ new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Verbose, 0x1)
};
Action _eventGeneratingAction = () =>
Logger.logger.Log("GCStartEvents: " + GCStartEvents);
Logger.logger.Log("GCEndEvents: " + GCEndEvents);
- bool GCStartStopResult = GCStartEvents >= 50 && GCEndEvents >= 50 && Math.Abs(GCStartEvents - GCEndEvents) <=2;
+ bool GCStartStopResult = GCStartEvents >= 50 && GCEndEvents >= 50 && Math.Abs(GCStartEvents - GCEndEvents) <= 2;
Logger.logger.Log("GCStartStopResult check: " + GCStartStopResult);
Logger.logger.Log("GCRestartEEStartEvents: " + GCRestartEEStartEvents);
};
};
- var config = new SessionConfiguration(circularBufferSizeMB: (uint)Math.Pow(2, 10), format: EventPipeSerializationFormat.NetTrace, providers: providers);
-
- var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, config, _DoesTraceContainEvents);
+ var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, GCProviders, 1024, _DoesTraceContainEvents);
Assert.Equal(100, ret);
}, output);
}
{ "Microsoft-Windows-DotNETRuntimeRundown", -1 },
{ "Microsoft-DotNETCore-SampleProfiler", -1 }
};
-
- var providers = new List<Provider>()
+
+ var GCProviders = new List<EventPipeProvider>()
{
- new Provider("Microsoft-DotNETCore-SampleProfiler"),
+ new EventPipeProvider("Microsoft-DotNETCore-SampleProfiler", EventLevel.Informational),
//GCKeyword (0x1): 0b1
- new Provider("Microsoft-Windows-DotNETRuntime", 0b1, EventLevel.Informational)
+ new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Verbose, 0x1)
};
Action _eventGeneratingAction = () =>
return GCFinalizersEndEvents >= 50 && GCFinalizersStartEvents >= 50 ? 100 : -1;
};
};
-
- var config = new SessionConfiguration(circularBufferSizeMB: (uint)Math.Pow(2, 10), format: EventPipeSerializationFormat.NetTrace, providers: providers);
-
- var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, config, _DoesTraceContainEvents);
+ var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, GCProviders, 1024, _DoesTraceContainEvents);
Assert.Equal(100, ret);
}, output);
}
{ "Microsoft-Windows-DotNETRuntimeRundown", -1 },
{ "Microsoft-DotNETCore-SampleProfiler", -1 }
};
-
- var providers = new List<Provider>()
+
+ var GCProviders = new List<EventPipeProvider>()
{
- new Provider("Microsoft-DotNETCore-SampleProfiler"),
+ new EventPipeProvider("Microsoft-DotNETCore-SampleProfiler", EventLevel.Informational),
//GCKeyword (0x1): 0b1
- new Provider("Microsoft-Windows-DotNETRuntime", 0b1, EventLevel.Verbose)
+ new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Verbose, 0x1)
};
Action _eventGeneratingAction = () =>
};
};
- var config = new SessionConfiguration(circularBufferSizeMB: (uint)Math.Pow(2, 10), format: EventPipeSerializationFormat.NetTrace, providers: providers);
-
- var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, config, _DoesTraceContainEvents);
+ var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, GCProviders, 1024, _DoesTraceContainEvents);
Assert.Equal(100, ret);
}, output);
}
using Xunit;
using System.IO;
using System.Runtime.Loader;
-using System.Threading;
using System.Reflection;
using Xunit.Abstractions;
-using Microsoft.Diagnostics.Tools.RuntimeClient;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using EventPipe.UnitTests.Common;
+using Microsoft.Diagnostics.NETCore.Client;
using Microsoft.Diagnostics.Tracing;
namespace EventPipe.UnitTests.LoaderEventsValidation
{
}
}
- public class ProviderTests
+ public class LoaderEventsTests
{
private readonly ITestOutputHelper output;
- public ProviderTests(ITestOutputHelper outputHelper)
+ public LoaderEventsTests(ITestOutputHelper outputHelper)
{
output = outputHelper;
}
{ "Microsoft-Windows-DotNETRuntimeRundown", -1 }
};
- var providers = new List<Provider>()
+ var providers = new List<EventPipeProvider>()
{
//LoaderKeyword (0x8): 0b1000
- new Provider("Microsoft-Windows-DotNETRuntime", 0b1000, EventLevel.Informational)
+ new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational, 0b1000)
};
string assemblyPath=null;
return LoaderAssemblyResult && LoaderModuleResult ? 100 : -1;
};
};
-
- var config = new SessionConfiguration(circularBufferSizeMB: (uint)Math.Pow(2, 10), format: EventPipeSerializationFormat.NetTrace, providers: providers);
-
- var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, config, _DoesTraceContainEvents);
+ var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, _DoesTraceContainEvents);
Assert.Equal(100, ret);
}, output);
}
using Xunit;
using System.ComponentModel;
using Xunit.Abstractions;
-using Microsoft.Diagnostics.Tools.RuntimeClient;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using EventPipe.UnitTests.Common;
+using Microsoft.Diagnostics.NETCore.Client;
using Microsoft.Diagnostics.Tracing;
namespace EventPipe.UnitTests.MethodEventsValidation
GC.SuppressFinalize(this);
}
}
- public class ProviderTests
+ public class MethodEventsTests
{
private readonly ITestOutputHelper output;
- public ProviderTests(ITestOutputHelper outputHelper)
+ public MethodEventsTests(ITestOutputHelper outputHelper)
{
output = outputHelper;
}
{ "Microsoft-DotNETCore-SampleProfiler", -1 }
};
- var providers = new List<Provider>()
+ var providers = new List<EventPipeProvider>()
{
- new Provider("Microsoft-DotNETCore-SampleProfiler"),
+ new EventPipeProvider("Microsoft-DotNETCore-SampleProfiler", EventLevel.Informational),
//MethodVerboseKeyword (0x10): 0b10000
- new Provider("Microsoft-Windows-DotNETRuntime", 0b10000, EventLevel.Verbose)
+ new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Verbose, 0b10000)
};
Action _eventGeneratingAction = () =>
};
};
- var config = new SessionConfiguration(circularBufferSizeMB: (uint)Math.Pow(2, 10), format: EventPipeSerializationFormat.NetTrace, providers: providers);
-
- var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, config, _DoesTraceContainEvents);
+ var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, _DoesTraceContainEvents);
Assert.Equal(100, ret);
}, output);
}
using System.Threading;
using System.Threading.Tasks;
using Xunit.Abstractions;
-using Microsoft.Diagnostics.Tools.RuntimeClient;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using EventPipe.UnitTests.Common;
+using Microsoft.Diagnostics.NETCore.Client;
using Microsoft.Diagnostics.Tracing;
namespace EventPipe.UnitTests.ThreadPoolValidation
{
- public class ProviderTests
+ public class ThreadPoolEventsTests
{
private readonly ITestOutputHelper output;
- public ProviderTests(ITestOutputHelper outputHelper)
+ public ThreadPoolEventsTests(ITestOutputHelper outputHelper)
{
output = outputHelper;
}
{ "Microsoft-Windows-DotNETRuntimeRundown", -1 }
};
- var providers = new List<Provider>()
+ var providers = new List<EventPipeProvider>()
{
//ThreadingKeyword (0x10000): 0b10000_0000_0000_0000
- new Provider("Microsoft-Windows-DotNETRuntime", 0b10000_0000_0000_0000, EventLevel.Informational)
+ new EventPipeProvider("Microsoft-Windows-DotNETRuntime", EventLevel.Informational, 0b10000_0000_0000_0000)
};
Action _eventGeneratingAction = () =>
return ThreadStartStopResult && ThreadAdjustmentResult ? 100 : -1;
};
};
-
- var config = new SessionConfiguration(circularBufferSizeMB: (uint)Math.Pow(2, 10), format: EventPipeSerializationFormat.NetTrace, providers: providers);
-
- var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, config, _DoesTraceContainEvents);
+ var ret = IpcTraceTest.RunAndValidateEventCounts(_expectedEventCounts, _eventGeneratingAction, providers, 1024, _DoesTraceContainEvents);
Assert.Equal(100, ret);
}, output);
}
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.Diagnostics.Tracing;
-using Microsoft.Diagnostics.Tools.RuntimeClient;
using System.Runtime.InteropServices;
using System.Linq;
using System.Text.RegularExpressions;
+using Microsoft.Diagnostics.NETCore.Client;
namespace EventPipe.UnitTests.Common
{
public void SentinelEvent() { WriteEvent(1, "SentinelEvent"); }
}
- public static class SessionConfigurationExtensions
- {
- public static SessionConfiguration InjectSentinel(this SessionConfiguration sessionConfiguration)
- {
- var newProviderList = new List<Provider>(sessionConfiguration.Providers);
- newProviderList.Add(new Provider("SentinelEventSource"));
- return new SessionConfiguration(sessionConfiguration.CircularBufferSizeInMB, sessionConfiguration.Format, newProviderList.AsReadOnly());
- }
- }
-
public class IpcTraceTest
{
// This Action is executed while the trace is being collected.
private Dictionary<string, ExpectedEventCount> _expectedEventCounts;
private Dictionary<string, int> _actualEventCounts = new Dictionary<string, int>();
private int _droppedEvents = 0;
- private SessionConfiguration _sessionConfiguration;
// A function to be called with the EventPipeEventSource _before_
// the call to `source.Process()`. The function should return another
// Example in situ: providervalidation.cs
private Func<EventPipeEventSource, Func<int>> _optionalTraceValidator;
+ /// <summary>
+ /// This is list of the EventPipe providers to turn on for the test execution
+ /// </summary>
+ private List<EventPipeProvider> _testProviders;
+
+ /// <summary>
+ /// This represents the current EventPipeSession
+ /// </summary>
+ private EventPipeSession _eventPipeSession;
+
+ /// <summary>
+ /// This is the list of EventPipe providers for the sentinel EventSource that indicates that the process is ready
+ /// </summary>
+ private List<EventPipeProvider> _sentinelProviders = new List<EventPipeProvider>()
+ {
+ new EventPipeProvider("SentinelEventSource", EventLevel.Verbose, -1)
+ };
+
IpcTraceTest(
Dictionary<string, ExpectedEventCount> expectedEventCounts,
Action eventGeneratingAction,
- SessionConfiguration sessionConfiguration = null,
+ List<EventPipeProvider> providers,
+ int circularBufferMB,
Func<EventPipeEventSource, Func<int>> optionalTraceValidator = null)
{
_eventGeneratingAction = eventGeneratingAction;
_expectedEventCounts = expectedEventCounts;
- _sessionConfiguration = sessionConfiguration?.InjectSentinel() ?? new SessionConfiguration(
- circularBufferSizeMB: 1000,
- format: EventPipeSerializationFormat.NetTrace,
- providers: new List<Provider> {
- new Provider("Microsoft-Windows-DotNETRuntime"),
- new Provider("SentinelEventSource")
- });
+ _testProviders = providers;
_optionalTraceValidator = optionalTraceValidator;
}
Logger.logger.Log(message);
Logger.logger.Log("Configuration:");
Logger.logger.Log("{");
- Logger.logger.Log($"\tbufferSize: {_sessionConfiguration.CircularBufferSizeInMB},");
Logger.logger.Log("\tproviders: [");
- foreach (var provider in _sessionConfiguration.Providers)
- {
- Logger.logger.Log($"\t\t{provider.ToString()},");
- }
Logger.logger.Log("\t]");
Logger.logger.Log("}\n");
Logger.logger.Log("Expected:");
sentinelTask.Start();
int processId = Process.GetCurrentProcess().Id;
- object threadSync = new object(); // for locking eventpipeSessionId access
- ulong eventpipeSessionId = 0;
+ object threadSync = new object(); // for locking eventpipeSession access
Func<int> optionalTraceValidationCallback = null;
+ DiagnosticsClient client = new DiagnosticsClient(processId);
var readerTask = new Task(() =>
{
Logger.logger.Log("Connecting to EventPipe...");
- using var eventPipeStream = new StreamProxy(EventPipeClient.CollectTracing(processId, _sessionConfiguration, out var sessionId));
- if (sessionId == 0)
+ try
{
- Logger.logger.Log("Failed to connect to EventPipe!");
- throw new ApplicationException("Failed to connect to EventPipe");
+ _eventPipeSession = client.StartEventPipeSession(_testProviders.Concat(_sentinelProviders));
}
- Logger.logger.Log($"Connected to EventPipe with sessionID '0x{sessionId:x}'");
-
- lock (threadSync)
+ catch(DiagnosticsClientException ex)
{
- eventpipeSessionId = sessionId;
+ Logger.logger.Log("Failed to connect to EventPipe!");
+ Logger.logger.Log(ex.ToString());
+ throw new ApplicationException("Failed to connect to EventPipe");
}
+ using var eventPipeStream = new StreamProxy(_eventPipeSession.EventStream);
Logger.logger.Log("Creating EventPipeEventSource...");
using EventPipeEventSource source = new EventPipeEventSource(eventPipeStream);
Logger.logger.Log("EventPipeEventSource created");
var stopTask = Task.Run(() =>
{
Logger.logger.Log("Sending StopTracing command...");
- lock (threadSync) // eventpipeSessionId
+ lock (threadSync) // eventpipeSession
{
- EventPipeClient.StopTracing(processId, eventpipeSessionId);
+ _eventPipeSession.Stop();
}
Logger.logger.Log("Finished StopTracing command");
}, ct);
public static int RunAndValidateEventCounts(
Dictionary<string, ExpectedEventCount> expectedEventCounts,
Action eventGeneratingAction,
- SessionConfiguration sessionConfiguration = null,
+ List<EventPipeProvider> providers,
+ int circularBufferMB=1024,
Func<EventPipeEventSource, Func<int>> optionalTraceValidator = null)
{
Logger.logger.Log("==TEST STARTING==");
- var test = new IpcTraceTest(expectedEventCounts, eventGeneratingAction, sessionConfiguration, optionalTraceValidator);
+ var test = new IpcTraceTest(expectedEventCounts, eventGeneratingAction, providers, circularBufferMB, optionalTraceValidator);
var ret = test.Validate();
if (ret == 100)
Logger.logger.Log("==TEST FINISHED: PASSED!==");
using System;
using Xunit;
using Xunit.Abstractions;
-using Microsoft.Diagnostics.Tools.RuntimeClient;
using System.Collections.Generic;
using System.Diagnostics.Tracing;
using EventPipe.UnitTests.Common;
+using Microsoft.Diagnostics.NETCore.Client;
// Use this test as an example of how to write tests for EventPipe in
// the dotnet/diagnostics repo
{ "Microsoft-DotNETCore-SampleProfiler", -1 }
};
- var providers = new List<Provider>()
+ var providers = new List<EventPipeProvider>()
{
- new Provider("MyEventSource"),
- new Provider("Microsoft-DotNETCore-SampleProfiler")
+ new EventPipeProvider("MyEventSource", EventLevel.Verbose, -1),
+ new EventPipeProvider("Microsoft-DotNETCore-SampleProfiler", EventLevel.Informational)
};
Action eventGeneratingAction = () =>
MyEventSource.Log.MyEvent();
}
};
-
- var config = new SessionConfiguration(circularBufferSizeMB: (uint)Math.Pow(2, 10), format: EventPipeSerializationFormat.NetTrace, providers: providers);
-
- var ret = IpcTraceTest.RunAndValidateEventCounts(expectedEventCounts, eventGeneratingAction, config);
+ var ret = IpcTraceTest.RunAndValidateEventCounts(expectedEventCounts, eventGeneratingAction, providers, 1024, null);
Assert.Equal(100, ret);
}, output);
}