简体   繁体   English

确定堆上对象的对象分配发生的位置

[英]Determining where object allocations for objects on the heap occurred

Is there any tool such that it can get a heap dump from a running application and determine/group objects by where in source code they were created? 是否有任何工具可以从正在运行的应用程序中获取堆转储并根据源代码的创建位置确定/分组对象?

With no changes to source code and ideally something free. 没有更改源代码,理想情况下是免费的。

What about .NET Memory Profiler from ANTS for example. 那么来自ANTS的.NET Memory Profiler呢? Maybe CLR Profiler. 也许CLR Profiler。

The information is not available if you create a memory dump. 如果创建内存转储,则无法使用该信息。 In order to gather this, you have to monitor the process as it is running. 为了收集它,您必须在进程运行时监视该进程。 You could launch the application via WinDbg and set breakpoints on all the constructors you're interested in (hopefully you don't want to look at each and every object). 您可以通过WinDbg启动应用程序并在您感兴趣的所有构造函数上设置断点(希望您不希望查看每个对象)。

If you create the breakpoint, so it dumps the stack you will have the point of creation for the object. 如果创建断点,那么它会转储堆栈,您将拥有该对象的创建点。 However, keep in mind that the objects may move around during GC, which will make parring objects with stacks difficult (or even impossible in some cases). 但是,请记住,在GC期间对象可能会移动,这会使堆叠对象变得困难(在某些情况下甚至是不可能的)。

Since your question is tagged with performance and profiling, I gather that you want to reduce memory allocations. 由于您的问题标记有性能和分析,因此我认为您希望减少内存分配。 Why not just look at the numbers of objects created (or possibly look at the largest objects created) by looking at the heap. 为什么不通过查看堆来查看创建的对象的数量(或者可能查看创建的最大对象)。 Then go through the source code and figure out where such instances are created. 然后浏览源代码并找出创建此类实例的位置。

As others suggested memory profilers, Memprofiler is definitely the most advanced one (I've tried all existing .NET profilers). 正如其他人建议的内存分析器, Memprofiler绝对是最先进的(我已经尝试过所有现有的.NET分析器)。 It has a 14 day trial. 它有14天的试用期。

You need a .NET memory profiler. 您需要一个.NET内存分析器。 These tools allow you to follow the object graphs on the garbage collected heap and can be very useful in identifying the sources of memory leaks. 这些工具允许您遵循垃圾收集堆上的对象图,并且在识别内存泄漏源方面非常有用。 While they may not necessarily tell you the method where an object was created they will tell which instances of which classes are holding on to the objects and allow you to take differences of snap shots of the gc heap. 虽然它们可能不一定会告诉您创建对象的方法,但它们会告诉哪些类占用了哪些类,并允许您对gc堆的快照进行区分。 They don't require modifications to source code. 它们不需要修改源代码。 You may want to have a look at What Are Some Good .NET Profilers? 您可能想看看什么是一些好的.NET Profilers?

Our QA teams use http://www.jetbrains.com/profiler/ for this kind of thing here when we run into bottlenecks. 当我们遇到瓶颈时,我们的QA团队会在这里使用http://www.jetbrains.com/profiler/来处理此类问题。 I'm pretty sure it will give you a list of allocations by method call. 我很确定它会通过方法调用给你一个分配列表。 I'll go install it and check :) 我会安装它并检查:)

Good old windbg + sos + pdb will make the dumping. 好旧的windbg + sos + pdb将进行倾销。 As for the "where in source code they were created" part - is impossible without instrumentation or injection. 至于“源代码在哪里创建”部分 - 没有仪器或注入是不可能的。

The SOS Debugging Extension SOS调试扩展

How to use : http://msdn.microsoft.com/en-us/library/yy6d2sxs.aspx 使用方法: http//msdn.microsoft.com/en-us/library/yy6d2sxs.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM