Search code examples
c#multithreadingperformancevisual-studioperfmon

How do I identify the thread in application that takes 100% CPU usage in PerfMon?


enter image description here

enter image description here

Trying to fine-tune/optimize my C# application. Been running PerfMon and I consistently get a spike of 100% on some operations. I can get the thread instance number from PerfMon but from Visual Studio 2015's thread window when debugging, how do I know which thread is the corresponding one?

Or am I going about it the wrong way? I want to find out the identity of the thread that's spiking in CPU usage from time to time. Thanks in advance SO!


Solution

  • Disclaimer: I work on the profiler in Visual Studio

    I would attach to the process using the Visual Studio debugger and then bring up the diagnostic tools window (since you stated you are using VS 2015). If you switch to the CPU Usage tab you can enable CPU profiling, repro your issue, then break the process. This will cause the profiler to analyze the collected trace. Finally you can hit the filter drop down which will allow you to filter the call tree by thread. We also list the CPU usage by thread ID so you can use this to figure out what thread was doing the work and then what was it doing.