Home > Net >  How diagnosis dotnet process process consumes high CPU?
How diagnosis dotnet process process consumes high CPU?

Time:02-11

I have an ASP.NET Core process running in Kubernetes. Suddenly something went wrong and CPU usage jumped from 8% to 100% and settled at that level. Memory usage did not change so it looks like an infinite loop in a thread.

What instruments can I use to diagnose what is happening in the process?

What should I do to be able to diagnose such problems in the future?

CodePudding user response:

.net core support some command that let us diagnose CPU high or Memory problem.

first, install tools

dotnet tool install --global dotnet-trace
dotnet tool install --global dotnet-counters

then we can use dotnet-trace ps to get the process id that we want to trace.

then use dotnet-counters command we can see the process using resource situations.

dotnet-counters monitor -p 22884 --refresh-interval 1
  • -p: which process id you want to trace
  • --refresh-interval: How often to refresh the monitor screen from commandline window (unit is second)

if you want to only focus on cpu-usage you can try to add this parameter --counters System.Runtime[cpu-usage]

when we use the above command we will get a lot of Runtime information that can help us to diagnose from your process.

[System.Runtime]
% Time in GC since last GC (%)                          
Allocation Rate (B / 1 sec)                             
CPU Usage (%)                                           
Exception Count (Count / 1 sec)                         
GC Committed Bytes (MB)                                 
GC Fragmentation (%)                                    
GC Heap Size (MB)                                       
Gen 0 GC Count (Count / 1 sec)                          
Gen 0 Size (B)                                          
Gen 1 GC Count (Count / 1 sec)                          
Gen 1 Size (B)                                        
Gen 2 GC Count (Count / 1 sec)                        
Gen 2 Size (B)                                        
IL Bytes Jitted (B)                                   
LOH Size (B)                                           
Monitor Lock Contention Count (Count / 1 sec)           
Number of Active Timers                                 
Number of Assemblies Loaded                             
Number of Methods Jitted                                
POH (Pinned Object Heap) Size (B)                       
ThreadPool Completed Work Item Count (Count / 1 sec)    
ThreadPool Queue Length                                 
ThreadPool Thread Count                                 
Time spent in JIT (ms / 1 sec)                          
Working Set (MB)                                        

more detail you can see Debug high CPU usage in .NET Core & dotnet-counters

  • Related