Blocked Process Report

捕获超过10秒的堵塞,开启了trace之后,所有的超过10秒的堵塞会被记录下来(重复记录,例如scenario1的堵塞被记录下来, 过了10秒之后, scenario1会被再次记录

sp_configure 
'show advanced options',1 ; 
GO
 
RECONFIGURE
GO
 sp_configure 
'blocked process threshold',10 ; 
GO
 
RECONFIGURE
 
go
 
select *from sys.traces
 
 
declare @rc int 
 
declare @TraceID int
  
declare @maxfilesize bigint
  
set @maxfilesize = 50 
  
exec @rc = sp_trace_create 
  
@TraceID output, 2, N'd:\trace\BlockedProcessTrace'
  
@maxfilesizeNULL 
--137解释:
--
 Blocked Process Report Occurs when a process has been blocked for more than a specified amount of time. Does not --include system processes or processes that are waiting on non deadlock-detectable --resources. Use sp_configure to configure the threshold and frequency at which reports are generated.
 
 
if(@rc =0)
 
begin
  
declare @on bit
  
set @on = 1
  
exec sp_trace_setevent @TraceID13715@on
  
exec sp_trace_setevent @TraceID1371@on
  
exec sp_trace_setevent @TraceID13713@on
 
end
   
--exec sp_trace_setfilter   2,35,0,0,N'testdb'

exec sp_trace_setstatus 21--start the trace
  
select *from sysprocesses where blocked<>0
select cast(TextData as XML) , SPID, EndTime, 
   Duration
/1000/1000from
    fn_trace_gettable(N
'd:\trace\BlockedProcessTrace.trc'default)
    
where eventclass = 137
--exec sp_trace_setstatus 2, 0--stop the trace
--
exec sp_trace_setstatus 2, 2--remove the trace definition but remain the trace file

 

posted on 2010-08-02 11:11  stswordman  阅读(360)  评论(0编辑  收藏  举报