Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using Tracing.Tests.Common;
using System.Collections.Generic;
using System.Collections.Concurrent;

namespace Tracing.Tests
{
Expand All @@ -29,23 +31,38 @@ static int Main(string[] args)

// If on Windows, attempt some Overlapped IO (triggers ThreadPool events)
if (OperatingSystem.IsWindows())
{
DoOverlappedIO();

// Wait for events.
Thread.Sleep(1000);
}

// Generate some GC events.
GC.Collect(2, GCCollectionMode.Forced);

// Wait for more events.
Thread.Sleep(1000);
Stopwatch sw = Stopwatch.StartNew();

while (sw.Elapsed <= TimeSpan.FromMinutes(1))
{
Thread.Sleep(100);

if ((OperatingSystem.IsWindows() && listener.SeenProvidersAndEvents.Contains("Microsoft-Windows-DotNETRuntime/EVENTID(65)"))
|| (!OperatingSystem.IsWindows() && listener.EventCount > 0))
{
break;
}
}

// Ensure that we've seen some events.
foreach (string s in listener.SeenProvidersAndEvents)
{
Console.WriteLine(s);
}

Assert.True("listener.EventCount > 0", listener.EventCount > 0);

if (OperatingSystem.IsWindows())
{
Assert.True("Saw the ThreadPoolIOPack event", listener.SeenProvidersAndEvents.Contains("Microsoft-Windows-DotNETRuntime/EVENTID(65)"));
}
}

// Generate some more GC events.
Expand All @@ -63,7 +80,9 @@ private static void Allocator()
while (true)
{
for(int i=0; i<1000; i++)
{
GC.KeepAlive(new object());
}

Thread.Sleep(10);
}
Expand All @@ -80,7 +99,7 @@ private static unsafe void DoOverlappedIO()

internal sealed class SimpleEventListener : EventListener
{
public HashSet<string> SeenProvidersAndEvents { get; private set; } = new();
public ConcurrentBag<string> SeenProvidersAndEvents { get; private set; } = new();
private string m_name;

// Keep track of the set of keywords to be enabled.
Expand Down