Skip to content

[clr-interp] Add support for logging interpreter IR ranges to perf map - #129989

Merged
BrzVlad merged 1 commit into
dotnet:mainfrom
BrzVlad:feature-interp-perfmap
Jul 1, 2026
Merged

BrzVlad merged 1 commit into
dotnet:mainfrom
BrzVlad:feature-interp-perfmap

Conversation

@BrzVlad

@BrzVlad BrzVlad commented Jun 29, 2026

Copy link
Copy Markdown
Member

Tested that it works correctly when passing the following env vars to the runtime:

export DOTNET_PerfMapEnabled=1
export DOTNET_PerfMapStubGranularity=2

The interpreter entries from the perf map could be used to profile as described in https://gist.github.com/BrzVlad/80c1b1f61b024f251b60f39c5dedc9d3

Tested that it works correctly when passing the following env vars to the runtime:
```
export DOTNET_PerfMapEnabled=1
export DOTNET_PerfMapStubGranularity=2
```
Copilot AI review requested due to automatic review settings June 29, 2026 17:55
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 extends CoreCLR’s perf-map logging to include interpreter-generated IR ranges, so profiler tools can symbolize interpreter frames similarly to JIT-compiled methods.

Changes:

  • Add PerfMap::LogInterpreterMethod(...) API (guarded by FEATURE_INTERPRETER) and implement logging of interpreter IR ranges.
  • Update MethodDesc::JitCompileCodeLockedEventWrapper to log interpreter IR ranges instead of logging the interpreter entrypoint as a JIT-compiled method.

Reviewed changes

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

File Description
src/coreclr/vm/prestub.cpp Adds interpreter-specific perfmap logging in the JIT/compile wrapper.
src/coreclr/vm/perfmap.h Declares the new interpreter logging entrypoint on PerfMap.
src/coreclr/vm/perfmap.cpp Implements interpreter IR range logging to the perfmap output.

Comment thread src/coreclr/vm/prestub.cpp Resolved
Comment thread src/coreclr/vm/perfmap.cpp Resolved
@BrzVlad

BrzVlad commented Jun 29, 2026 •

Copy link
Copy Markdown
Member Author

Example usage: ~/profile.sh x27 ./corerun gettype.dll. The automated register fetching via script-find-ip-reg.sh is not very reliable, it worked fine with checked build but no longer with release (maybe due to the computed goto change). Copilot can easily tweak the script or detect the real register from the disassembly however. EDIT: Updated the script to a new mechanism based on load + br.

Normal perf output (non-descriptive InterpMethodExec)

    79.36%  corerun         libcoreclr.so          [.] InterpExecMethod(InterpreterFrame*, InterpMethodContextFrame*, InterpThreadContext*, ExceptionClauseArgs*)
     4.89%  corerun         libc.so.6              [.] __memset_zva64
     4.74%  corerun         libcoreclr.so          [.] FrameDataAllocator::PopInfo(InterpMethodContextFrame*)
     2.10%  corerun         ld-linux-aarch64.so.1  [.] _dl_tlsdesc_dynamic
     1.99%  corerun         libcoreclr.so          [.] memset@plt
     1.32%  corerun         libcoreclr.so          [.] InterpreterStub
     1.08%  corerun         libcoreclr.so          [.] ErectWriteBarrier(Object**, Object*)
     0.60%  corerun         libcoreclr.so          [.] ExecuteInterpretedMethod

Parsed interp execution:

Samples       %  Method
 -------     ---  ------
    2590   22.4%  [Interpreter] void [System.Private.CoreLib] System.SpanHelpers::Memmove(uint8&,uint8&,native uint)
    1070    9.2%  [Interpreter] object [System.Private.CoreLib] System.Runtime.CompilerServices.CastHelpers::Box(valuetype System.Runtime.CompilerServices.MethodTable*,uint8&)
     860    7.4%  [Interpreter] instance bool [System.Linq] System.Linq.Enumerable+RepeatIterator`1[System.Int32]::MoveNext()
     729    6.3%  [Interpreter] void [gettype] ConsumerExtensions::Consume(class [System.Runtime]System.Collections.IEnumerable,class Consumer)
     685    5.9%  [Interpreter] !!0& [System.Private.CoreLib] System.Runtime.CompilerServices.Unsafe::Add(!!0&,int32)
     588    5.1%  [Interpreter] object [System.Private.CoreLib] System.RuntimeTypeHandle::InternalAllocNoChecks(valuetype System.Runtime.CompilerServices.MethodTable*)
     551    4.8%  [Interpreter] !!0 [System.Private.CoreLib] System.Runtime.CompilerServices.Unsafe::ReadUnaligned(uint8&)
     535    4.6%  [Interpreter] !!0& [System.Private.CoreLib] System.Runtime.CompilerServices.Unsafe::Add(!!0&,native uint)
....
       1    0.0%  [Interpreter] instance void [gettype] Program::BenchRepeat()
       1    0.0%  [Interpreter] instance void [System.Private.CoreLib] System.Object::.ctor()

Total samples: 14576, in InterpExecMethod: 11568 (79.4%), resolved: 11370 (98.3%)

@BrzVlad
BrzVlad requested a review from davidwrighton June 29, 2026 18:03

@davidwrighton davidwrighton 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.

I think we can get an even better profiler than this constructed with actual mixed interpreter/native stack walking, but this is a great first step.

@BrzVlad
BrzVlad merged commit a31b492 into dotnet:main Jul 1, 2026
113 checks passed
@BrzVlad

BrzVlad commented Jul 1, 2026 •

Copy link
Copy Markdown
Member Author

@davidwrighton Any more detail about what you mean here ? I normally envision this as an internal development tool, where you also care about native bits in the runtime. For all other things, managed only profiling, we would need to make sure that the interpreter frames integrate well into the dotnet-trace flows, which I belive are used for profiling apps by customers. Last time I tried a couple of months ago, it wasn't really working. Do you envision also third approach ? Or any other nice to haves on the interpreter profiling front ?

EDIT: It looks like profiling with dotnet-trace actually works correctly with the interpreter.

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 2, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
#129989)

Tested that it works correctly when passing the following env vars to
the runtime:
```
export DOTNET_PerfMapEnabled=1
export DOTNET_PerfMapStubGranularity=2
```

The interpreter entries from the perf map could be used to profile as
described in
https://gist.github.com/BrzVlad/80c1b1f61b024f251b60f39c5dedc9d3
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants