This article defines views that can be used to view activity data contained in a trace file that is created by the job described in the following article in the Microsoft Knowledge Base:
283696
(http://support.microsoft.com/kb/283696/EN-US/
)
INF: Job to Monitor SQL Server 2000 Performance and Activity
NOTE: This article discusses a DBCC command (DBCC PSS) that is unsupported, and may cause unexpected behavior. Microsoft cannot guarantee that you can solve problems that result from the incorrect use of this DBCC command. Use this DBCC command at your own risk. This DBCC command may not be available in future versions of SQL Server. For a list of the supported DBCC commands, see the "DBCC" topic in the Transact-SQL Reference section of SQL Server Books Online.
Before you create these views, the trace file must be imported into a SQL Server 2000 table named ActivityTrace. The stored procedure defined below, trace_gettable, imports the data from the trace file to a SQL Server 2000 table.
Note that you must create the trace_events table from the script below before creating the v_eventcount and v_SumDuration views because both of these views use the trace_events table.
Use the views defined below to display activity data as noted:
The v_eventcount view lists the count for each event class.
The v_SumDuration view lists the sum of the trace duration column for each event class.
The v_sysprocesses view lists the results from the sysprocesses table for the system process IDs (SPIDs) involved in blocking.
The v_syslockinfo view lists the results from the syslockinfo table for the SPIDs involved in blocking.
The v_dbccpss view lists the dbcc pss results for blocking SPIDs.
The syntax for the trace_gettable stored procedure is as follows:
trace_gettable, @tablename, @tracefile, @numfiles
The arguments have the following datatypes and defaults:
@tablename sysname = N'ActivityTrace'
This argument is the name of the table where the trace data will be copied. If the table does not exist, the stored procedure will create it. Otherwise, the table will be truncated before importing the data. Note that the other stored procedures in this article expect the table name to be ActivityTrace.
@tracefile nvarchar(245) = 'none'
This argument is the name of the trace file. If no trace file is specified, the C:\ActivityTrace.ini file is read to find the name of the trace file.
@numfiles nvarchar(3) = '1'
This argument specifies the number of rollover files to be read, including the initial file specified in filename. number_files is int. A value of '1' indicates one file is read, and a value of '-1' indicates that all files are read.
CREATE view v_eventcount as
select top 100 percent
e.EventName, a.EventClass
,count(*) as [Number of Events]
,min(StartTime) as [Time of First Event]
,max(StartTime) as [Time of Last Event]
,datediff(mi,min(StartTime),max(StartTime)) as [minutes]
from ActivityTrace a left join trace_events e
on a.EventClass = e.EventClass
group by e.Eventname, a.EventClass
order by [Number of Events] desc
CREATE view v_SumDuration as
SELECT TOP 100 PERCENT
e.EventName
,COUNT(*) AS [Frequency]
,SUM(a.Duration) AS [Sum of Duration]
,SUBSTRING(a.TextData, 1, 60) AS [Substring from Text Data]
FROM dbo.ActivityTrace a LEFT OUTER JOIN
dbo.trace_events e
ON a.EventClass = e.EventClass
GROUP BY SUBSTRING(a.TextData, 1, 60), e.EventName
HAVING (SUM(a.Duration) > 0)
ORDER BY SUM(a.Duration) DESC
CREATE view v_sysprocesses as
select RowNumber,StartTime
,TextData
,cast(substring(BinaryData,1,2) as smallint) as [spid]
,cast(substring(BinaryData,3,2) as smallint) as [kpid]
,cast(substring(BinaryData,5,2) as smallint) as [blocked]
,cast(substring(BinaryData,7,2) as binary(2)) as [waittype]
,cast(substring(BinaryData,9,4) as int) as [waittime]
,cast(substring(BinaryData,13,64) as nchar(32)) as [lastwaittype]
,cast(substring(BinaryData,77,512) as nchar(256)) as [waitresource]
,cast(substring(BinaryData,589,2) as smallint) as [dbid]
,cast(substring(BinaryData,591,2) as smallint) as [uid]
,cast(substring(BinaryData,593,4) as int) as [cpu]
,cast(substring(BinaryData,597,8) as bigint) as [physical_io]
,cast(substring(BinaryData,605,4) as int) as [memusage]
,cast(substring(BinaryData,609,8) as datetime) as [login_time]
,cast(substring(BinaryData,617,8) as datetime) as [last_batch]
,cast(substring(BinaryData,625,2) as smallint) as [ecid]
,cast(substring(BinaryData,627,2) as smallint) as [open_tran]
,cast(substring(BinaryData,629,60) as nchar(30)) as [status]
,cast(substring(BinaryData,689,86) as binary(86)) as [sid]
,cast(substring(BinaryData,775,256) as nchar(128)) as [hostname]
,cast(substring(BinaryData,1031,256) as nchar(128)) as [program_name]
,cast(substring(BinaryData,1287,16) as nchar(8)) as [hostprocess]
,cast(substring(BinaryData,1303,32) as nchar(16)) as [cmd]
,cast(substring(BinaryData,1335,256) as nchar(128)) as [nt_domain]
,cast(substring(BinaryData,1591,256) as nchar(128)) as [nt_username]
,cast(substring(BinaryData,1847,24) as nchar(12)) as [net_address]
,cast(substring(BinaryData,1871,24) as nchar(12)) as [net_library]
,cast(substring(BinaryData,1895,256) as nchar(128)) as [loginame]
,cast(substring(BinaryData,2151,128) as binary(128)) as [context_info]
from ActivityTrace
where eventclass = 82 and substring(TextData,1,8) = N'blocking'
CREATE view v_syslockinfo as
select RowNumber,StartTime
,TextData
,cast(substring(BinaryData,2279,64) as nchar(32)) as [rsc_text]
,cast(substring(BinaryData,2343,16) as binary(16)) as [rsc_bin]
,cast(substring(BinaryData,2359,16) as binary(16)) as [rsc_valblk]
,cast(substring(BinaryData,2375,2) as smallint) as [rsc_dbid]
,cast(substring(BinaryData,2377,2) as smallint) as [rsc_indid]
,cast(substring(BinaryData,2379,4) as int) as [rsc_objid]
,cast(substring(BinaryData,2383,1) as tinyint) as [rsc_type]
,cast(substring(BinaryData,2384,1) as tinyint) as [rsc_flag]
,cast(substring(BinaryData,2385,1) as tinyint) as [req_mode]
,cast(substring(BinaryData,2386,1) as tinyint) as [req_status]
,cast(substring(BinaryData,2387,2) as smallint) as [req_cnt]
,cast(substring(BinaryData,2389,2) as smallint) as [req_cryrefcnt]
,cast(substring(BinaryData,2391,4) as int) as [req_lifetime]
,cast(substring(BinaryData,2395,4) as int) as [req_spid]
,cast(substring(BinaryData,2399,4) as int) as [req_ecid]
,cast(substring(BinaryData,2403,2) as smallint) as [req_ownertype]
,cast(substring(BinaryData,2405,8) as bigint) as [req_transactionID]
,cast(substring(BinaryData,2413,16) as uniqueidentifier) as [req_transactionUOW]
from ActivityTrace
where eventclass = 82 and substring(TextData,1,8) = N'blocking'
CREATE view v_dbccpss as
select top 100 percent RowNumber, TextData as dbccpss
from ActivityTrace with (nolock)
where eventclass = 82
and (substring(TextData,1,8) != N'blocking'
or substring(TextData,1,8) != N'no block')
order by RowNumber