gpt4 book ai didi

c# - 如何诊断 dotnet 进程消耗高 CPU 的情况?

转载 作者:行者123 更新时间:2023-12-03 08:10:16 25 4
gpt4 key购买 nike

我有一个在 Kubernetes 中运行的 ASP.NET Core 进程。突然出现问题,CPU 使用率从 8% 跃升至 100%,并稳定在该水平。内存使用情况没有改变,因此看起来像是线程中的无限循环。

我可以使用哪些工具来诊断流程中发生的情况?

我应该怎么做才能在将来诊断此类问题?

最佳答案

.net core 支持一些命令,让我们可以诊断 CPU 高或内存问题。

首先,安装工具

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

然后我们可以使用dotnet-trace ps来获取我们想要跟踪的进程ID。

然后使用dotnet-counters命令我们可以看到进程使用资源的情况。

dotnet-counters monitor -p 22884 --refresh-interval 1
  • -p:您要跟踪的进程 ID
  • --refresh-interval:从命令行窗口刷新监视器屏幕的频率(单位为秒)

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

当我们使用上述命令时,我们将获得大量运行时信息,可以帮助我们从您的进程中进行诊断。

[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)

更多详情可以查看Debug high CPU usage in .NET Core & dotnet-counters

关于c# - 如何诊断 dotnet 进程消耗高 CPU 的情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71052597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com