CLR Profile能够看到应用程序的内存堆栈情况并且能够查询垃圾回收机制的行为。利用CLR Profile可以确定你的代码哪儿分配了太多内存,从而导致垃圾回收机制的执行,哪些代码长时间的占有内存。不过CLR Profile不适合在生产环境下使用,因为如果用它,会使你的应用程序的性能下降10倍甚至100倍。

请从http://download.microsoft.com/download/4/4/2/442d67c7-a1c1-4884-9715-803a7b485b82/clr%20profiler.exe下载CLR Profile

CLR Profile 可以做:

  • 查看托管堆上的对象
  • 查看托管堆中存活的对象
  • 谁引用了托管堆上的对象
  • 垃圾回收机制在整个应用程序的生命周期内都做了什么
View Description
Histogram Allocated Types Gives you a high-level view of what object types are allocated (by allocation size) during the lifetime of your application. This view also shows those objects that are allocated in the large object heap (objects larger than 85 KB).

This view allows you to click parts of the graph so that you can see which methods allocated which objects.

Histogram Relocated Types Displays the objects that the garbage collector has moved because they have survived a garbage collection.
Objects By Address Provides a picture of what is on the managed heap at a given time.
Histogram By Age Allows you to see the lifetime of the objects on the managed heap.
Allocation Graph Graphically displays the call stack for how objects were allocated. You can use this view to:

-See the cost of each allocation by method.

-Isolate allocations that you were not expecting.

-View possible excessive allocations by a method.

Assembly, Module, Function, and Class Graph These four views are very similar. They allow you to see which methods pulled in which assemblies, functions, modules, or classes.
Heap Graph Shows you all of the objects in the managed heap, along with their connections.
Call Graph Lets you see which methods call which other methods and how frequently.

You can use this graph to get a feel for the cost of library calls and to determine how many calls are made to methods and which methods are called.

Time Line Displays what the garbage collector does over the lifetime of the application. Use this view to:

-Investigate the behavior of the garbage collector.

-Determine how many garbage collections occur at the three generations (Generation 0, 1, and 2) and how frequently they occur.

-Determine which objects survive garbage collection and are promoted to the next generation.

You can select time points or intervals and right-click to show who allocated memory in the interval.

Call Tree View Provides a text-based, chronological, hierarchical view of your application's execution. Use this view to:

-See what types are allocated and their size.

-See which assemblies are loaded as result of method calls.

-Analyze the use of finalizers, including the number of finalizers executed.

-Identify methods where Close or Dispose has not been implemented or called, thereby causing a bottleneck.

-Analyze allocations that you were not expecting.

启动CLR Profile

选择 Start Applcation 选择exe文件,然后等待应用程序执行完毕,然后就可以看到
我们选择exe文件的代码为:
[csharp] view plain copy  print?
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace ConsoleApplication2
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string str = "";
  12. DateTime begin = DateTime.Now;
  13. for (int i = 0; i < 10000; ++i)
  14. str += i;
  15. DateTime end = DateTime.Now;
  16. Console.WriteLine(begin - end);
  17. }
  18. }
  19. }

点击Histogram可以看到内存分配情况和对象构造情况,从下图可以看出string类型分配了300多M,30945 个实例对象。
点击 Allocation Graph 可以分析出,可以查看谁分配了对象占用了内存

分析另一个应用程序:
[csharp] view plain copy  print?
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Drawing;
  6. namespace ConsoleApplication2
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int start = Environment.TickCount;
  13. for (int i = 0; i < 100 * 1000; i++)
  14. {
  15. Brush b = new SolidBrush(Color.Black);    // Brush has a finalizer
  16. string s = new string(' ', i % 37);
  17. // Do something with the brush and the string.
  18. // For example, draw the string with this brush - omitted...
  19. }
  20. Console.WriteLine("Program ran for {0} seconds",
  21. 0.001 * (Environment.TickCount - start));
  22. }
  23. }
  24. }

这段代码分配了100000个SolidBrush和一些string,导致了总共分配了大约9M内存。通过以下(第一幅是总得,第二副是回收后的)两图比较可以看出最后剩余的内存很大部分是SolidBrush,大部分String对象都被回收。也就是说存活的对象都被提高到更高的代。



通过点击view-》Objects by Address 可以看到对象占用的内存空间。
通过点击view-》timeline 可以看到GC的行为

通过点击view->Call tree ,可以看到finalizers被调用的情况,

参考 :http://msdn.microsoft.com/en-us/library/ff650691.aspx

