Skip to content

[NativeAOT] Add sampling profiler #108083

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

Merged
merged 2 commits into from
Jun 4, 2025

Conversation

filipnavara
Copy link
Member

Presumably this is pretty useless since we don't do the rundown to get readable method names... but since I already have it laying around, anyone can think of a use for this?

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Sep 20, 2024
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

@MichalStrehovsky
Copy link
Member

@LakshanF do you think we'd be able to implement the rest?

If there is a rundown for this, we do have names of methods available in stack trace metadata. If the rundown can run managed code, we could get it there. Maybe. Depending on what actually involves the rundown.

@filipnavara
Copy link
Member Author

I only tried to run it with dotnet-trace and conversion to Speedscope format, which was quite useless, since you could see the stack traces but instead of method names there was just "?!?". I wonder if PerfView could perhaps show the addresses or correlate that to image base addresses. That would be already good enough for tools that can perform native symbolication (eg. Sentry).

Stack trace metadata sound like an interesting thing to try...

@LakshanF
Copy link
Contributor

LakshanF commented Oct 1, 2024

There is a work item in the diagnostic repo to lookup type information for native AOT GCDump, which could be expanded to include method information as well.

Copy link
Contributor

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 1, 2024
@MichalStrehovsky
Copy link
Member

This is useful on its own - without this, dotnet-gcdump will just hang at "Flushing the type table".

@dotnet dotnet unlocked this conversation Jun 4, 2025
@MichalStrehovsky MichalStrehovsky marked this pull request as ready for review June 4, 2025 05:29
@Copilot Copilot AI review requested due to automatic review settings June 4, 2025 05:29
@MichalStrehovsky MichalStrehovsky self-requested a review as a code owner June 4, 2025 05:29
Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

Thank you!

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a basic sampling profiler for NativeAOT by adding helper methods and integrating stack walking logic.

  • Added a new GetTransitionFrameForSampling method in thread.h
  • Extended the sampling event capture logic in ep-rt-aot.cpp
  • Introduced a GetControlPC method in StackFrameIterator.h

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/coreclr/nativeaot/Runtime/thread.h Added a helper method to support sampling profiler functionality
src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp Integrated sampling profiler logic to capture stack frames and emit events
src/coreclr/nativeaot/Runtime/StackFrameIterator.h Exposed the control PC via a new method for use by the profiler
Comments suppressed due to low confidence (3)

src/coreclr/nativeaot/Runtime/thread.h:323

  • Consider adding a brief comment to clarify the purpose and usage of GetTransitionFrameForSampling for future maintainability.
PInvokeTransitionFrame* GetTransitionFrameForSampling() { return GetTransitionFrame(); }

src/coreclr/nativeaot/Runtime/eventpipe/ep-rt-aot.cpp:113

  • [nitpick] Clarify or document in a tracking issue whether the differentiation between managed and external code will be addressed later to improve future code maintainability.
            // TODO: We can actually detect whether we are in managed or external code but does it matter?!

src/coreclr/nativeaot/Runtime/StackFrameIterator.h:58

  • Consider adding a comment to describe the role of GetControlPC in the sampling process to aid future maintainers.
PTR_VOID         GetControlPC() { return m_ControlPC; }

@MichalStrehovsky
Copy link
Member

/azp run runtime-nativeaot-outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@MichalStrehovsky
Copy link
Member

/ba-g the arm32 build break was fixed and the rest are known

@MichalStrehovsky MichalStrehovsky merged commit 3427e5f into dotnet:main Jun 4, 2025
111 of 117 checks passed
@filipnavara filipnavara deleted the aot-sampling branch June 4, 2025 21:01
@github-actions github-actions bot locked and limited conversation to collaborators Jul 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants