使用dotnet-dump 查找 .net core 3.0 占用CPU 100%的原因解析

本文介绍了如何在.NETCore程序中使用dotnet-dump工具收集和分析CPU占用过高的情况,包括创建测试程序、安装工具、捕获dump并查看线程信息,以及使用clrthreads和dumpobj进行深入分析。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 这篇文章介绍了3个工具

•dotnet-counters: 实时统计runtime的状况, 包括 CPU、内存、GC、异常等
•dotnet-trace: 类似性能探测器
•dotnet-dump: 程序崩溃时使用该工具

  这次使用的是dotnet-dump, 即使程序没有崩溃, 也可以dump程序快照, 用于分析

实验环境

ubuntu-16.04.5-desktop-amd64
SDK 3.0.100-preview6-012264

1. 新建一个简单Console程序(只能是 .net core 3.0的程序, 不支持 .net core 2.2), 模拟CPU占用100%的情况

1

2

mkdir NetCoreDumpTest && cd NetCoreDumpTest

dotnet new console

编辑Program.cs

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

namespace NetCoreDumpTest

{

 using System;

 using System.Threading.Tasks;

 class Program

 {

  static void Main(string[] args)

  {

   Task.Factory.StartNew(() => PrintNumber("Print", 5));

   Console.WriteLine("Press any key to exit.");

   Console.ReadKey();

  }

  static void PrintNumber(string message, int startNumber)

  {

   var number = startNumber;

   while (true)

    Console.WriteLine($"{message} {number++}");

  }

 }

}

2. 安装dotnet-dump

dotnet tool install --global dotnet-dump --version 1.0.4-preview6.19311.1

提示

If you are using bash, you can add it to your profile by running the following command:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值