Hack the Mono runtime to emit JIT symbol mapping ETW events, have xperf in your Unity! Capture low overhead sampling performance profiling stack traces that span the Unity engine, the Mono runtime, your jitted .NET code, and even the Windows kernel!
- Replace Unity's mono.dll with the appropriately altered matching mono.dll (2018.2 v3.5 runtime provided; all other version left as an exercise for the reader)
- Before launching your program, start recording a trace using xperf from the Windows Performance Toolkit:
xperf -on Base -Stackwalk Profile -start MonoSymbolTrace -on Microsoft-JScript
. - Now you can start it. Do your thing.
- Stop & save the trace:
xperf -stop -stop MonoSymbolTrace -d MyUnityTrace.etl
- Open up your shiny new etl file in Windows Performance Analyzer. Add
http://symbolserver.unity3d.com/
to your symbol path for Unity player symbols, and make sure it can find the mono.pdb that matches your mono.dll too.
There are four ETW providers that WPA knows how to translate into symbols for jitted code: Microsoft-Windows-DotNetRuntime, Microsoft-JScript, WARP, and VPC. The only thing I know about the WARP and VPC providers is their GUID (I don't even know their actual names!), so they're out. DotNetRuntime seems the obvious choice for Mono - but the JScript events are much less complex and easy for me to test behaviors against so I picked it for an easier proof-of-concept.
I haven't implemented any of the data collection start/end rundown events - the assembly load & jit compile events get emitted once, when they happen, and if you aren't listening at the time, they're gone.