Skip to content

Create custom events in GCPerfsim test #4893

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -22,18 +22,18 @@ public sealed class TraceCollector : IDisposable
private static readonly Lazy<WebClient> _client = new();

// TODO: Make this URL configurable.
private const string PERFVIEW_URL = "https://github.com/microsoft/perfview/releases/download/v3.0.0/PerfView.exe";
private const string PERFVIEW_URL = "https://github.com/microsoft/perfview/releases/download/v3.1.23/PerfView.exe";

private readonly string ALWAYS_ARGS = @$" /AcceptEULA /NoGUI /Merge:true";
internal static readonly Dictionary<CollectType, string> WindowsCollectTypeMap = new()
{
{ CollectType.gc, "/GCCollectOnly" },
{ CollectType.verbose, "/ClrEventLevel:Verbose /ClrEvents:GC+Stack" },
{ CollectType.cpu, "/KernelEvents=Process+Thread+ImageLoad+Profile /ClrEventLevel:Informational /ClrEvents:GC+Stack /BufferSize:3000 /CircularMB:3000" },
{ CollectType.cpu_managed, "/KernelEvents=Process+Thread+ImageLoad+Profile /ClrEventLevel:Informational /ClrEvents:GC+Stack+Codesymbols+JitSymbols+Compilation+Type+GCHeapAndTypeNames /BufferSize:3000 /CircularMB:3000" },
{ CollectType.threadtime_managed, "/KernelEvents=Process+Thread+ImageLoad+Profile+ContextSwitch+Dispatcher /ClrEvents:GC+Stack+Codesymbols+JitSymbols+Compilation+Type+GCHeapAndTypeNames /BufferSize:3000 /CircularMB:3000 /ClrEventLevel=Verbose" },
{ CollectType.threadtime, "/KernelEvents=Process+Thread+ImageLoad+Profile+ContextSwitch+Dispatcher /ClrEvents:GC /ClrEventLevel=Verbose /BufferSize:3000 /CircularMB:3000 " },
{ CollectType.join, " /BufferSizeMB:4096 /CircularMB:4096 /KernelEvents:Process+Thread+ImageLoad /ClrEvents:GC+Threading /ClrEventLevel=Verbose " },
{ CollectType.gc, "/KernelEvents=Process /Providers=GCPerfsimCustomEvents::Verbose /ClrEventLevel:Informational /ClrEvents:GC" },
{ CollectType.verbose, "/ClrEventLevel:Verbose /Providers=GCPerfsimCustomEvents::Verbose /ClrEvents:GC+Stack" },
{ CollectType.cpu, "/KernelEvents=Process+Thread+ImageLoad+Profile /Providers=GCPerfsimCustomEvents::Verbose /ClrEventLevel:Informational /ClrEvents:GC+Stack /BufferSize:3000 /CircularMB:3000" },
{ CollectType.cpu_managed, "/KernelEvents=Process+Thread+ImageLoad+Profile /Providers=GCPerfsimCustomEvents::Verbose /ClrEventLevel:Informational /ClrEvents:GC+Stack+Codesymbols+JitSymbols+Compilation+Type+GCHeapAndTypeNames /BufferSize:3000 /CircularMB:3000" },
{ CollectType.threadtime_managed, "/KernelEvents=Process+Thread+ImageLoad+Profile+ContextSwitch+Dispatcher /Providers=GCPerfsimCustomEvents::Verbose /ClrEvents:GC+Stack+Codesymbols+JitSymbols+Compilation+Type+GCHeapAndTypeNames /BufferSize:3000 /CircularMB:3000 /ClrEventLevel=Verbose" },
{ CollectType.threadtime, "/KernelEvents=Process+Thread+ImageLoad+Profile+ContextSwitch+Dispatcher /Providers=GCPerfsimCustomEvents::Verbose /ClrEvents:GC /ClrEventLevel=Verbose /BufferSize:3000 /CircularMB:3000 " },
{ CollectType.join, " /BufferSizeMB:4096 /CircularMB:4096 /KernelEvents:Process+Thread+ImageLoad /Providers=GCPerfsimCustomEvents::Verbose /ClrEvents:GC+Threading /ClrEventLevel=Verbose " },
};

internal static readonly Dictionary<CollectType, string> LinuxCollectTypeMap = new()
Expand Down
43 changes: 43 additions & 0 deletions src/benchmarks/gc/GCPerfSim/CustomEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Diagnostics;
using System.Diagnostics.Tracing;

[EventSource(Name = "GCPerfsimCustomEvents")]
public class GCPerfsimCustomEvents : EventSource
{
private const int PrivateMemoryAtGCStartEventId = 1;
private const int PrivateMemoryAtGCEndEventId = 2;

public static GCPerfsimCustomEvents Log = new GCPerfsimCustomEvents();

[Event(PrivateMemoryAtGCStartEventId)]
public void PrivateMemoryAtGCStart(long PrivateMemory) => WriteEvent(PrivateMemoryAtGCStartEventId, PrivateMemory);

[Event(PrivateMemoryAtGCEndEventId)]
public void PrivateMemoryAtGCEnd(long PrivateMemory) => WriteEvent(PrivateMemoryAtGCEndEventId, PrivateMemory);
}

public class GCEventListener : EventListener
{
protected override void OnEventSourceCreated(EventSource eventSource)
{
if (String.CompareOrdinal(eventSource.Name, "Microsoft-Windows-DotNETRuntime") == 0)
{
EnableEvents(eventSource, EventLevel.Informational, (EventKeywords)0x1); // GC keyword
}
}

protected override void OnEventWritten(EventWrittenEventArgs eventData)
{
if (String.CompareOrdinal(eventData.EventName, "GCStart_V2") == 0)
{
long privateMemory = Process.GetCurrentProcess().PrivateMemorySize64;
GCPerfsimCustomEvents.Log.PrivateMemoryAtGCStart(privateMemory);
}
if (String.CompareOrdinal(eventData.EventName, "GCEnd_V1") == 0)
{
long privateMemory = Process.GetCurrentProcess().PrivateMemorySize64;
GCPerfsimCustomEvents.Log.PrivateMemoryAtGCEnd(privateMemory);
}
}
}
4 changes: 4 additions & 0 deletions src/benchmarks/gc/GCPerfSim/GCPerfSim.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<NullableReferenceTypes>true</NullableReferenceTypes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.14.0" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.12" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions src/benchmarks/gc/GCPerfSim/Harness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ public static class Harness
{
public static void Main(string[] args)
{
using var listener = new GCEventListener();
MemoryAlloc.Test(args);
}
}