microsoft / perfview

PerfView is a CPU and memory performance-analysis tool
http://channel9.msdn.com/Series/PerfView-Tutorial
MIT License
4.05k stars 696 forks source link

.NET Alloc profiler activation on .NET (Core) #1955

Open ocoanet opened 7 months ago

ocoanet commented 7 months ago

The .NET Alloc option requires the activation of a specific CLR profiler. The activation is implemented in PerfView by configuring HKLM\Software\Microsoft\.NETFramework\COR* registry keys. It does not seem to have any effect on my net7.0 application:

Action Target Framework Has ETWClrProfiler events
Run/Collection net461 Yes
Run/Collection net7.0 No
Run/Collection net7.0 + manual profiler activation using environment variables Yes

Is this behavior a configuration issue on my side?

I could not find any documented way to activate profilers from registry keys for the .NET (Core) runtime, so maybe it is a known and expected behavior.

However, if the profiler cannot be activated using registry keys, I suppose that PerfView should be improved:

It can eventually create a PR for the last point.

brianrob commented 7 months ago

I don't believe that the registry is supported for configuring the profiler API for .NET Core. @davmason can you please confirm.

At the same time, you should be able to capture the unsampled allocation events directly in PerfView without using the profiler API at all. This is done by specifying /ClrEvents:Default+GCAllObjectAllocation.

ocoanet commented 7 months ago

I did a few experiments with GCAllObjectAllocation and it seems to generate unsampled Microsoft-Windows-DotNETRuntime/GC/SampledObjectAllocation events. So, indeed, it is a good option to capture allocations for .NET (Core) programs.

But my main issue is that many collection UI options are linked to the CLR profiler. This fact is not clearly documented and these options have no effect on .NET (Core) programs unless the profiler is manually enabled.

I think that both the collection UI and the documentation (PerfView Help) should be improved to make more explicit the behaviors. Also, it would be nice to have an option to enable GCAllObjectAllocation.

I clearly lake experience on the subject to describe a complete solution. I can only make a few suggestions:

  1. Either move all CLR-profiler-related options to a specific section, or add a "Profiler" prefix to the options labels.
  2. Add a CLR profiler documentation entry to explain its role, usage and activation.
  3. Add an option to automatically enable the profiler in the "Run" collection.
  4. Rename "ETW .NET Alloc" to "CLR SampAlloc".
  5. Add an option "CLR Alloc" (related to GCAllObjectAllocation).

I can probably help on these tasks if needed.