I'm writing a library plugin for an application. The plugin is written in C# using .NET Framework 4.7.1. In order to debug the application, I have to start an external program. Essentially, it's the same mechanism as "Attach to process". This may be relevant later.
I'm attempting to profile the CPU usage between two breakpoints using Visual Studio's CPU Usage/Profiler diagnostic tool. When attempting to start the profiler, I get the following message.
Cannot enable CPU profiling. ETW resources have been exhausted. Try shutting down other diagnostic tools (e.g. Sysinternals) or restarting to free these resources
I have tried restarting Visual Studio with no effect. Additionally, I do not have any other diagnostic tools running that I'm aware of, aside from sysmon. I found a 'solution' on Microsoft's site Troubleshoot profiling errors, which led me to execute the following command to add additional ETW loggers.
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\WMI" /v EtwMaxLoggers /t REG_DWORD /d 128
This increases the number of loggers to 128. This had no effect on the profiling error. I then attempted to further increase it to the maximum of 256 with no change in behavior. I find it hard to believe that sysmon would be using 256 ETW loggers.
I believe I can use xperf to diagnose the issue but I have no idea what I'm looking at or how to tell how many ETW loggers are in use and by what process.
Has anyone experienced this issue and have a solution or answer as to why it's happening?
After running into this a second time(!), I assembled the following Powershell command from all the different answers out there, which will list all ETW sessions with the system logger mode turned on (excluding one created by the deprecated methods in the StartTraceW docs):
Get-WmiObject -Class MSFT_EtwTraceSession -Namespace ROOT/Microsoft/Windows/EventTracingManagement | Get-EtwTraceSession | Where-Object { $_.LoggingModeNames -contains 'EVENT_TRACE_SYSTEM_LOGGER_MODE' }
When I was getting this problem, I got less than 8. However, when I stopped the Visual Studio debugger, I saw the count go down to 2. I already had CPU Usage turned on in diagnostic tools, and when starting the debugger again, I saw it create 3 system logger sessions.
At one point I had 4 in there, which if they were orphaned, would not have left enough room for the new set of 3 to start.
If you open Performance Monitor and go to Data Collector Sets > Event Trace Sessions, you can see all of them (not the logging flags unfortunately.) After manually stopping the DiagHubEtwSession.* ones and restarting the debugger, it magically started to work.
I wish I had something more specific to tell you for a solution, but the real money in this answer is the PS command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With