Skip to content

Preserve source and callback when cloning predefined dynamic events - #2472

Merged
Brian Robbins (brianrob) merged 1 commit into
microsoft:mainfrom
evschaff:dev/evschaff/traceevent-clone-source
Oct 2, 2026
Merged

Brian Robbins (brianrob) merged 1 commit into
microsoft:mainfrom
evschaff:dev/evschaff/traceevent-clone-source

Conversation

@evschaff

@evschaff evschaff commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fix cloning of populated PredefinedDynamicEvent instances. TraceLog.GetEvent() returns a clone, but the current override unconditionally clears its source and callback as if every clone were an unpopulated parser template. For Universal CPU events, subsequently calling CallStack() fails with:

Attempted to use TraceLog support on a non-TraceLog TraceEventSource.

This is an existing issue, also present in TraceEvent 3.2.6.

Changes

  • Clear traceEventSource and Target only when cloning an unpopulated template (eventRecord == null).
  • Preserve source and callback for populated events, consistent with the base TraceEvent.Clone() behavior.
  • Add focused coverage for populated CPU/context-switch event clones and detached template clones. CloneToTemplate() continues to explicitly detach its result.

Validation

On this branch, Windows x64:

  • Targeted Debug/net10.0 UniversalTests: 10 passed.
  • Targeted Release rebuild of TraceEvent.Tests.csproj: succeeded.

The full repository test suite and other target frameworks were not run for this branch.

Keep populated predefined dynamic event copies attached to their source and callback while leaving template clones detached.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@evschaff
evschaff requested a review from a team as a code owner October 2, 2026 02:21
@evschaff evschaff changed the title [WIP] Preserve source and callback when cloning predefined dynamic events Preserve source and callback when cloning predefined dynamic events Oct 2, 2026

@brianrob Brian Robbins (brianrob) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks evschaff!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants