Memory Dump 分析器
Visual Studio 2013 新功能 Memory Dump 分析器
TechEd2013 发现新功能
12月5日和6日,在国家会议中心参加了微软的 TechEd2013 技术大会,了解了很多微软所提供的软件新功能和新技术。





在上面的图中描述了在 Visual Studio 2013 中提供了新的功能 .NET Memory Dump Analysis,在具体的 Visual Studio 2013 新功能介绍的 Session 看到了实际的演示。当时感觉这个新功能对开发人员太有帮助了,因为使用 WinDbg 进行内存泄漏等问题排查总是一种痛苦。如果能在 Visual Studio 中包含类似的功能就再好不过了。
准备尝鲜 .NET Memory Dump Analysis
回到家,自然是想使用 Visual Studio 2013 直接上手实际体验下。
在创造了一个 Dump 文件之后,使用 Visual Studio 2013 直接打开,

结果发现,在 Actions 处少一个 "Debug Managed Memory" 按钮。

它应该长这个样子才对:

Google 之后发现原来我使用的是 Visual Studio 2013 Premium 版本,而该功能只有在 Visual Studio 2013 Ultimate 版本中才支持。

公司的 MSDN 订阅选的是 Premium ,比较了下与 Ultimate 的区别,价格果真差的很大。

此时,我选择了安装个 Windows 7 SP1 虚拟机,并安装 Visual Studio 2013 Ultimate 的试用版。
遭遇 Visual Studio 2013 的 Known Issue
显然,安装上 Visual Studio 2013 Ultimate 之后,再打开 Dump 文件,就可以成功看到 Actions 中的 "Debug Managed Memory" 按钮。
点击该按钮,等待 Heap View 显示。
什么?白屏?一万只马飘过。

这可真是郁闷,折腾了半天都没反应。
于是只能问 Google 了,显然,新的功能暂时没什么人用,也搜不到什么有用的讨论。
终于,当搜索关键词修改为 “Visual Studio 2013 Debug Managed Memory is not work” 时,有用的信息出现了。

打开一看,这居然是一个 Visual Studio 2013 Known Issue,基本就是要求安装 IE10 或以上的版本才能使用此功能。

解决办法,当然就是安装新版 IE,立马下载安装 IE11。新装的虚拟机中的 Windows 7 默认的还是 IE8 。
使用 Dump 文件比较功能
这一次,成功看到了 Heap View。

在 Compare to 中选择一个之前的 Dump 文件作为对比,即可查看两个文件时间的内存变化。

Inclusive Size
在 Heap View 中,有一列为 Inclusive Size (Bytes)。

其包含所显示对象引用的所有对象内存占用的总和。下面的图标展示了内存占用大小的计算过程。

|
Object Type |
Count |
Size (Bytes) |
Inclusive Size (Bytes) |
|
Customer |
1 |
100 |
400 |
|
Address |
1 |
50 |
200 |
|
String |
2 |
150 |
150 |
|
Byte[] |
1 |
100 |
100 |
Address 对象的 Inclusive Size = Address (50 bytes) + String (50 bytes) + Byte[] (100 bytes) = 200 bytes
Customer 对象的 Inclusive Size = Address Inclusive Size (200 bytes) + String (100 bytes) + Customer (100 bytes) = 400 bytes
Inclusive Size Diff
在使用 Dump 比较功能后,显示的列中会出现 "Inclusive Size Diff",用来描述在两个 Dump 文件采集的时间点时,Inclusive Size 的变化。

View Setting
在 Dump 比较的界面中,我们可以看到 View Settings 选项。

- Just My Code :顾名思义,仅显示用户代码。
- Collapse Small Objects :隐藏小对象。
这里需要描述下,小对象隐藏后的 Inclusive Size 的计算方式。
实际上,会将被隐藏的小对象的大小累加到父对象上。
仍然使用上面的图例进行计算。

我们假设 String 和 Byte[] 被隐藏,在隐藏小对象后,

|
Object Type |
Count |
Size (Bytes) |
Inclusive Size (Bytes) |
|
Customer |
1 |
200 |
400 |
|
Address |
1 |
200 |
200 |
Paths To Root View
点击 Heap View 列表中的某一个 Object Type,在 Paths To Root 中会通过级联方式显示对象的引用关系。
这用于显示,是哪个对象引用导致该对象没有被垃圾回收。

References View
References View 用于显示,这个对象都引用了哪些对象。

测试用代码

1 using System;
2 using System.Collections.Concurrent;
3 using System.Collections.Generic;
4 using System.Threading;
5
6 namespace TestDebugMemoryDumpFile
7 {
8 class Program
9 {
10 static ConcurrentQueue<Tree> _leakedTrees = new ConcurrentQueue<Tree>();
11
12 static void Main(string[] args)
13 {
14 List<string> fruits = new List<string>() // 6 items
15 {
16 "Apple", "Orange", "Pear", "Banana", "Peach", "Hawthorn",
17 };
18
19 Random random = new Random();
20 while (true)
21 {
22 string fruitName = fruits[random.Next(0, 5)];
23 Tree fruitTree = new Tree(fruitName);
24 BuildFruitTree(fruitTree, 100); // 100M
25 _leakedTrees.Enqueue(fruitTree);
26
27 Console.WriteLine("Added [{0}] on [{1}]...",
28 fruitTree.Name,
29 DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.ffffff"));
30
31 Thread.Sleep(TimeSpan.FromSeconds(5));
32 }
33 }
34
35 private static void BuildFruitTree(Tree fruitTree, int leafCount)
36 {
37 Console.WriteLine("Building [{0}] on [{1}]...",
38 fruitTree.Name,
39 DateTime.Now.ToString(@"yyyy-MM-dd HH:mm:ss.ffffff"));
40
41 for (int i = 0; i < leafCount; i++) // size M
42 {
43 Leaf<byte[]> leaf = new Leaf<byte[]>(Guid.NewGuid())
44 {
45 Content = CreateContentSizeOfOneMegabyte()
46 };
47 fruitTree.Leaves.Add(leaf);
48 }
49 }
50
51 private static byte[] CreateContentSizeOfOneMegabyte()
52 {
53 byte[] content = new byte[1024 * 1024]; // 1 M
54 for (int j = 0; j < content.Length; j++)
55 {
56 content[j] = 127;
57 }
58 return content;
59 }
60 }
61
62 internal class Tree
63 {
64 public Tree(string name)
65 {
66 Name = name;
67 Leaves = new List<Leaf<byte[]>>();
68 }
69
70 public string Name { get; private set; }
71 public List<Leaf<byte[]>> Leaves { get; private set; }
72 }
73
74 internal class Leaf<T>
75 {
76 public Leaf(Guid id)
77 {
78 Id = id;
79 }
80
81 public Guid Id { get; private set; }
82 public T Content { get; set; }
83 }
84 }

参考资料
Memory Dump 分析器的更多相关文章
- Visual Studio 2013 新功能 Memory Dump 分析器
本文为 Dennis Gao 原创技术文章,发表于博客园博客,未经作者本人允许禁止任何形式的转载. TechEd2013 发现新功能 12月5日和6日,在国家会议中心参加了微软的 TechEd2013 ...
- Responder Pro new version could analyze Win10 memory dump
My friend John acquired a memory dump from Windows 10, but he could analyze this memory dump with an ...
- qualcomm memory dump 抓取方法
Memory dump是系统出现crash时常用的分析故障原因的方法,qualcomm 各子系统运行时,为方便debug,都会开辟ram log和debug variable用于保存各系统运行信息及健 ...
- How do I find what queries were executing in a SQL memory dump?-----stack
https://blogs.msdn.microsoft.com/askjay/2010/10/03/how-do-i-find-what-queries-were-executing-in-a-s ...
- 利用 Memory Dump Diagnostic for Java (MDD4J) 分析内存管理问题
利用 Memory Dump Diagnostic for Java (MDD4J) 分析内存管理问题(2) 启动和理解 MDD4J[size=1.0625]为了充分理解如何使用 MDD4J,您需要了 ...
- memory dump and CLR Inside Out
MSDN Magazine: CLR Inside Out https://msdn.microsoft.com/en-us/magazine/cc501040.aspx CLR Inside Out ...
- Android memory dump
1.读取指定pid和内存地址的字符: #include <stdlib.h> #include <stdio.h> #include <string.h> #inc ...
- .NET Memory Profiler 查看内存使用情况
1 简介 .Net Memory Profiler(以下简称Profiler):专门针对于.NET程序,功能最全的内存分析工具,最大的特点是具有内存动态分析(Automatic Memory Anal ...
- SharePoint运行状况分析器有关磁盘空间不足的警告
对于负责管理SharePoint内部部署安装的SharePoint管理员,SharePoint Health Analyzer是一款出色的工具.此功能不仅有助于解决服务器故障和服务失败的问题,还提供了 ...
随机推荐
- springMVC3得知(五岁以下儿童)--MultiActionController
Spring为了提供一个多动作控制器,您可以使用它的几个行动统一到一个控制器,这可以放在一起功能. 多动作控制器存在在一个单独的包中--org.springframework.web.mvc.mult ...
- VisualStudio 怎么使用Visual Leak Detector
VisualStudio 怎么使用Visual Leak Detector 那么在Windows下有什么好的内存泄漏检测工具呢?微软提供Visual Studio开发工具本身没有什么太好的内存泄漏检测 ...
- ASP.NET MVC+EF框架+EasyUI实现权限管理系列(3)-面向接口的编程
原文:ASP.NET MVC+EF框架+EasyUI实现权限管理系列(3)-面向接口的编程 ASP.NET MVC+EF框架+EasyUI实现权限管系列 (开篇) (1)框架搭建 (2):数据 ...
- HDFS副本放置策略和机架感知
副本放置策略 的副本放置策略的基本思想是: 第一block在复制和client哪里node于(假设client它不是群集的范围内,则这第一个node是随机选取的.当然系统会尝试不选择哪些太满或者太忙的 ...
- 【转】Appium 服务器端从启动到case完成的活动分析
原文地址:http://blog.csdn.net/zhubaitian/article/details/39474151 此文的目的主要是通过分析Appium Server打印出来的log,加深对A ...
- C#创建和初始化类
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace C_编辑 ...
- gpu显存(全局内存)在使用时数据对齐的问题
全局存储器,即普通的显存,整个网格中的随意线程都能读写全局存储器的任何位置. 存取延时为400-600 clock cycles 很easy成为性能瓶颈. 訪问显存时,读取和存储必须对齐,宽度为4B ...
- JS判断Array数组中是否包含指定元素
1.调用方式: var arr=["a","b"]; alert(arr.in_array("a")) 2.JS判断数组是否包含指定元素方法 ...
- 浅谈JavaScript性能
最近在JavaScript性能方面有所感悟,把我的经验分给大家: 说到JavaScript,就不得不说它的代码的运行速度—— 在我初学JavaScript的时候,只是觉得它是一个很强大的脚本.渐渐的, ...
- 使用AndroidStudio快速开发教程
关于AndroidStudio的使用 参考:http://www.codes51.com/article/detail_98914.html 1.对于开发环境的通性:编写 调试 视图 一般的开发 ...