Skip to content

Commit

Permalink
Reduce process count for ETW manifest test (dotnet#96950)
Browse files Browse the repository at this point in the history
* Reduce process count for ETW manifest test

Remove the launch process and instead run
within the test host. Launch the ETW session
prior to launching the process - removes
the race window between ETW session spin up
and process start.
  • Loading branch information
AaronRobinsonMSFT authored and tmds committed Jan 23, 2024
1 parent f365173 commit a25783f
Showing 1 changed file with 73 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,117 +33,112 @@ public partial class TestsManifestGeneration
[SkipOnCoreClr("Test should only be run in non-stress modes", ~RuntimeTestModes.RegularRun)]
public void Test_EventSource_EtwManifestGeneration()
{
RemoteInvokeOptions options = new RemoteInvokeOptions { TimeOut = 300_000 /* ms */ };
RemoteExecutor.Invoke(() =>
{
RemoteInvokeOptions localOptions = new RemoteInvokeOptions { TimeOut = 300_000 /* ms */ };
using (RemoteInvokeHandle handle = RemoteExecutor.Invoke(() =>
{
var es = new SimpleEventSource();
for (var i = 0; i < 100; i++)
{
es.WriteSimpleInt(i);
Thread.Sleep(100);
}
}, localOptions))
{
var etlFileName = @"file.etl";
var tracesession = new TraceEventSession("testname", etlFileName);
var pid = Process.GetCurrentProcess().Id;
var etlFileName = $"file.{pid}.etl";
var tracesession = new TraceEventSession("testname", etlFileName);

tracesession.EnableProvider("SimpleEventSource");
tracesession.EnableProvider(nameof(SimpleEventSource));

Thread.Sleep(TimeSpan.FromSeconds(5));
RemoteInvokeOptions localOptions = new RemoteInvokeOptions { TimeOut = 300_000 /* ms */ };
using (RemoteInvokeHandle handle = RemoteExecutor.Invoke(() =>
{
var es = new SimpleEventSource();
for (var i = 0; i < 100; i++)
{
es.WriteSimpleInt(i);
Thread.Sleep(100);
}
}, localOptions))
{
Thread.Sleep(TimeSpan.FromSeconds(5));

tracesession.Flush();
tracesession.Flush();

tracesession.DisableProvider("SimpleEventSource");
tracesession.Dispose();
tracesession.DisableProvider(nameof(SimpleEventSource));
tracesession.Dispose();

var manifestExists = false;
var max_retries = 50;
var manifestExists = false;
var max_retries = 50;

for (int i = 0; i < max_retries; i++)
for (int i = 0; i < max_retries; i++)
{
if (VerifyManifestAndRemoveFile(etlFileName))
{
if (VerifyManifestAndRemoveFile(etlFileName))
{
manifestExists = true;
break;
}
Thread.Sleep(1000);
manifestExists = true;
break;
}
Assert.True(manifestExists);
Thread.Sleep(1000);
}
}, options).Dispose();
Assert.True(manifestExists);
}
}

[ConditionalFact(nameof(IsProcessElevatedAndNotWindowsNanoServerAndRemoteExecutorSupported))]
[SkipOnCoreClr("Test should only be run in non-stress modes", ~RuntimeTestModes.RegularRun)]
public void Test_EventSource_EtwManifestGenerationRollover()
{
RemoteExecutor.Invoke(() =>
{
using (RemoteInvokeHandle handle = RemoteExecutor.Invoke(() =>
{
var es = new SimpleEventSource();
for (var i = 0; i < 100; i++)
{
es.WriteSimpleInt(i);
Thread.Sleep(100);
}
}))
{
var initialFileName = @"initialFile.etl";
var rolloverFileName = @"rolloverFile.etl";
var tracesession = new TraceEventSession("testname", initialFileName);
var max_retries = 50;
var pid = Process.GetCurrentProcess().Id;
var initialFileName = $"initialFile.{pid}.etl";
var rolloverFileName = $"rolloverFile.{pid}.etl";
var tracesession = new TraceEventSession("testname", initialFileName);

tracesession.EnableProvider("SimpleEventSource");
tracesession.EnableProvider(nameof(SimpleEventSource));

Thread.Sleep(TimeSpan.FromSeconds(5));
using (RemoteInvokeHandle handle = RemoteExecutor.Invoke(() =>
{
var es = new SimpleEventSource();
for (var i = 0; i < 100; i++)
{
es.WriteSimpleInt(i);
Thread.Sleep(100);
}
}))
{
Thread.Sleep(TimeSpan.FromSeconds(5));

tracesession.Flush();
tracesession.Flush();

tracesession.SetFileName(rolloverFileName);
tracesession.SetFileName(rolloverFileName);

Thread.Sleep(TimeSpan.FromSeconds(5));
Thread.Sleep(TimeSpan.FromSeconds(5));

tracesession.Flush();
tracesession.Flush();

tracesession.DisableProvider("SimpleEventSource");
tracesession.Dispose();
tracesession.DisableProvider(nameof(SimpleEventSource));
tracesession.Dispose();

bool initialFileHasManifest = false;
bool rollOverFileHasManifest = false;
bool initialFileHasManifest = false;
bool rollOverFileHasManifest = false;

for (int i = 0; i < max_retries; i++)
var max_retries = 50;
for (int i = 0; i < max_retries; i++)
{
if (VerifyManifestAndRemoveFile(initialFileName))
{
if (VerifyManifestAndRemoveFile(initialFileName))
{
initialFileHasManifest = true;
break;
}
Thread.Sleep(1000);
initialFileHasManifest = true;
break;
}
for (int i = 0; i < max_retries; i++)
Thread.Sleep(1000);
}
for (int i = 0; i < max_retries; i++)
{
if (VerifyManifestAndRemoveFile(rolloverFileName))
{
if (VerifyManifestAndRemoveFile(rolloverFileName))
{
rollOverFileHasManifest = true;
break;
}
Thread.Sleep(1000);
rollOverFileHasManifest = true;
break;
}
Assert.True(initialFileHasManifest);
Assert.True(rollOverFileHasManifest);
Thread.Sleep(1000);
}
}).Dispose();
Assert.True(initialFileHasManifest);
Assert.True(rollOverFileHasManifest);
}
}

private bool VerifyManifestAndRemoveFile(string fileName)
{
Assert.True(File.Exists(fileName));

ETWTraceEventSource source = new ETWTraceEventSource(fileName);
using var source = new ETWTraceEventSource(fileName);

Dictionary<string, int> providers = new Dictionary<string, int>();
int eventCount = 0;
Expand All @@ -157,7 +152,7 @@ private bool VerifyManifestAndRemoveFile(string fileName)
}
providers[eventData.ProviderName]++;

if (eventData.ProviderName.Equals("SimpleEventSource") && eventData.EventName.Equals("ManifestData"))
if (eventData.ProviderName.Equals(nameof(SimpleEventSource)) && eventData.EventName.Equals("ManifestData"))
{
sawManifestData = true;
}
Expand All @@ -167,7 +162,7 @@ private bool VerifyManifestAndRemoveFile(string fileName)

if (!sawManifestData)
{
Console.WriteLine("Did not see ManifestData event from SimpleEventSource, test will fail. Additional info:");
Console.WriteLine($"Did not see ManifestData event from {nameof(SimpleEventSource)}, test will fail. Additional info:");
Console.WriteLine($" file name {fileName}");
Console.WriteLine($" total event count {eventCount}");
Console.WriteLine($" total providers {providers.Count}");
Expand Down

0 comments on commit a25783f

Please sign in to comment.