Monthly Archives: September 2008

使用!dump系列命令剖析ArrayList的内容

参考:!dumpheap –stat explained… (debugging .net leaks) by Tess 例程如下:[STAThread] static void Main(string[] args) {    ArrayList list = new ArrayList();    list.Add("ItemA");    list.Add("ItemB");    Console.ReadLine(); } 运行程序,然后用WinDBG attach进程(F6) 加载SOS .loadby sos mscorwks 0:003>!dupmheap -stattotal 2212 objectsStatistics:      MT    Count    TotalSize … Continue reading

Posted in Debug | Leave a comment

在Visual Studio中使用SOS

1.在要调试的Project的属性页上进行设置,选中"Enable unmanaged debugging"功能 否则加载SOS时会报错:".load sos’: not available while Managed only debugging." 2.在"Immediate Window"(Ctrl+Alt+I)中执行命令"!load sos"或".load sos"加载SOS Immediate Window支持很多用于Debug的高级命令,比如显示线程,调用栈的信息,见MSDN http://msdn.microsoft.com/en-us/library/f177hahy.aspx

Posted in Debug | Leave a comment

OutOfMemoryExceptions while remoting very large datasets(From Tess) 笔记

http://blogs.msdn.com/tess/archive/2008/09/02/outofmemoryexceptions-while-remoting-very-large-datasets.aspx 如果需要在Process和App Domain之间传递对象,需要把对象序列化后才能传递,序列化操作即耗费CPU又耗费内存,如果对象过于庞大和复杂,比如dataset,还会导致OOM(out of memory),此时用~* e !clrstack 会看到…0454f408 651eadee System.Data.DataSet.SerializeDataSet(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext, System.Data.SerializationFormat) 传递dataset的做法值得检讨:为什么要传递dataset?是否仅dataset中的一小部分需要传递?是否使用64bit系统可以解决问题? 通过Debug一个server-client结构的remoting例程来说明问题: 用windbg attach到remoting server进程上,执行 .loadby sos mscorwks 加载SOS, 显示mscorwks!WKS::gc_heap::allocate_large_object()的地址:0:008> x mscorwks!WKS*allocate_large*79ef212d mscorwks!WKS::gc_heap::allocate_large_object = <no type information> 在mscorwks!WKS::gc_heap::allocate_large_object()上加断点:0:008> bp 79ef212d  " ?@ebx;!clrstack;g"在每次为大对象分配内存时都可以得到要分配的内存的大小,本例中,为了XML序列化100M的对象,使用了1G的内存! 解决方案:使用ds.RemotingFormat = SerializationFormat.Binary;

Posted in Debug | Leave a comment

APS.NET Memory Issue (From Tess) 笔记

http://blogs.msdn.com/tess/archive/2008/09/12/asp-net-memory-issues-high-memory-usage-with-ajaxpro.aspx 1. !dumpheap -state 显示托管堆中的内容,发现有大量的UI相关的对象和数据相关的对象.猜测: 如果有User control被放入session或cache或使用static对象,这个User control就一直不会被垃圾回收,而它的Parent属性引用的web page,以及web page上的其他control和control中的数据对象也都会一直存在,直到那个罪魁user control被移出session或cache. 2. !dumpheap -type *aspx 把托管堆中的所有web page对象显示出来,有1230个,正常情况下,每个页面对应一个正在执行的请求.用~* e !clrstack 列出所有线程的callstacks.没有一个正在处理请求.这说明page应该被回收而没有被回收. 3. !gcroot 6d67cb28 显示地址为6d67cb28的page对象的引用(或root)信息Root:  0a629ac8(System.Object[])-> 02777208(System.Collections.Specialized.HybridDictionary)-> 06946578(System.Collections.Hashtable)-> 3eac4e0c(System.Collections.Hashtable+bucket[])-> 6d67cb28(ASP.default_aspx)问题:System.Collections.Hashtable+bucket[]是什么对象?和System.Collections.Hashtable有什么关系?用reflector查看System.Collections.Hashtable的代码,得知bucket是Hashtable的嵌套类型private struct bucket {     public object key;     public object val; … Continue reading

Posted in Debug | Leave a comment

WinDBG 使用技巧2则

1. 为dmp文件添加Context menu,方便加载(From Tess)用reg文件生成context menu启动debugger,加载dmp文件,并传入一个包含参数的txt文件来进行必要的设置,比如:设置sympath,加载SOS,执行下文中的.cmdtree Reg 文件 Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\.dmp]@="Debugger.Dump" [HKEY_CLASSES_ROOT\Debugger.Dump] [HKEY_CLASSES_ROOT\Debugger.Dump\DefaultIcon]@="c:\\debuggers\\cdb.exe" [HKEY_CLASSES_ROOT\Debugger.Dump\Shell] [HKEY_CLASSES_ROOT\Debugger.Dump\Shell\Debug_Without_Remote]@="Debug This Dump" [HKEY_CLASSES_ROOT\Debugger.Dump\Shell\Debug_Without_Remote\Command]@="\"C:\\debuggers\\windbg\" -z \"%1\" -c \"$<c:\\debuggers\\commands.txt\"" [HKEY_CLASSES_ROOT\Debugger.Dump\Shell\Debug_With_Remote70]@="Debug this Dump With Remote:70" [HKEY_CLASSES_ROOT\Debugger.Dump\Shell\Debug_With_Remote70\Command]@="\"C:\\debuggers\\windbg\" -server tcp:port=70 -z \"%1\" -c \"$<c:\\debuggers\\commands.txt\"" -z DumpFile 指定要加载的dump文件-c 在debugger启动时,执行一些命令,和$< … Continue reading

Posted in Debug | Leave a comment

下载狂

找书比读完这本书更吸引我,立贴为证. 寻找   Framework Design guidelines 2ed                 搞到 2008.09.16 O’Reilly.C.Sharp.3.0.Design.Patterns.pdf 差   O’Reilly.Programming.C.Sharp.3.0.5th.Edition.pdf     OReilly.Programming.dot.NET.3.5.Aug.2008.pdf               2008.09.17 Pro JavaScript Techniques.pdf     Framework Design Guidelines … Continue reading

Posted in Books | Leave a comment

Debug the Process Memory Usage

1. Windows 内存管理    Reserve: The virtual memory space reserved for the application but no disk or main memory pages have been used.    Commit: The physical memory for which space has been reserved on the disk paging file    Working … Continue reading

Posted in Debug | 1 Comment

Windows Task Manager 有关Process的信息

Image Name: 进程的名字 PID : 进程ID CPU Usage: 从前一次更新算起, 当前进程使用的CPU时间的百分比 CPU Time: 从进程开始运行算起,共使用了多少秒的CPU时间Memory Usage: In Task Manager, the current working set of a process, in kilobytes.                The current working set is the number of pages currently resident in memory. On … Continue reading

Posted in Debug | Leave a comment