sp_sysmon {'begin_sample' | {{'end_sample' | '<interval>'}[, section]}}
[, <applmon>=
{'appl_only' | 'appl_and_login' | 'no_appl' | 'noclear' | 'clear'}
[, <filter>={<cache_wizard_filter_value> | 'noclear' | 'clear'}
[, <dumpcounters>={'y' | 'n' | 'noclear' | 'clear' | NULL}
[, <option>={'noclear' | 'clear' | NULL}]]]]
begin_sample
开始采样。如果指定了 begin_sample,则不能指定部分。
end_sample
结束采样并打印报告。
<interval>
指定采样的时间范围。必须采用 HH:MM:SS 格式,例如“00:20:00”。
<section></p>
<p>是 sp_sysmon 打印的某一部分的缩写。报告部分的值和对应名称如下:</p>
<p><ul><li>appmgmt – 应用程序管理</p>
<p></li></ul><ul><li>cache wizard – 高速缓存向导</p>
<p></li></ul><ul><li>dcache – 数据高速缓存管理</p>
<p></li></ul><ul><li>diskio – 磁盘 I/O 管理</p>
<p></li></ul><ul><li>esp – ESP 管理</p>
<p></li></ul><ul><li>housekeeper – 管家任务活动</p>
<p></li></ul><ul><li>ndexmgmt – 索引管理</p>
<p></li></ul><ul><li>kernel – 内核利用率</p>
<p></li></ul><ul><li>locks – 锁管理</p>
<p></li></ul><ul><li>memory – 内存管理</p>
<p></li></ul><ul><li>mdcache – 元数据高速缓存管理</p>
<p></li></ul><ul><li>monaccess – 对执行 SQL 的监控访问</p>
<p></li></ul><ul><li>netio – 网络 I/O 管理</p>
<p></li></ul><ul><li>parallel – 并行查询管理</p>
<p></li></ul><ul><li>pcache – 过程高速缓存管理</p>
<p></li></ul><ul><li>recovery – 恢复管理</p>
<p></li></ul><ul><li>repagent – RepAgent</p>
<p></li></ul><ul><li>nvcache – NV 高速缓存</p>
<p></li></ul><ul><li>taskmgmt – 任务管理</p>
<p></li></ul><ul><li>xactmgmt – 事务管理</p>
<p></li></ul><ul><li>xactsum – 事务配置文件</p>
<p></li></ul><ul><li>wpm – 工作进程管理</p>
<p>您还可以使用 sp_monitorconfig 获取 sp_sysmon mdcache 报告中提供的大多数信息。</p>
<p></p>
<p>指定是打印应用程序详细信息、应用程序和登录名详细信息,还是不打印应用程序详细信息。缺省设置为省略应用程序详细信息。有效值及其报告的信息为:</p>
<p></li></ul><ul><li>appl_only – 按应用程序名称输出的 CPU、I/O、优先级更改和资源限制违反信息。</p>
<p></li></ul><ul><li>appl_and_login – 按应用程序名和登录名输出的 CPU、I/O、优先级更改和资源限制违反信息。</p>
<p></li></ul><ul><li>no_appl – 跳过报告的“按应用程序”或“按登录名”部分。这是缺省设置。</p>
<p>只有在打印完整报告并且为 指定了 appmgmt 时此参数才有效。</p>
<p>noclear | clear</p>
<p>指定是否清除监控计数器:</p>
<p></li></ul><ul><li>clear – 显式清除监控计数器。</p>
<p></li></ul><ul><li>noclear – sp_sysmon 不清除监控计数器。noclear 参数的首要作用是提供向后兼容性(sp_sysmon 的早期版本在缺省情况下会清除监控计数器)。</p>
<p>> 注意</br></p>
<p>仅当在 sp_sysmon 中指定了采样间隔时,才能使用 noclear 参数。如果指定了 begin_sample 或 end_sample,则不能使用 noclear。</p>
<p>缺省情况下,sp_sysmon 不清除用作报告源数据的监控计数器。如果清除计数器时有其它应用程序或 sp_sysmon 报告的实例正在运行,则清除计数器可能会导致它们报告的数据无效。</p>
<p></p>
<p>是一种 varchar 数据类型,用来为报告中包括的高速缓存指定模式。</p>
<p>例如,如果将它指定为缺省数据高速缓存,报告将只包含有关缺省数据高速缓存的信息。如果将它指定为 emp%,输出将包括名称与此模式匹配的所有高速缓存的有关信息。如果未指定任何值,输出将包含所有高速缓存,且首先显示缺省数据高速缓存,然后按字母顺序显示其它高速缓存。</p>
<p>'cache wizard'</p>
<p>可帮助监控和配置数据高速缓存以获得最佳性能。</p>
<p></p>
<p>在返回请求的报告部分之后,将 master..sysmonitors 表的内容(包含所有监控计数器的名称和值)作为一个结果集返回。</p>
<p>
在 5 分钟后只打印 sp_sysmon 报告的“磁盘管理”部分:
sp_sysmon "00:05:00", diskio
开始采样,执行过程和查询,结束采样,然后只打印报告的“数据高速缓存”部分:
sp_sysmon begin_sample
go
execute proc1
go
execute proc2
go
select sum(total_sales) from titles
go
sp_sysmon end_sample, dcache
go
打印完整报告,并且包括各个登录名的应用程序和登录名详细信息:
sp_sysmon "00:05:00", @applmon = appl_and_login
不清除计数器的报告用法:
sp_sysmon "00:01:00", kernel, noclear
也可以使用:
sp_sysmon "00:01:00", noclear
使用高速缓存向导打印报告:
sp_sysmon '00:00:30', 'cache wizard'
</h1>
<h1>Cache Wizard</h1>
------------------
default data cache
------------------Run Size : 100.00 Mb Usage% : 2.86
LR/sec : 41.10 PR/sec : 22.57 Hit%: 45.09
Cache Partitions: 4 Spinlock Contention%: 0.00
<h2>Buffer Pool Information</h2>
IO Size Wash Size Run Size APF% LR/sec PR/sec Hit% APF-Eff% Usage%
------- ---------- ----------- ------ -------- -------- ------ -------- ------
4 Kb 3276 Kb 16.00 Mb 10.00 0.47 0.13 71.43 n/a 0.20
2 Kb 17200 Kb 84.00 Mb 10.00 40.63 22.43 44.79 n/a 3.37
(1 row affected)
Object Statistics
-----------------------------------------------------------------------------
Object LR/sec PR/sec Hit% Obj_Cached% Cache_Occp%
------------------------------- ------- ------- ------ ----------- -----------
empdb.dbo.t1 0.57 0.30 47.06 56.25 0.02
empdb.dbo.t2 0.30 0.30 0.00 56.25 0.02
empdb.dbo.t3 0.30 0.30 0.00 56.25 0.02
empdb.dbo.t4 0.30 0.30 0.00 56.25 0.02
empdb.dbo.t5 0.30 0.30 0.00 56.25 0.02
empdb.dbo.t6 0.30 0.30 0.00 56.25 0.02
empdb.dbo.t8 0.30 0.30 0.00 56.25 0.02
empdb.dbo.t7 0.57 0.20 64.71 62.50 0.02
tempdb.dbo.tempcachedobjstats 3.63 0.00 100.00 50.00 0.01
tempdb.dbo.tempobjstats 0.47 0.00 100.00 25.00 0.00
Object Obj Size Size in Cache
------------------------------- ----------- -------------
empdb.dbo.t1 32 Kb 18 Kb
empdb.dbo.t2 32 Kb 18 Kb
empdb.dbo.t3 32 Kb 18 Kb
empdb.dbo.t4 32 Kb 18 Kb
empdb.dbo.t5 32 Kb 18 Kb
empdb.dbo.t6 32 Kb 18 Kb
empdb.dbo.t8 32 Kb 18 Kb
empdb.dbo.t7 32 Kb 20 Kb
tempdb.dbo.tempcachedobjstats 16 Kb 8 Kb
tempdb.dbo.tempobjstats 16 Kb 4 Kb
---------
company_cache
---------
Run Size : 1.00 Mb Usage% : 0.39
LR/sec : 0.07 PR/sec : 0.07 Hit%: 0.00
Cache Partitions: 1 Spinlock Contention%: 0.00
<h2>Buffer Pool Information</h2>
IO Size Wash Size Run Size APF% LR/sec PR/sec Hit% APF-Eff% Usage%
------- ---------- ----------- ------ -------- -------- ------ -------- ------
2 Kb 204 Kb 1.00 Mb 10.00 0.07 0.07 0.00 n/a 0.39
<h2>Object Statistics</h2>
Object LR/sec PR/sec Hit% Obj_Cached% Cache_Occp%
-------------------- ------- ------- ------ ----------- -----------
empdb.dbo.history 0.07 0.07 0.00 25.00 0.39
Object Obj Size Size in Cache
-------------------- ----------- -------------
empdb.dbo.history 16 Kb 4 Kb
-------------
<h2>companydb_cache</h2>
Run Size : 5.00 Mb Usage% : 100.00
LR/sec : 380.97 PR/sec : 56.67 Hit%: 85.13
Cache Partitions: 1 Spinlock Contention%: 0.00
<h2>Buffer Pool Information</h2>
IO Size Wash Size Run Size APF% LR/sec PR/sec Hit% APF-Eff% Usage%
------- ---------- ----------- ------ -------- -------- ------ -------- ------
2 Kb 1024 Kb 5.00 Mb 10.00 380.97 56.67 85.13 98.42 100.00
<h2>Object Statistics</h2>
Object LR/sec PR/sec Hit% Obj_Cached% Cache_Occp%
----------------------------- ------- ------- ------ ----------- -----------
company_db.dbo.emp_projects 41.07 22.80 44.48 19.64 9.45
company_db.dbo.dept_det 93.03 20.67 77.79 99.08 54.53
company_db.dbo.emp_perf 116.70 2.63 97.74 97.77 34.18
company_db.dbo.dept_locs 0.43 0.17 61.54 50.00 0.16
Object Obj Size Size in Cache
----------------------------- ----------- -------------
company_db.dbo.emp_projects 2464 Kb 484 Kb
company_db.dbo.dept_det 2818 Kb 2792 Kb
company_db.dbo.emp_perf 1790 Kb 1750 Kb
company_db.dbo.dept_locs 16 Kb 8 Kb
<h2>TUNING RECOMMENDATIONS</h2>
Usage% for 'default data cache' is low (< 5%)
Usage% for 4k buffer pool in cache:default data cache is low (< 5%)
Usage% for 2k buffer pool in cache:default data cache is low (< 5%)
Usage% for 'company_cache' is low (< 5%)
Usage% for 2k buffer pool in cache:company_cache is low (< 5%)
Consider adding a large I/O pool for 'companydb_cache'
20 秒后仅打印 sp_sysmon 报告的非易变高速缓存部分:
sp_sysmon "00:00:20", 'nvcache'
</h1>
<h2>NV Cache Management</h2>
<h2>Cache Statistics Summary (All NV Caches)</h2>
per sec per xact count % of total
------------ ------------ ---------- ----------
Cache Search Summary
Total Cache Hits 96.9 226.1 2035 46.7 %
Total Cache Misses 110.7 258.2 2324 53.3 %
------------------------- ------------ ------------ ----------
Total Cache Searches 207.6 484.3 4359
Cache Turnover
Buffers Grabbed 110.1 257.0 2313 n/a
<h2> Buffers Grabbed Dirty 0.0 0.0 0 0.0 %</h2>
Cache: nvcache
per sec per xact count % of total
------------------------- ------------ ------------ ---------- ----------
Spinlock Contention n/a n/a n/a 0.0 %
Utilization n/a n/a n/a 100.0 %
Cache Searches
Cache Hits 96.9 226.1 2035 46.7 %
Cache Misses 110.7 258.2 2324 53.3 %
------------------------- ------------ ------------ ----------
Total Cache Searches 207.6 484.3 4359
Cache Turnover
Buffers Grabbed 207.6 484.3 4359 n/a
Buffers Grabbed Dirty 0.0 0.0 0 0.0 %
Cache Device Reads
Cache Device Writes
</li></ul><ul><li>Consider increase size for this cache.
</li></ul><ul><li>Consider making NV cache lazy cleaner less aggressive.
</li></ul><ul><li>Or consider ratio of sizes of NV cache and
<h2> main memory caches associated with it</h2>
Cache: nvcache2
per sec per xact count % of total
------------------------- ------------ ------------ ---------- ----------
Spinlock Contention n/a n/a n/a 0.0 %
Utilization n/a n/a n/a 0.0 %
Cache Searches
Total Cache Searches 0.0 0.0 0 n/a
------------------------- ------------ ------------ ----------
Total Cache Searches 0.0 0.0 0
Cache Turnover
Buffers Grabbed 0.0 0.0 0 n/a
Cache Device Reads
Cache Device Writes
</li></ul><ul><li>Consider making NV cache lazy cleaner more aggressive.
</li></ul><ul><li>Or consider ratio of sizes of NV cache and
main memory caches associated with it
</li></ul><ul><li>Consider making NV cache lazy cleaner less aggressive.
</li></ul><ul><li>Or consider ratio of sizes of NV cache and
main memory caches associated with it
(return status = 0)
使用 sp_sysmon 时,还存在一些其它注意事项:
的有效值。</p>
<p></li></ul><ul><li>如果以批处理模式使用 sp_sysmon(使用 begin_sample 和 end_sample),执行之间的时间间隔必须至少为一秒。可以使用 waitfor delay "00:00:01"` 来延长批处理的执行时间。