Conversation
…TraceEventParser Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add typed schema for AllocationSampled EventID 303
Add typed schema for AllocationSampled (EventID 303, .NET 10+) in ClrTraceEventParser
Mar 19, 2026
brianrob
reviewed
Mar 20, 2026
|
|
||
| // Also subscribe to Dynamic.All to confirm the event does fire (it might | ||
| // still appear in the Dynamic stream as a fallback, that is acceptable) | ||
| source.Dynamic.All += data => |
Member
There was a problem hiding this comment.
Remove the dynamic test and dynamicHandlerHits.
Contributor
Author
There was a problem hiding this comment.
Done in 7569f1a — removed the Dynamic.All subscription and dynamicHandlerHits variable.
| GCSampledObjectAllocationLow = 0x2000000, | ||
| PerfTrack = 0x20000000, | ||
| Stack = 0x40000000, | ||
| AllocationSampling = 0x80000000000, |
Member
There was a problem hiding this comment.
Undo the changes in this file.
Contributor
Author
There was a problem hiding this comment.
Done in 7569f1a — reverted ClrTraceEventParser.cs.base to its pre-PR state.
| WaitHandle = 0x40000000000, | ||
|
|
||
| /// <summary> | ||
| /// Events for randomized allocation sampling (AllocationSampled, EventID 303). Requires .NET 10+. |
Member
There was a problem hiding this comment.
Suggested change
| /// Events for randomized allocation sampling (AllocationSampled, EventID 303). Requires .NET 10+. | |
| /// Events for randomized allocation sampling. |
| } | ||
|
|
||
| /// <summary> | ||
| /// Data for the AllocationSampled event (EventID 303, .NET 10+). |
Member
There was a problem hiding this comment.
Suggested change
| /// Data for the AllocationSampled event (EventID 303, .NET 10+). | |
| /// Data for the AllocationSampled event. |
| /// <summary> | ||
| /// Data for the AllocationSampled event (EventID 303, .NET 10+). | ||
| /// Emitted by the randomized allocation sampler when <see cref="ClrTraceEventParser.Keywords.AllocationSampling"/> | ||
| /// is enabled on the <c>Microsoft-Windows-DotNETRuntime</c> provider. |
Member
There was a problem hiding this comment.
Suggested change
| /// is enabled on the <c>Microsoft-Windows-DotNETRuntime</c> provider. | |
| /// is enabled. |
…namic handler test Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
Contributor
Author
brianrob
reviewed
Mar 20, 2026
| /// <summary> | ||
| /// Data for the AllocationSampled event. | ||
| /// Emitted by the randomized allocation sampler when | ||
| /// is enabled. |
…c comment Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
mconnew
approved these changes
Mar 20, 2026
This was referenced Apr 1, 2026
This was referenced Apr 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2385.
AllocationSampled(EventID 303), added in .NET 10 via dotnet/runtime#104955, had no entry inClrTraceEventParser. Because CLR runtime events carry no embedded manifest in EventPipe.nettracefiles, theDynamicparser cannot synthesise a schema — allPayloadByName/PayloadValuecalls silently returnnullor a sentinel exception string, andsource.Clr.Allnever fires for this event.Schema definition (from
ClrEtwAll.man)Task
AllocationSampling(value=40, GUID{CC82530E-A21C-4EB0-A68A-FA4F7E66498F}), EventID 303, opcode 0 (Info), keywordAllocationSamplingKeyword = 0x80000000000.AllocationKindwin:UInt32(0=SOH, 1=LOH, 2=POH)ClrInstanceIDwin:UInt16TypeIDwin:PointerTypeNamewin:UnicodeStringAddresswin:PointerObjectSizewin:UInt64SampledByteOffsetwin:UInt64Changes
ClrTraceEventParser.Keywords— addedAllocationSampling = 0x80000000000ClrTraceEventParser— addedpublic event Action<AllocationSampledTraceData> AllocationSampling(EventID 303, Task 40, Opcode 0). The property is namedAllocationSamplingrather thanAllocationSampledbecause opcode=0 (Info) collapsesEventNameto just the task name, which must match the internal template/event validatorAllocationSampledTraceData— new sealed class with all 7 typed payload accessors,PayloadNames,PayloadValue,ToXml,Validate, andGetKeywords. Pointer-relative offsets use theHostOffset(10, 1)convention (10 = 6 fixed bytes + 4-byte minimum for TypeID pointer;HostOffsetadds the remaining 4 bytes on 64-bit traces)EnumerateTemplates— array size 147→148, new entry wired inClrTraceEventParser.cs.base— mirrored all changesAfter this change:
Test
Added
AllocationSampledEventRoutesAndDecodesPayloadinEventPipeParsing.cs: builds a minimal in-memory V6 nettrace containing oneAllocationSampledevent with a known binary payload and asserts the event dispatches throughsource.Clr.AllocationSampling, all 7 typed accessors decode correctly, andPayloadByName/PayloadValueround-trip cleanly.Original prompt
This section details on the original issue you should resolve
<issue_title>
AllocationSampled(EventID 303, .NET 10+) has no typed schema inClrTraceEventParser</issue_title><issue_description>## Problem
AllocationSampled(EventID 303) was added to the CLR in .NET 10 via dotnet/runtime#104955.ClrTraceEventParser.cs.basehas no entry for it — EventID 303 is entirely absent from the parser, which currently covers events up to approximately EventID 190.Because CLR runtime events do not embed ETW manifest blocks in EventPipe
.nettracefiles (unlikeEventSourceevents), theDynamicparser cannot synthesise a schema at runtime. All field accessors fail — and critically,PayloadValuefails silently: it neither throws nor returnsnullbut returns an opaque sentinel string, making it impossible to distinguish a missing schema from a valid value:source.Clr.Allnever fires for EventID 303 — the event is not routed throughClrTraceEventParserat all.The event carries the following payload fields (from
ClrEtwAll.man):AllocationKindwin:UInt32(0=SOH, 1=LOH, 2=POH)ClrInstanceIDwin:UInt16TypeIDwin:PointerTypeNamewin:UnicodeStringAddresswin:PointerObjectSizewin:UInt64SampledByteOffsetwin:UInt64Expected behaviour
ClrTraceEventParsershould expose a typed event handler (e.g.Clr.AllocationSampled) backed by anAllocationSampledTraceDataclass, analogous toGCAllocationTickTraceData(EventID 10).PayloadNamesshould return["AllocationKind", "ClrInstanceID", "TypeID", "TypeName", "Address", "ObjectSize", "SampledByteOffset"]and allPayloadByName/PayloadValuecalls should return correctly typed values.Actual behaviour
PayloadNamesreturns an emptystring[](length 0, notnull).PayloadByName(...)returnsnull.PayloadValue(0)returns the sentinel string<<<EXCEPTION_DURING_VALUE_LOOKUP IndexOutOfRangeException>>>— TraceEvent catches the internalIndexOutOfRangeExceptionand surfaces it as a string rather than rethrowing. The only way to extract any data is raw byte parsing viaTraceEvent.EventData()using the binary layout reverse-engineered from the dotnet/runtime reference consumer.Workaround
Parse the raw payload from
data.EventData()using the known binary layout. Pointer size is read fromdata.PointerSize.Full implementation:
TryParseAllocationSampledin the repro project.Environment
Microsoft.Diagnostics.Tracing.TraceEventMicrosoft-Windows-DotNETRuntimeAllocationSamplingKeyword = 0x80000000000Repro
Self-contained .NET 10 console project: https://github.com/baal2000/AllocationSampledRepro
git clone https://github.com/baal2000/AllocationSampledRepro cd AllocationSampledRepro dotnet runThe project instruments itself via
DiagnosticsClientwithAllocationSamplingKeyword, allocates 200 000 objects to guarantee sampled events, then parses the resulting trace twice — once via the native TraceEvent API (broken), once viaEventData()raw bytes (workaround).Actual console output
CI-verified on GitHub-hosted
ubuntu-latest, .NET 10.0.5, TraceEvent 3.1.30 — job log: