Thursday, April 1, 2010

Procedure Cache Information with high paln cache size

/*
 To list entries from procedure cache with high cache plan size
 with parameter @noofrounds  = 0 all entries are returned
 with parameter @noofrounds  > 0 returns entries if  particular cache
 is removed from  previous and all round counts which indicates internal procedure cache pressure

Usage : 
exec .sp_lib_CacheInfo  0
exec .sp_lib_CacheInfo  1
*/






CREATE PROCEDURE dbo.sp_lib_CacheInfo @noofrounds int = 0

AS
BEGIN

 SET NOCOUNT ON
 SELECT DISTINCT cc.cache_address, cc.name, cc.type,
 cc.single_pages_kb + cc.multi_pages_kb AS total_kb,
 cc.single_pages_in_use_kb + cc.multi_pages_in_use_kb AS total_in_use_kb,
 cc.entries_count,
 cc.entries_in_use_count,
 ch.removed_all_rounds_count,
 ch.removed_last_round_count
FROM sys.dm_os_memory_cache_counters cc
 INNER JOIN sys.dm_os_memory_cache_clock_hands ch
 ON (cc.cache_address = ch.cache_address)
-- information only for moving hands caches
WHERE
(
               @noofrounds  = 0 
              OR
              ( @noofrounds  > 0
              AND
              ch.rounds_count > 0
              AND ch.removed_all_rounds_count > 0
              )
)
ORDER BY total_kb DESC

END

GO

1 comment:

Anonymous said...

Genial post and this fill someone in on helped me alot in my college assignement. Thanks you on your information.