如何捕获的.NET处理的处理存储器转储时.NET不是在一个垃圾收集的中间(GC) [英] How to capture a process memory dump of a .NET process when .NET is not in the middle of a garbage collection (GC)

查看:121
本文介绍了如何捕获的.NET处理的处理存储器转储时.NET不是在一个垃圾收集的中间(GC)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当捕获转储文件,并(在WinDbg中如)分析它,我经常得到警告,该数据可能不准确,或命令可能无法访问,因为这个过程是在GC的中间时,转储文件收集。

When capturing a dump file and analyzing it (e.g. in WinDbg), I often get the warning that the data may not be accurate, or commands may not be accessible, because the process was in the middle of GC when the dump file was collected.

在做内存分析,我们经常这样做,因为对进程的内存高,内存压力高,我猜部队.NET频繁GC。

When doing memory analysis, we often do it because the memory on the process is high and memory pressure is high which I guess forces .NET to GC frequently.

我如何避免GC期间服用转储?有没有办法知道什么时候其安全地捕获转储文件?

How do I avoid taking dumps during a GC? Is there a way to know when its safe to capture the dump file?

推荐答案

我在这方面的专家,但我已经注意到,您可以使用.NET运行时的性能计数器,用于监控一些有趣的事情 - 其中之一是已经被垃圾收集器在分配它的最后收集的字节数。
的描述分配的字节/秒中的表现在指出在.NET Framework计数器:

I am no expert in this area but I've noticed that you can use the performance counters of the .NET runtime for monitoring some interesting things - one of them is the number of bytes that has been allocated by the garbage collector during it's last collection. The description of Allocated Bytes/second in Performance Counters in the .NET Framework states:

显示在垃圾收集堆中分配每秒字节数。此计数器在每个垃圾收集结束时更新,而不是在每次分配。此计数器不是一段时间的平均值;它显示的最后两个样本由样本间隔的持续时间除以所观察到的值之间的差

Displays the number of bytes per second allocated on the garbage collection heap. This counter is updated at the end of every garbage collection, not at each allocation. This counter is not an average over time; it displays the difference between the values observed in the last two samples divided by the duration of the sample interval.

据我的测试,如果您在性能监视器的更新间隔设置为1秒,并采取在指标好找分配的字节/秒,这似乎显示<$ C的值$ C> 0 收集完成后。所以,我认为,可以从该值的集合是否正在进行或不派生。

According to my tests, if you set the update interval of the performance monitor to 1 second and take a good look at the indicator for Allocated Bytes/second, it seems to show a value of 0 after a collection has completed. So I would assume, that you can derive from this value whether a collection is in progress or not.

我通过建立在VS 2015年的小应用程序,它具有检查了它能力,以显示是否有正在进行的垃圾收集。该指标的值是0不同,如果是这样的。

I checked it by building a small application in VS 2015 which has the ability to show whether there is a garbage collection in progress. The value of the indicator was different to 0 if it was the case.

更新(感谢托马斯)

有可能使用 ProcDump 监测性能计数器和以自动化方式创建的转储。
这样做是正确的方法: procdump ProcessName -s 1 -ma -pl\.NET CLR内存(ProcessName)\Allocated字节/秒1000 如果该值低于千这将触发转储。

It is possible to use ProcDump for monitoring the performance counter and create the dump in an automated fashion. The correct way of doing so would be: procdump ProcessName -s 1 -ma -pl "\.NET CLR Memory(ProcessName)\Allocated Bytes/second" 1000 which would trigger the dump if the value drops below one thousand.

这应该工作作为值只有零,如果没有垃圾收集回事。

This should work as the value is only zero if there is no garbage collection going on.

如果你没有在操作系统的英文版本操作系统,你将不得不找出性能计数器的正确的语言特定名称(可以通过观察来完成上面提供和切换到一个不同的语言有MSDN链路)。例如。德国名将
\.NET CLR-斯派克(ProcessName)\Zugeordnete字节/瑞典克朗。

If you are not operating on an english version of the operating system you will have to find out the correct language specific name of the performance counter (can be done by looking at the MSDN-link provided above and switching to a different language there). E.g. the german name would be "\.NET CLR-Speicher(ProcessName)\Zugeordnete Bytes/Sek.".

这篇关于如何捕获的.NET处理的处理存储器转储时.NET不是在一个垃圾收集的中间(GC)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