Technical Article

Calculate point in time DB Hit Ratios

,

Displays the hit ratio of the buffer, procedure and log caches. Does not check for div by zero as I am lazy. Tested on SS2k (any SP).

-- Hit Ratio of caches

select 	distinct counter_name,
	(select isnull(sum(convert(dec(15,0),B.cntr_value)),0) 
	from 	master..sysperfinfo as B (nolock) 
	where 	Lower(B.counter_name) like '%hit ratio%'
	and	A.counter_name = B.counter_name) as CurrHit,
	(select isnull(sum(convert(dec(15,0),B.cntr_value)),0) 
	from 	master..sysperfinfo as B (nolock) 
	where 	Lower(B.counter_name) like '%hit ratio base%'
	and	lower(B.counter_name) = (lower(ltrim(rtrim(A.counter_name))) + ' base')) as CurrBase,
	(select isnull(sum(convert(dec(15,0),B.cntr_value)),0) 
	from 	master..sysperfinfo as B (nolock) 
	where 	Lower(B.counter_name) like '%hit ratio%'
	and	A.counter_name = B.counter_name) / 
	(select isnull(sum(convert(dec(15,0),B.cntr_value)),0) 
	from 	master..sysperfinfo as B (nolock) 
	where 	Lower(B.counter_name) like '%hit ratio base%'
	and	lower(B.counter_name) = (lower(ltrim(rtrim(A.counter_name))) + ' base')) as HitRatio
from 	master..sysperfinfo as A (nolock) 
where 	Lower(A.counter_name) like '%hit ratio%'
and 	Lower(A.counter_name) not like '%hit ratio base%' 

-- Audit list as a double verification

select counter_name,isnull(sum(convert(dec(15,0),cntr_value)),0) as Value
from 	master..sysperfinfo (nolock) 
where 	Lower(counter_name) like '%hit ratio%'
or 	Lower(counter_name) like '%hit ratio base%' 
group by counter_name

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating