1. dumpstackobjects (!dso)找到當前線程引用的全部的對象。 數組
2. !dumparray(!da) 有的對象是數組,好比 System.Object[]類型,此時要查看其內容應該使用 !dumparray命令 session
3. !objsize 不管是使用 !do仍是 !da ,若是用於查看數組類型的對象,看到的對象大小是諸如System.Object[]類型的對象大小而未包含其數組元素的大小。此時使用 !objsize 能夠查看到數組及其元素的大小。 線程
4. !dumpheap –stat 因爲!dumpheap例舉出的heap上的對象太多,可使用 -stat參數使得Debugger僅僅列出heap的統計數據,以及heap上的Method Table以及這個Method Table對應的類型。 3d
在得知了各個Method Table以後,可使用 !dumpheap –mt MTAddress來獲得全部與該Method Table聯繫的類型的對象實例的狀況(MT與類型一一對應,可是一個類型可能有多個實例) orm
5. Dumpheap應用實例: 對象
有一個Web Garden,客戶聲稱使用的是SQL Server來存儲的Cache,如今客戶遇到了performance問題,可是問題描述至關模糊。對於這種performance問題,首先想到的是cache的問題,可是客戶聲稱並無使用cache,爲了證明這個想法,先從Cache檢查起。 ip
!dumpheap –type System.Web.Caching.Cache –stat 這條命令的做用是列出heap的統計數據,以及全部Method table對應的type裏面包含有System.Web.Caching.Cache字符串的統計數據。結果以下: 字符串
0:050> !dumpheap -type System.Web.Caching.Cache -stat
------------------------------
Heap 0
total 665 objects
------------------------------
Heap 1
total 1084 objects
------------------------------
total 1749 objects
Statistics:
MT Count TotalSize Class Name
123056f8 1 12 System.Web.Caching.CacheKeyComparer
1230494c 1 12 System.Web.Caching.Cache
1230500c 1 24 System.Web.Caching.CacheMultiple
1230514c 1 32 System.Web.Caching.CacheMemoryStats
123053b4 1 36 System.Web.Caching.CacheMemoryTotalMemoryPressure
123059bc 2 40 System.Web.Caching.CacheUsage
12304bdc 1 48 System.Web.Caching.CacheCommon
123054f4 1 52 System.Web.Caching.CacheMemoryPrivateBytesPressure
12305874 2 64 System.Web.Caching.CacheExpires
12304e64 2 200 System.Web.Caching.CacheSingle
1255b594 85 1360 System.Web.Caching.CacheDependency+DepFileInfo
123046c4 40 1440 System.Web.Caching.CacheDependency
123042ec 47 1504 System.Web.Caching.CacheItemRemovedCallback
123063fc 832 16640 System.Web.Caching.CacheKey
12306820 732 52704 System.Web.Caching.CacheEntry
Total 1749 objects get
可見的確有一個Method Table對應的是System.Web.Caching.Cache類型。 hash
如今經過Method Table地址找到全部該Cache類型對應的對象。執行 !dumpheap –mt 1230494c,結果以下:
0:050> !dumpheap -mt 1230494c
------------------------------
Heap 0
Address MT Size
03392d20 1230494c 12
total 1 objects
------------------------------
Heap 1
Address MT Size
total 0 objects
------------------------------
total 1 objects
Statistics:
MT Count TotalSize Class Name
1230494c 1 12 System.Web.Caching.Cache
Total 1 objects
可見在heap 0上面的確有一個Cache對象,其地址爲 03392d20。爲了證明Cache比較嚴重,能夠查看該對象的實際大小。執行 !objsize 03392d20,結果以下:
0:050> !objsize 03392d20
sizeof(03392d20) = 266640828 ( 0xfe49dbc) bytes (System.Web.Caching.Cache)
可見該Cache的大小爲266640828,即266MB。
此時咱們試圖找到Cache的具體內容,這裏能夠從CacheEntry這個類來查找,所以執行 !dumpheap –mt 12306820
0:050> !dumpheap -mt 12306820
------------------------------
Heap 0
Address MT Size
033950bc 12306820 72
033a20d8 12306820 72
033ac79c 12306820 72
033da21c 12306820 72
033f04c4 12306820 72
03428ec8 12306820 72
0344dab4 12306820 72
03815d00 12306820 72
038265d8 12306820 72
....etc...
03af7010 12306820 72
03b291bc 12306820 72
03b2c674 12306820 72
03b6dca0 12306820 72
03b797dc 12306820 72
03b85318 12306820 72
03ba9150 12306820 72
03c258cc 12306820 72
03de43c8 12306820 72
03e160f8 12306820 72
total 382 objects
------------------------------
total 732 objects
能夠看到CacheEntry具備732個實例。此時執行 !do 03b2c674,查看其中一個對象的內容:
0:050> !do 03b2c674
Name: System.Web.Caching.CacheEntry
MethodTable: 12306820
EEClass: 122f6470
Size: 72(0x48) bytes
(C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll)
Fields:
MT Field Offset Type VT Attr Value Name
02c39310 4001327 4 System.String 0 instance 03b2c600 _key
0fb8f1f8 4001328 c System.Byte 0 instance 2 _bits
0fd3da00 4001329 8 System.Int32 0 instance -1314181915 _hashCode
02c36ca0 4001330 10 System.Object 0 instance 03b2c644 _value
120219d0 4001331 1c System.DateTime 1 instance 03b2c690 _utcCreated
120219d0 4001332 24 System.DateTime 1 instance 03b2c698 _utcExpires
1202af88 4001333 2c System.TimeSpan 1 instance 03b2c6a0 _slidingExpiration
0fb8f1f8 4001334 d System.Byte 0 instance 7 _expiresBucket
123062d8 4001335 34 ...g.ExpiresEntryRef 1 instance 03b2c6a8 _expiresEntryRef
0fb8f1f8 4001336 e System.Byte 0 instance 4294967295 _usageBucket
12306738 4001337 38 ...ing.UsageEntryRef 1 instance 03b2c6ac _usageEntryRef
120219d0 4001338 3c System.DateTime 1 instance 03b2c6b0 _utcLastUpdate
123046c4 4001339 14 ...g.CacheDependency 0 instance 00000000 _dependency
02c36ca0 400133a 18 System.Object 0 instance 033d8344 _onRemovedTargets
120219d0 400132d 1bc System.DateTime 1 shared static NoAbsoluteExpiration
>> Domain:Value 0019daf0:NotInit 11b42540:03395104 <<
1202af88 400132e 1c0 System.TimeSpan 1 shared static NoSlidingExpiration
>> Domain:Value 0019daf0:NotInit 11b42540:03395114 <<
1202af88 400132f 1c4 System.TimeSpan 1 shared static OneYear
>> Domain:Value 0019daf0:NotInit 11b42540:03395124 <<
此時咱們對這個對象裏面的Value值比較感興趣,將Value值拷貝出來,查看他指向的對象的具體內容是什麼。執行 !do 03e160c8:
0:000> !do 03e160c8
Name: System.Web.SessionState.InProcSessionState
MethodTable: 14dbad5c
EEClass: 14e43af8
Size: 48(0x30) bytes
(C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll)
Fields:
MT Field Offset Type VT Attr Value Name
1466c9d8 4001d89 4 ...ateItemCollection 0 instance 1a7f5438 _sessionItems
1292672c 4001d8a 8 ...ObjectsCollection 0 instance 00000000 _staticObjects
0fd3da00 4001d8b c System.Int32 0 instance 20 _timeout
120261c8 4001d8c 18 System.Boolean 0 instance 0 _locked
120219d0 4001d8d 1c System.DateTime 1 instance 03e160e4 _utcLockDate
0fd3da00 4001d8e 10 System.Int32 0 instance 1 _lockCookie
1202bf60 4001d8f 24 ...ReadWriteSpinLock 1 instance 03e160ec _spinLock
0fd3da00 4001d90 14 System.Int32 0 instance 0 _flags
此時能夠發現實際上使用的Session 存儲方式是InProc.