[WIP] IL "source" references in JIT map - #132948
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
When jitdump is enabled and DOTNET_PerfMapIlSourcePath is set, emit a JIT_CODE_DEBUG_INFO record before each JIT_CODE_LOAD, mapping native offsets to synthetic IL source files (contract: IL instruction at offset K is on line K + 2 of <dir>/<assembly>/m_<token>.il; the files themselves are produced by external tooling from assembly metadata). This completes the existing ToDo in perfjitdump.cpp LogMethod. perf inject --jit converts the records to DWARF .debug_line in the emitted jitted-*.so files, giving perf annotate, addr2line and samply IL-level source attribution for JIT-compiled managed code. Disabled by default; no additional work on the JIT path unless the config is set. IL-to-native boundaries are obtained via WalkILOffsets/ILToNativeMapArrays, the same helpers used by the ETW MethodILToNativeMap event.
I have seen other profilers display the C# source code; how do they do that? |
Postprocessing I believe: if between getting samples and firing up the UI you replace IL references to source code references (external tools have all that), it'll just work. But I haven't got there yet. Was any of those profilers The postprocessing approach:
I'll see if it's practical, and update. On the CLA, will need to double check at the office, so Tuesday. Apologies for a cheeky draft PR—I thought it would be a cheap, low-visibility CI run :) |
|
@alf239 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement ( “Agreement” ) is agreed to by the party signing below ( “You” ), 1. Definitions. “Code” means the computer software code, whether in human-readable or machine-executable form, “Project” means any of the projects owned or managed by .NET Foundation and offered under a license “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any “Submission” means the Code and any other copyrightable material Submitted by You, including any 2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any 3. Originality of Work. You represent that each of Your Submissions is entirely Your 4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else 5. Licenses. a. Copyright License. You grant .NET Foundation, and those who receive the Submission directly b. Patent License. You grant .NET Foundation, and those who receive the Submission directly or c. Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement. 6. Representations and Warranties. You represent that You are legally entitled to grant the above 7. Notice to .NET Foundation. You agree to notify .NET Foundation in writing of any facts or 8. Information about Submissions. You agree that contributions to Projects and information about 9. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and 10. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and .NET Foundation dedicates this Contribution License Agreement to the public domain according to the Creative Commons CC0 1. |
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
|
On a related note: I integrated Samply into EgorBot for macos-arm64 target (on Linux I use @EgorBot -macos_arm -profiler using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Runtime.CompilerServices;
BenchmarkSwitcher.FromAssembly(typeof(MyBench).Assembly).Run(args);
public class MyBench
{
object _fld;
[Benchmark] public void Foo() => Bar();
[MethodImpl(MethodImplOptions.NoInlining)]
public void Bar() => _fld = new object();
} |
samplyis happy to show the assembly of the code sampled, but the "source" tab stays empty for .net apps, which is a pity.Now it would be tempting to add a proper source reference, but JIT doesn't know about the real source, so that's a headache. On the other hand, JIT does know about the IL it compiles, so we can pretend IR is the source, et voila:
The empty lines where IL instruction is longer are either clumsy or cute, depending on how you look at those.