{
public static class Assert
{
- public static void Equal<T>(T left, T right) where T : IEquatable<T>
+ public static void Equal<T>(string name, T left, T right) where T : IEquatable<T>
{
if (left == null && right != null)
{
throw new Exception(
- string.Format("Values are not equal! Left=NULL Right='{0}'", right));
+ string.Format("Values for '{0}' are not equal! Left=NULL Right='{1}'", name, right));
}
else if (left != null && right == null)
{
throw new Exception(
- string.Format("Values are not equal! Left='{0}' Right=NULL", left));
+ string.Format("Values for '{0}' are not equal! Left='{1}' Right=NULL", name, left));
}
else if (!left.Equals(right))
{
throw new Exception(
- string.Format("Values are not equal! Left='{0}' Right='{1}'", left, right));
+ string.Format("Values for '{0}' are not equal! Left='{1}' Right='{2}'", name, left, right));
}
}
- public static void NotEqual<T>(T left, T right) where T : IEquatable<T>
+ public static void NotEqual<T>(string name, T left, T right) where T : IEquatable<T>
{
if (left == null && right == null)
{
throw new Exception(
- "Values are equal! Left=NULL Right=NULL");
+ string.Format("Values for '{0}' are equal! Left=NULL Right=NULL", name));
}
else if (left != null && left.Equals(right))
{
throw new Exception(
- string.Format("Values are equal! Left='{0}' Right='{1}'", left, right));
+ string.Format("Values for '{0}' are equal! Left='{1}' Right='{2}'", name, left, right));
}
}
}
int retCode = EventActivityIdControl(
ActivityControlCode.EVENT_ACTIVITY_CTRL_GET_ID,
ref activityId);
- Assert.Equal<int>(retCode, 0);
- Assert.Equal<Guid>(activityId, Guid.Empty);
+ Assert.Equal<int>(nameof(retCode), retCode, 0);
+ Assert.Equal<Guid>(nameof(activityId), activityId, Guid.Empty);
// Set the activity ID to a random GUID and then confirm that it was properly set.
activityId = Guid.NewGuid();
retCode = EventActivityIdControl(
ActivityControlCode.EVENT_ACTIVITY_CTRL_SET_ID,
ref activityId);
- Assert.Equal<int>(retCode, 0);
+ Assert.Equal<int>(nameof(retCode), retCode, 0);
Guid currActivityId = Guid.Empty;
retCode = EventActivityIdControl(
ActivityControlCode.EVENT_ACTIVITY_CTRL_GET_ID,
ref currActivityId);
- Assert.Equal<int>(retCode, 0);
- Assert.Equal<Guid>(currActivityId, activityId);
+ Assert.Equal<int>(nameof(retCode), retCode, 0);
+ Assert.Equal<Guid>(nameof(currActivityId), currActivityId, activityId);
// Set and get the activity ID in one call.
activityId = Guid.NewGuid();
retCode = EventActivityIdControl(
ActivityControlCode.EVENT_ACTIVITY_CTRL_GET_SET_ID,
ref activityId);
- Assert.Equal<int>(retCode, 0);
- Assert.Equal<Guid>(currActivityId, activityId);
+ Assert.Equal<int>(nameof(retCode), retCode, 0);
+ Assert.Equal<Guid>(nameof(currActivityId), currActivityId, activityId);
// Validate that the value we specified in the previous call is what comes back from a call to Get.
retCode = EventActivityIdControl(
ActivityControlCode.EVENT_ACTIVITY_CTRL_GET_ID,
ref activityId);
- Assert.Equal<int>(retCode, 0);
- Assert.Equal<Guid>(savedActivityId, activityId);
+ Assert.Equal<int>(nameof(retCode), retCode, 0);
+ Assert.Equal<Guid>(nameof(savedActivityId), savedActivityId, activityId);
// Create a new ID but don't change the current value.
Guid newActivityId = Guid.Empty;
retCode = EventActivityIdControl(
ActivityControlCode.EVENT_ACTIVITY_CTRL_CREATE_ID,
ref newActivityId);
- Assert.Equal<int>(retCode, 0);
- Assert.NotEqual<Guid>(newActivityId, Guid.Empty);
+ Assert.Equal<int>(nameof(retCode), retCode, 0);
+ Assert.NotEqual<Guid>(nameof(newActivityId), newActivityId, Guid.Empty);
retCode = EventActivityIdControl(
ActivityControlCode.EVENT_ACTIVITY_CTRL_GET_ID,
ref activityId);
- Assert.Equal<int>(retCode, 0);
- Assert.Equal<Guid>(savedActivityId, activityId);
+ Assert.Equal<int>(nameof(retCode), retCode, 0);
+ Assert.Equal<Guid>(nameof(savedActivityId), savedActivityId, activityId);
// Create a new ID and set it in one action.
retCode = EventActivityIdControl(
ActivityControlCode.EVENT_ACTIVITY_CTRL_CREATE_SET_ID,
ref activityId);
- Assert.Equal<int>(retCode, 0);
- Assert.Equal<Guid>(savedActivityId, activityId);
+ Assert.Equal<int>(nameof(retCode), retCode, 0);
+ Assert.Equal<Guid>(nameof(savedActivityId), savedActivityId, activityId);
savedActivityId = activityId;
retCode = EventActivityIdControl(
ActivityControlCode.EVENT_ACTIVITY_CTRL_GET_ID,
ref activityId);
- Assert.Equal<int>(retCode, 0);
- Assert.NotEqual<Guid>(savedActivityId, activityId);
- Assert.NotEqual<Guid>(activityId, Guid.Empty);
+ Assert.Equal<int>(nameof(retCode), retCode, 0);
+ Assert.NotEqual<Guid>(nameof(savedActivityId), savedActivityId, activityId);
+ Assert.NotEqual<Guid>(nameof(activityId), activityId, Guid.Empty);
retCode = EventActivityIdControl(
ActivityControlCode.EVENT_ACTIVITY_CTRL_GET_ID,
ref newActivityId);
- Assert.Equal<int>(retCode, 0);
- Assert.Equal<Guid>(activityId, newActivityId);
+ Assert.Equal<int>(nameof(retCode), retCode, 0);
+ Assert.Equal<Guid>(nameof(activityId), activityId, newActivityId);
// Set the activity ID back to zero.
activityId = Guid.Empty;
retCode = EventActivityIdControl(
ActivityControlCode.EVENT_ACTIVITY_CTRL_SET_ID,
ref activityId);
- Assert.Equal<int>(retCode, 0);
+ Assert.Equal<int>(nameof(retCode), retCode, 0);
retCode = EventActivityIdControl(
ActivityControlCode.EVENT_ACTIVITY_CTRL_GET_ID,
ref activityId);
- Assert.Equal<int>(retCode, 0);
- Assert.Equal<Guid>(activityId, Guid.Empty);
+ Assert.Equal<int>(nameof(retCode), retCode, 0);
+ Assert.Equal<Guid>(nameof(activityId), activityId, Guid.Empty);
// Try pass an invalid control code.
activityId = Guid.NewGuid();
retCode = EventActivityIdControl(
(ActivityControlCode)10,
ref activityId);
- Assert.Equal<int>(retCode, 1);
- Assert.Equal<Guid>(activityId, savedActivityId);
+ Assert.Equal<int>(nameof(retCode), retCode, 1);
+ Assert.Equal<Guid>(nameof(activityId), activityId, savedActivityId);
}
catch(Exception ex)
{
--- /dev/null
+using System;
+using System.IO;
+using Tracing.Tests.Common;
+using Microsoft.Diagnostics.Tracing;
+using Microsoft.Diagnostics.Tracing.Parsers;
+using Microsoft.Diagnostics.Tracing.Parsers.Clr;
+
+namespace Tracing.Tests
+{
+ public static class TraceValidationInducedGC
+ {
+ private static int InducedGCIterations = 10;
+
+ public static int Main(string[] args)
+ {
+ bool pass = true;
+ bool keepOutput = false;
+
+ // Use the first arg as an output filename if there is one.
+ string outputFilename = null;
+ if (args.Length >= 1)
+ {
+ outputFilename = args[0];
+ keepOutput = true;
+ }
+ else
+ {
+ outputFilename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".netperf";
+ }
+
+ try
+ {
+ Console.WriteLine("\tStart: Enable tracing.");
+ TraceControl.EnableDefault(outputFilename);
+ Console.WriteLine("\tEnd: Enable tracing.\n");
+
+ Console.WriteLine("\tStart: Generate some events.");
+ for(int i=0; i<InducedGCIterations; i++)
+ {
+ GC.Collect();
+ }
+ Console.WriteLine("\tEnd: Generate some events.\n");
+
+ Console.WriteLine("\tStart: Disable tracing.");
+ TraceControl.Disable();
+ Console.WriteLine("\tEnd: Disable tracing.\n");
+
+ Console.WriteLine("\tStart: Process the trace file.");
+ int matchingEventCount = 0;
+ int nonMatchingEventCount = 0;
+ using (var trace = TraceEventDispatcher.GetDispatcherFromFileName(outputFilename))
+ {
+ string gcReasonInduced = GCReason.Induced.ToString();
+ string providerName = "Microsoft-Windows-DotNETRuntime";
+ string gcTriggeredEventName = "GC/Triggered";
+
+ trace.Clr.GCTriggered += delegate(GCTriggeredTraceData data)
+ {
+ if(gcReasonInduced.Equals(data.Reason.ToString()) &&
+ providerName.Equals(data.ProviderName) &&
+ gcTriggeredEventName.Equals(data.EventName))
+ {
+ matchingEventCount++;
+ }
+ else
+ {
+ nonMatchingEventCount++;
+ }
+ };
+
+ trace.Process();
+ }
+ Console.WriteLine("\tEnd: Processing events from file.\n");
+
+ Assert.Equal(nameof(matchingEventCount), InducedGCIterations, matchingEventCount);
+ Assert.Equal(nameof(nonMatchingEventCount), nonMatchingEventCount, 0);
+ }
+ finally {
+ if (keepOutput)
+ {
+ Console.WriteLine("\n\tOutput file: {0}", outputFilename);
+ }
+ else
+ {
+ System.IO.File.Delete(outputFilename);
+ }
+ }
+
+ return 100;
+ }
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{8E3244CB-407F-4142-BAAB-E7A55901A5FA}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <CLRTestKind>BuildAndRun</CLRTestKind>
+ <DefineConstants>$(DefineConstants);STATIC</DefineConstants>
+ <CLRTestPriority>0</CLRTestPriority>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"></PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"></PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="InducedGC.cs" />
+ <ProjectReference Include="../../common/common.csproj" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+</Project>
\ No newline at end of file
--- /dev/null
+using System;
+using System.IO;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Runtime.CompilerServices;
+using Tracing.Tests.Common;
+using Microsoft.Diagnostics.Tracing;
+using Microsoft.Diagnostics.Tracing.Parsers;
+using Microsoft.Diagnostics.Tracing.Parsers.Clr;
+
+namespace Tracing.Tests
+{
+ public static class TraceValidationJittingStarted
+ {
+ // Delegate declaration matching the signature of the dynamic method.
+ private delegate void DynamicallyCompiledMethodInvoker();
+
+ public static int Main(string[] args)
+ {
+ bool pass = true;
+ bool keepOutput = false;
+
+ // Use the first arg as an output filename if there is one.
+ string outputFilename = null;
+ if (args.Length >= 1)
+ {
+ outputFilename = args[0];
+ keepOutput = true;
+ }
+ else
+ {
+ outputFilename = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".netperf";
+ }
+
+ try
+ {
+ Console.WriteLine("\tStart: Enable tracing.");
+ TraceControl.EnableDefault(outputFilename);
+ Console.WriteLine("\tEnd: Enable tracing.\n");
+
+ Console.WriteLine("\tStart: Generate some events.");
+ DynamicallyCompiledMethodInvoker invoker = BuildDynamicMethod();
+ invoker.Invoke();
+ Console.WriteLine("\tEnd: Generate some events.\n");
+
+ Console.WriteLine("\tStart: Disable tracing.");
+ TraceControl.Disable();
+ Console.WriteLine("\tEnd: Disable tracing.\n");
+
+ Console.WriteLine("\tStart: Process the trace file.");
+
+ int matchingEventCount = 0;
+ int nonMatchingEventCount = 0;
+
+ using (var trace = TraceEventDispatcher.GetDispatcherFromFileName(outputFilename))
+ {
+ string methodNamespace = "dynamicClass";
+ string methodName = "DynamicallyCompiledMethod";
+ string methodSignature = "void ()";
+ string providerName = "Microsoft-Windows-DotNETRuntime";
+ string gcTriggeredEventName = "Method/JittingStarted";
+
+ trace.Clr.MethodJittingStarted += delegate(MethodJittingStartedTraceData data)
+ {
+ if(methodNamespace.Equals(data.MethodNamespace) &&
+ methodName.Equals(data.MethodName) &&
+ methodSignature.Equals(data.MethodSignature) &&
+ providerName.Equals(data.ProviderName) &&
+ gcTriggeredEventName.Equals(data.EventName))
+ {
+ matchingEventCount++;
+ }
+ };
+
+ trace.Process();
+ }
+ Console.WriteLine("\tEnd: Processing events from file.\n");
+
+ // CompiledMethod
+ Assert.Equal(nameof(matchingEventCount), matchingEventCount, 1);
+ }
+ finally
+ {
+ if (keepOutput)
+ {
+ Console.WriteLine("\n\tOutput file: {0}", outputFilename);
+ }
+ else
+ {
+ System.IO.File.Delete(outputFilename);
+ }
+ }
+
+ return 100;
+ }
+
+ private static DynamicallyCompiledMethodInvoker BuildDynamicMethod()
+ {
+ Type[] methodArgs = { };
+
+ DynamicMethod dynamicMethod = new DynamicMethod(
+ "DynamicallyCompiledMethod",
+ typeof(void),
+ methodArgs);
+
+ ILGenerator il = dynamicMethod.GetILGenerator();
+ il.Emit(OpCodes.Ret);
+
+ return (DynamicallyCompiledMethodInvoker)dynamicMethod.CreateDelegate(typeof(DynamicallyCompiledMethodInvoker));
+ }
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <SchemaVersion>2.0</SchemaVersion>
+ <ProjectGuid>{8E3244CB-407F-4142-BAAB-E7A55901A5FA}</ProjectGuid>
+ <OutputType>Exe</OutputType>
+ <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
+ <CLRTestKind>BuildAndRun</CLRTestKind>
+ <DefineConstants>$(DefineConstants);STATIC</DefineConstants>
+ <CLRTestPriority>0</CLRTestPriority>
+ </PropertyGroup>
+ <!-- Default configurations to help VS understand the configurations -->
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"></PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"></PropertyGroup>
+ <ItemGroup>
+ <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies">
+ <Visible>False</Visible>
+ </CodeAnalysisDependentAssemblyPaths>
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="JittingStarted.cs" />
+ <ProjectReference Include="../../common/common.csproj" />
+ </ItemGroup>
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
+</Project>
\ No newline at end of file