diff --git a/src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/TraceCollection/TraceCollector.cs b/src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/TraceCollection/TraceCollector.cs index 752657610b5..4abf99b1c08 100644 --- a/src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/TraceCollection/TraceCollector.cs +++ b/src/benchmarks/gc/GC.Infrastructure/GC.Infrastructure.Core/TraceCollection/TraceCollector.cs @@ -22,18 +22,18 @@ public sealed class TraceCollector : IDisposable private static readonly Lazy _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 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 LinuxCollectTypeMap = new() diff --git a/src/benchmarks/gc/GCPerfSim/CustomEvents.cs b/src/benchmarks/gc/GCPerfSim/CustomEvents.cs new file mode 100644 index 00000000000..25ffaaed394 --- /dev/null +++ b/src/benchmarks/gc/GCPerfSim/CustomEvents.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/src/benchmarks/gc/GCPerfSim/GCPerfSim.csproj b/src/benchmarks/gc/GCPerfSim/GCPerfSim.csproj index 2bc325b893f..0c057c60b62 100644 --- a/src/benchmarks/gc/GCPerfSim/GCPerfSim.csproj +++ b/src/benchmarks/gc/GCPerfSim/GCPerfSim.csproj @@ -10,4 +10,8 @@ true true + + + + diff --git a/src/benchmarks/gc/GCPerfSim/Harness.cs b/src/benchmarks/gc/GCPerfSim/Harness.cs index e363d6d5520..1054f99056c 100644 --- a/src/benchmarks/gc/GCPerfSim/Harness.cs +++ b/src/benchmarks/gc/GCPerfSim/Harness.cs @@ -2,6 +2,7 @@ public static class Harness { public static void Main(string[] args) { + using var listener = new GCEventListener(); MemoryAlloc.Test(args); } } \ No newline at end of file