提高.net程序性能和稳定性-CLR Profile相关推荐

  1. 提高WPF程序性能的几条建议

    原文:提高WPF程序性能的几条建议 这篇博客将介绍一些提高WPF程序的建议(水平有限,如果建议有误,请指正.) 1. 加快WPF程序的启动速度: (1).减少需要显示的元素数量,去除不需要或者冗余的X ...

  2. system.gc 性能_使用这些先进的GC技术提高应用程序性能

    system.gc 性能 应用程序性能是我们关注的重点,垃圾收集优化是取得小而有意义的进步的好地方 自动化垃圾收集(与JIT HotSpot编译器一起)是JVM中最先进,最有价值的组件之一,但是许多开 ...

  3. 使用这些先进的GC技术提高应用程序性能

    应用程序性能是我们的首要考虑因素,垃圾收集优化是取得小而有意义的进步的好地方 自动化垃圾收集(与JIT HotSpot编译器一起)是JVM中最先进,最有价值的组件之一,但是许多开发人员和工程师对垃圾收 ...

  4. java项目怎样提高性能_Java程序员成长之路(如何提高Java程序性能?)

    1.尽量在合适的场合使用单例 使用单例可以减轻加载的负担,缩短加载的时间,提高加载的效率,但并不是所有地方都适用于单例,简单来说,单例主要适用于以下三个方面 第一,控制资源的使用,通过线程同步来控制资 ...

  5. php开启opcache,启用OPCache提高PHP程序性能的方法

    说明 PHP 5.5+版本以上的,可以使用PHP自带的opcache开启性能加速(默认是关闭的).对于PHP 5.5以下版本的,需要使用APC加速,这里不说明,可以自行上网搜索PHP APC加速的方法 ...

  6. php5.5 opcache,PHP5.5+启用OPCache提高php程序性能的方法

    opcache是Zend Optimizer编译到php环境中的名字,意思即优化缓存.Zend OPcache 通过将 PHP 脚本预编译的字节码存储到共享内存中来提升 PHP 的性能, 存储预编译字 ...

  7. abap性能优化——利用凭证的number ranger提高abap程序性能

    当我们的程序需要搜索某些凭证的时侯,常常会涉及到比较庞大的数据表,比如BSEG, MSEG, VBRP等等,如果这时又无法获取凭证号码等一些关键字段的值,那么程序必然会消耗非常多的资源.这种情况下,下 ...

  8. javascript使用缓存计算来提高应用程序性能

    2019独角兽企业重金招聘Python工程师标准>>> <!doctype html> <html xmlns="http://www.w3.org/19 ...

  9. Asp.net性能优化-提高ASP.Net应用程序性能的十大方法

    一.返回多个数据集 检查你的访问数据库的代码,看是否存在着要返回多次的请求.每次往返降低了你的应用程序的每秒能够响应请求的次数.通过在单个数据库请求中返回多个结果集,可以减少与数据库通信的时间,使你的 ...

最新文章

  1. Python Qt GUI设计:QTabWidget、QStackedWidget和QDockWidget容器控件类(提升篇—2)
  2. 阿里云联合中国信通院发布《云计算开放应用架构》标准
  3. 课堂作业:返回一个二维整数组中最大子数组的和
  4. Confluence 6 workbox 通知包含了什么
  5. 【数据结构与算法】共享栈的Java实现
  6. Java static静态关键字 有啥用
  7. uushare.com 增加了小组(群)功能
  8. mysql 密码输入正确,登陆失败的原因
  9. umi 导航菜单的空白页问题
  10. 用DEM制作通用三维地形模型
  11. jquery 抓取微博_使用jQuery和RegexJavaScript进行客户端网络抓取
  12. 篡改计算机网络,基于TCP协议的网络数据实时篡改.doc
  13. 时辰和属相、当令经的对应关系
  14. win7系统提示计算机内存不足,win7电脑提示计算机内存不足怎么办
  15. Python - 使用python-opencv裁剪原视频为与视频高同宽的视频
  16. 苹果id界面无法打开解决方法「iphone技巧」
  17. Lind.DDD.Manage项目核心技术分享
  18. 长三角如何成为人才净流入最高的城市群?
  19. 如何成为一名专业的云渗透测试工程师
  20. 蓝牙4.0温度计android设计,蓝牙体温计方案,听说体温计还能被记录?

热门文章

  1. 谈谈现在的状况,顺便给以后找工作的和我一样的毕业生说说
  2. 如何破解Red Hat Enterprise 4的root密码(救援有密码)
  3. 学C++走游戏方向,是不是非常艰难自找苦吃?
  4. 为什么基类的析构函数要声明成虚函数
  5. 利用正高Dolphin智能广告监测系统做好违法广告监测
  6. 解析Jquery取得iframe中元素的几种方法
  7. Linux内核源代码情景分析-fork()
  8. ajax 同步和异步的区别|已迁移
  9. WinForm 应用程序中开启新的进程及控制
  10. 《代码敲不队》第五次作业:项目需求分析改进与系统设计