创建测试程序,有如下代码:
class Program
{
static List<string> strList = new List<string>();
static void Main(string[] args)
{
Console.WriteLine("123");
//strList.Add("fake");
//strList.Add("张三");
//Console.ReadLine();
Test();
Test1();
Thread.Sleep(5000);
var a = dic["jkldsjfksjfldkf_10"];
Console.WriteLine(a);
while (true)
{
Thread.Sleep(1000);
}
}
public static void Test()
{
Thread thread = new Thread(() =>
{
while (true)
{
double sum = 0;
for (int i = 0; i < 1000000; i++)
{
if (sum >= 10000000)
sum = 0;
sum += 0;
}
}
});
thread.Start();
}
private static Dictionary<string, string> dic = new Dictionary<string, string>();
public static void Test1()
{
Thread thread = new Thread(() =>
{
for (int i = 0; i < 10000; i++)
{
dic.Add($"jkldsjfksjfldkf_{i}", $"AAABBBCCC123456789_{Guid.NewGuid()}_{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ffff")}");
}
Console.WriteLine("dic.add end");
});
thread.Start();
}
}
Sysbol File Path 设置文件符号文件(.pdb)路径,例如:E:\WebApplication\Orchard.Test\bin\Debug
Source File Path 设置源文件(.cs)路径,例如:E:\WebApplication\Orchard.Test
Open Crash Dump 打开Dump文件(.dump),可以通过任务管理器创建转存文件
分析CPU占用过高问题
使用!runaway 命令可以看到各线程的CPU占用总时间
.load C:\Windows\Microsoft.NET\Framework64\v4.0.30319\SOS.dll 加载sos扩展
~5 s 切换到5线程
!clrstack 查看堆栈
分析内存占用过高问题
!eeheap -gc 查看托管堆的总信息
!dumpheap -min 200 -stat 获取占用堆内存的各对象的统计信息
!dumpheap -type System.Collections.Generic.Dictionary -min 200 看各Dictionary占用堆内存的详细信息
!gcroot 0000000012c72c00 < Dictionary对象地址> 看对象引用关系
在使用 !clrstack 命令时可以会出现以下问题:
Failed to load data access DLL, 0x80004005
Verify that 1) you have a recent build of the debugger (6.2.14 or newer)
2) the file mscordacwks.dll that matches your version of clr.dll is
in the version directory or on the symbol path
3) or, if you are debugging a dump file, verify that the file
mscordacwks_<arch>_<arch>_<version>.dll is on your symbol path.
4) you are debugging on supported cross platform architecture as
the dump file. For example, an ARM dump file must be debugged
on an X86 or an ARM machine; an AMD64 dump file must be
debugged on an AMD64 machine.
You can also run the debugger command .cordll to control the debugger's
load of mscordacwks.dll. .cordll -ve -u -l will do a verbose reload.
If that succeeds, the SOS command should work on retry.
If you are debugging a minidump, you need to make sure that your executable
path is pointing to clr.dll as well.
这时由于当前系统mscordacwks.dll版本和dump来源系统版本不同导致的。
由于只是学习,我这里直接通过修改程序目标框架为 .NET Framework 4问题就解决了。