简体   繁体   English

.net内存测量和性能分析

[英].net memory measuring and profiling

I understand there are many questions related to this, so I'll be very specific. 我了解与此相关的问题很多,因此我将非常具体。 I create Console application with two instructions. 我用两个指令创建控制台应用程序。 Create a List with some large capacity and fill it with sample data, and then clear that List or make it equal to null. 创建一个具有较大容量的列表,并用示例数据填充它,然后清除该列表或使其等于null。 What I want to know is if there is a way for me to know/measure/profile while debugging or not, if the actual memory used by the application after the list was cleared and null-ed is about the same as before the list was created and populated. 我想知道的是,是否有一种方法可以让我在调试时了解/测量/配置文件,清除列表并清空后应用程序使用的实际内存是否与列表被清除之前的内存大致相同。创建并填充。 I know for sure that the application has disposed of the information and the GC has finished collecting, but can I know for sure how much memory my application would consume after this? 我肯定知道应用程序已经处理了信息并且GC已经完成收集,但是我可以确定之后此应用程序将消耗多少内存吗? I understand that during the process of filling the list, a lot of memory is allocated and after it's been cleared that memory may become available to other process if it needs it, but is it possible to measure the real memory consumed by the application at the end? 我了解在填充列表的过程中会分配大量内存,并且在清除内存后,如果有需要,其他进程可能会使用该内存,但是有可能在应用程序中测量应用程序消耗的实际内存结束? Thanks 谢谢

Edit: OK, here is my real scenario and objective. 编辑:好的,这是我的真实情况和目标。 I work on a WPF application that works with large amounts of data read through USB device. 我在WPF应用程序上工作,该应用程序处理通过USB设备读取的大量数据。 At some point, the application allocates about 700+ MB of memory to store all the List data, which it parses, analyzes and then writes to the filesystem. 在某个时候,该应用程序分配了大约700+ MB的内存来存储所有List数据,它解析,分析然后将其写入文件系统。 When I write the data to the filesystem, I clear all the Lists and dispose all collections that previously held the large data, so I can do another data processing. 当我将数据写入文件系统时,我清除了所有列表,并处置了以前保存大数据的所有集合,因此可以进行其他数据处理。 I want to know that I won't run into performance issues or eventually use up all memory. 我想知道我不会遇到性能问题,也不会最终耗尽所有内存。 I'm fine with my program using a lot of memory, but I'm not fine with it using it all after few USB processings. 我的程序使用了很多内存,但我对此表示满意,但经过几次USB处理后,我却无法全部使用它。 How can I go around controlling this? 我该如何控制呢? Are memory or process profilers used in case like this? 在这种情况下是否使用内存或进程分析器? Simply using Task Manager, I see my application taking up 800 MB of memory, but after I clear the collections, the memory stays the same. 仅使用任务管理器,我看到我的应用程序占用了800 MB的内存,但是清除集合后,内存保持不变。 I understand this won't go down unless windows needs it, so I was wondering if I can know for sure that the memory is cleared and free to be used (by my application or windows) 我知道除非Windows需要,否则这种情况不会消失,因此我想知道是否可以确定内存已清除并可以免费使用(由我的应用程序或Windows使用)

Process Explorer will give you all the information you need. Process Explorer将为您提供所需的所有信息。 Specifically, you will probably be most interested in the "private bytes history" graph for your process. 具体来说,您可能会对过程的“专用字节历史记录”图最感兴趣。

Alternatively, it is possible to use Window's Performance Monitor to track your specific application. 另外,也可以使用Window的性能监视器来跟踪您的特定应用程序。 This should give identical information to Process Explorer, though it will let you write the actual numbers out to a separate file. 这应该为Process Explorer提供相同的信息,尽管它使您可以将实际数字写到单独的文件中。

进程浏览器窗口

(A picture because I can...) (一张照片因为我可以...)

It is very hard to measure "real memory" usage on Windows if you mean physical memory. 如果您指的是物理内存,则很难在Windows上衡量“实际内存”的使用情况。 Most likley you want something else like: 大多数likley您都想要其他类似的东西:

  1. Amount of memory allocated for the process (see Zooba's answer) 为该进程分配的内存量(请参阅Zooba的答案)
  2. Amount of Managed memory allocated - CLR Profiler, or any other profiler listed in this one - Best .NET memory and performance profiler? 分配的托管内存量-CLR探查器,或此一中列出的任何其他探查器- 最佳.NET内存和性能探查器?
  3. What Task Manager reports for your application 任务管理器为您的应用程序报告什么

Note that it is not necessary that after garbage collection is finished amount of memory allocated for your process (1) changes - GC may keep allocated memory for future managed allocations (this behavior is not specific to CLR for memory allcation - most memory allocators keep free blocks for later usage unless forced to release it by some means). 请注意,垃圾收集完成后,不必为进程分配的内存量(1)发生变化-GC可能会为将来的托管分配保留已分配的内存(此行为并非特定于CLR的内存分配-大多数内存分配器都保持空闲状态阻止以后使用,除非通过某种方式强制释放它)。 The http://blogs.msdn.com/b/maoni/ blog is excelent source for details on GC/memory. http://blogs.msdn.com/b/maoni/博客是有关GC /内存的详细信息的绝佳来源。

I personaly use SciTech Memory Profiler 我个人使用SciTech Memory Profiler
It has a real time option that you can use to see your memory usage. 它具有实时选项,可用于查看内存使用情况。 It has help me find a number of problems with leaking memory. 它有助于我发现内存泄漏的许多问题。

Try ANTS Profiler. 尝试ANTS Profiler。 Its not free but you can try the trial version. 它不是免费的,但您可以尝试使用试用版。


http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/ http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/

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

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