跟踪.NET 4.0诱导GC的来源 [英] Tracking down the source of .NET 4.0 Induced GC

查看:118
本文介绍了跟踪.NET 4.0诱导GC的来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是PerfMonitor.exe( http://bcl.codeplex.com/wikipage? title = PerfMonitor )来追踪.NET 4.0应用程序的一些.NET性能问题,该应用程序使用一些第三方库,其中一些是本地代码。



当我运行Perfmonitor GCTime报告时,它会列出各个GC并以几种方式对它们进行分类。报告中的一列称为原因。有些GC的Reason =Induced,其他人的Reason =SmallAlloc。

我假设标记为SmallAlloc的GC是由定期分配引起的(New Object ))和标记为诱导的GC是由对System.GC.Collect的调用引起的。请让我知道,如果你认为我做了一个不正确的假设。



我试图找到调用System.GC.Collect的代码,但我已经不成功。使用MSVS 2010 Professional,我在System.GC.Collect中设置了一个断点,并通过编写一个包含对System.GC.Collect的调用的简单测试函数来确保此断点工作正常。然而,我正在调整的应用程序在该断点处没有中断,这使得我相信没有任何代码会调用System.GC.Collect。



我在想也许有通过直接调用mscorwks.dll中的本地函数来诱发GC的本机代码,并绕过System.GC.Collect。我看到System.GC.Collect调用了mscorwks中的JitHelpers.cpp中的_Collect。有没有办法在该函数中设置断点?

解决方案

看来你已经推断GC.Collect()不是你的问题,但作为参考,我已经成功在GC.Collect中,当我从诱导GC计数器中看到有明确诱发的GC发生时,在GC.Collect中添加了断点。



您可以将断点位置设置为System .GC。收集并放弃它。使用这种策略,我有时可以成功设置Framework断点,有时不会。我不知道是否因为方法/属性调用被优化或者其他原因。但它总是值得一试。您可能必须执行诸如在工具 - >选项 - >调试部分中禁用Just My Code。


I'm using PerfMonitor.exe ( http://bcl.codeplex.com/wikipage?title=PerfMonitor ) to track down some .NET performance issues of a .NET 4.0 app that uses some third party libraries some of which are native code.

When I run the Perfmonitor GCTime report, it lists the individual GC's and classifies them in several ways. One column in the report is called "Reason". Some GC's have Reason="Induced" and others have Reason="SmallAlloc".

I assume that the GCs labelled "SmallAlloc" are caused by regular allocation (New Object()) and GCs labelled "Induced" are caused by a call to "System.GC.Collect". Please let me know if you think I've made an incorrect assumption.

I'm trying to find the code that is calling System.GC.Collect but I've been unsuccessful. Using MSVS 2010 Professional, I set up a breakpoint in System.GC.Collect, and made sure that this breakpoint works by writing a simple test function that contains a call to System.GC.Collect. However, my app that I'm tuning does not break at that breakpoint which makes me believe that none of the code calls System.GC.Collect.

I'm thinking maybe there is native code that induces the GC by calling a native function in mscorwks.dll directly and bypasses System.GC.Collect. I see that System.GC.Collect calls _Collect in JitHelpers.cpp which is in mscorwks. Is there a way to set a breakpoint in that function?

解决方案

It seems you've deduced that GC.Collect() is not your issue here, but for reference, I have succeeded in putting breakpoints in GC.Collect in the past when I could see from the Induced GC counter that there were definitely induced GCs happening.

You can set the breakpoint location to System.GC.Collect and give it a go. Using this tactic, I'm sometimes successful in setting Framework breakpoints, sometimes not. I don't know if it's because methods/property calls are optimised out, or some other reason. But it's always worth a try. You may have to do things such as disabling "Just My Code" in the Tools->Options->Debug section.

这篇关于跟踪.NET 4.0诱导GC的来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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