dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.45k stars 4.76k forks source link

MemoryAllocatedForJitCode ETW Event missing in trace, but CLRStackWalk still fires #102004

Open vvuk opened 6 months ago

vvuk commented 6 months ago

Description

When the ETW JIT keyword is enabled with Verbose along with the STACK keyword (at Info in this specific case, but I don't think that matters), it looks like MethodJittingStarted events are followed by two stack traces. The second one is coming from the MemoryAllocatedForJitCode event callout, but that event is not making it into the trace.

Reproduction Steps

xperf -start UserSession -on Microsoft-Windows-DotNETRuntime:0x40000000:4+Microsoft-Windows-DotNETRuntime:0x30:5, run some dotnet thing, xperf -stop -d foo.etl. Then probably xperf -i foo.etl -a dumper or similar and look at the events.

Expected behavior

MemoryAllocatedForJitCode event should be included in the trace. Obviously this is minor, but I did spend a bunch of time trying to figure out why stacks weren't lining up with events (other than no-stack events) :)

Actual behavior

The event is missing, but it looks like it at least tried to fire (FireEtw... was called), and its Stackwalk fires. See two stacks in the image below. The first little blue square on the timeline is the MethodJittingStarted event.

image

Regression?

No response

Known Workarounds

No response

Configuration

dotnet 8.0.204

Other information

No response

tommcdon commented 6 months ago

Adding @kunalspathak for thoughts. It seems this event was added on #44030.

tommcdon commented 6 months ago

@vvuk it's possible this is an issue specific to xperf. Would you mind trying with https://github.com/microsoft/perfview and reporting back if it correctly emits the event?

vvuk commented 6 months ago

Hmm, sure, but I'm not sure why xperf vs perfview would matter here -- it's the coreclr runtime that's doing the event emitting. With a profile captured by PerfView (after turning on a bunch of the .net etc flags), here's a sample of what I see in the .etl (via dump output) looking at one process, and DotNETRuntime provider events only:

Microsoft-Windows-DotNETRuntime/CLRMethod/MethodJittingStarted,     539043,         pwsh.exe (13680),      11312,   4, , , , , 0x00007fff0014cfa8, 0x00007ffefff34000, 0x06005400, 0x0000013e, "System.Reflection.CustomAttribute", "GetCustomAttributes", "class System.Object[]  (class System.Reflection.RuntimeMethodInfo,class System.RuntimeType,bool)", 6
Microsoft-Windows-DotNETRuntime/CLRStack/CLRStackWalk,     539045,         pwsh.exe (13680),      11312,   4, , , , , 6, 0, 0, 18, [0x00007fff5fd63edd : 0x00007fff5fd6588f]
Microsoft-Windows-DotNETRuntime/CLRStack/CLRStackWalk,     540635,         pwsh.exe (13680),      11312,   4, , , , , 6, 0, 0, 28, [0x00007fff5fd63edd : 0x00007fff5fd6588f]
Microsoft-Windows-DotNETRuntime/CLRMethod/MethodLoadVerbose,     540831,         pwsh.exe (13680),      11312,   4, , , , , 0x00007fff0014cfa8, 0x00007ffefff34000, 0x00007fff0125bb80, 0x000005a3, 0x06005400, 520, "System.Reflection.CustomAttribute", "GetCustomAttributes", "class System.Object[]  (class System.Reflection.RuntimeMethodInfo,class System.RuntimeType,bool)", 6, 0x0000000000000001
...
Microsoft-Windows-DotNETRuntime/CLRMethod/MethodJittingStarted,     540855,         pwsh.exe (13680),      11312,   4, , , , , 0x00007fff0014d378, 0x00007ffefff34000, 0x0600541a, 0x0000008c, "System.Reflection.PseudoCustomAttribute", "GetCustomAttributes", "void  (class System.Reflection.RuntimeMethodInfo,class System.RuntimeType,value class ListBuilder`1<class System.Attribute>&)", 6
Microsoft-Windows-DotNETRuntime/CLRStack/CLRStackWalk,     540858,         pwsh.exe (13680),      11312,   4, , , , , 6, 0, 0, 18, [0x00007fff5fd63edd : 0x00007fff5fd6588f]
Microsoft-Windows-DotNETRuntime/CLRStack/CLRStackWalk,     541108,         pwsh.exe (13680),      11312,   4, , , , , 6, 0, 0, 28, [0x00007fff5fd63edd : 0x00007fff5fd6588f]
Microsoft-Windows-DotNETRuntime/CLRMethod/MethodLoadVerbose,     541157,         pwsh.exe (13680),      11312,   4, , , , , 0x00007fff0014d378, 0x00007ffefff34000, 0x00007fff0125c160, 0x00000112, 0x0600541a, 520, "System.Reflection.PseudoCustomAttribute", "GetCustomAttributes", "void  (class System.Reflection.RuntimeMethodInfo,class System.RuntimeType,value class ListBuilder`1<class System.Attribute>&)", 6, 0x0000000000000001

There's the MethodJittingStarted for a method, followed by two CLRStackWalk events, then the MethodLoadVerbose for the method that was just jitted.

mdh1418 commented 2 weeks ago

Hi @vvuk, I tried collecting a trace using PerfView on a simple .NET app, and it looks like the MemoryAllocatedForJitCode event showed up.

PerfView setup Image

Events Image

I'm wondering if in your scenario, events are being dropped. Do you know if specifically just the MemoryAllocatedFOrJitCode events are being omitted everytime, or is it sometimes there and sometimes absent when you collect traces?

vvuk commented 2 weeks ago

In my case it was just MemoryAllocatedForJitCode; it was always missing, and no events were dropped.

I wonder if it's a provider configuration issue. In your screenshot you have additional advanced options checked in PerfView, which I believe will enable a bunch of providers in addition to the "additional providers". In my case, I was only enabling those specific providers. Maybe try unchecking everything and just specifying the explicit providers? (Though MethodAllocatedForJitCode is attached to the JitKeyword (0x20), so it should be enabled)

mdh1418 commented 2 weeks ago

I removed all of the checked boxes in the Advanced Options, only specifying the Additional providers Microsoft-Windows-DotNETRuntime:0x40000000:4,Microsoft-Windows-DotNETRuntime:0x30:5.

Image

I still can see the MethodAllocatedForJitCode events Image

I also just specified just the JitKeyword 0x10 (Microsoft-Windows-DotNETRuntime:0x10:5) and the MethodAllocatedForJitCode event still shows

Image

Image