dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.28k stars 5.91k forks source link

GC ETW Documentation does not document GCAllocationTick_V4 #43566

Open antiduh opened 1 day ago

antiduh commented 1 day ago

Type of issue

Typo

Description

It seems under dotnet 8 or dotnet 9, GC ETW events no longer produce GCAllocationTick_V3 events, and instead produce GCAllocationTick_V4 events. However, there is no documentation for V4.

According to the ETW data, the PayloadNames are the following:

Page URL

https://learn.microsoft.com/en-us/dotnet/framework/performance/garbage-collection-etw-events

Content source URL

https://github.com/dotnet/docs/blob/main/docs/framework/performance/garbage-collection-etw-events.md

Document Version Independent Id

eb24522a-de26-44e6-75fc-4a332fe45501

Article author

@BillWagner

Metadata

Related Issues

antiduh commented 1 day ago

Here's some code to exercise this feature, if it's helpful:

    public class Program
    {
        public static void Main( string[] args )
        {
            using( var watcher = new AllocationWatcher() )
            {
                while( true )
                {
                    Thread.Sleep( 100 );

                    byte[] bytes = new byte[50000];
                }
            }
        }
     }

    public sealed class AllocationWatcher : EventListener, IDisposable
    {
        private const int GC_KEYWORD = 0x0000001;

        private EventSource dotnetEvents;

        public AllocationWatcher()
        { }

        protected override void OnEventSourceCreated( EventSource eventSource )
        {
            // look for .NET Garbage Collection events
            if( eventSource.Name.Equals( "Microsoft-Windows-DotNETRuntime" ) )
            {
                dotnetEvents = eventSource;
                EnableEvents( eventSource, EventLevel.Verbose, (EventKeywords)GC_KEYWORD );
            }
        }

        protected override void OnEventWritten( EventWrittenEventArgs eventData )
        {
            switch( eventData.EventName )
            {
                case "GCAllocationTick_V4":
                    ProcessAllocationEvent( eventData );
                    break;
            }
        }

        private void ProcessAllocationEvent( EventWrittenEventArgs eventData )
        {
            ulong size = (ulong)eventData.Payload[3];
            string typeName = (string)eventData.Payload[5];

            Console.WriteLine( $"Allocation: Size: {size}. Type:\r\n{typeName}" );
        }
    }