SQL Profiler is a very powerful tool. It is fine to read the analysis principles in order. However, if you want to analyze complicated situations, you need more things.
Here we will introduce a method to operate Profiler Trace like an SQL table, so that you can use select to view the information you are interested in.
To do this, you can use a built-in function named fn_trace_gettable.
select * from fn_trace_gettable('c:\MyTraceFile.trc', default)
The first parameter is obviously the path of the profiler trace on the disk.
The second parameter indicates the number of files to be read. The default value is-1, meaning all files must be read.
Although you can use this function to read the trace file each time, there is a better way, that is, to import the data in the file into a table and then query the table, this is much faster than reading files every time.
The method is as follows:
select IDENTITY(BIGINT, 1, 1) AS RowNumber, * into MyTraceTablefrom fn_trace_gettable('D:\MyProfilerTrace.trc', default)where 1 = 0 --just create the table without any data
Once you have created a table definition, the next step is to insert data into the table.
insert into MyTraceTableselect * from fn_trace_gettable('D:\MyProfilerTrace.trc', default)
Add
==============
After reading the table, you can try to run the following statement to select the statement or stored procedure with the longest running time.
select top 50 T.RowNumber, TE.name,T.duration DurationMicroSeconds,T.TextData from MyTraceTable T join sys.trace_events TE ON T.EventClass = TE.trace_event_idwhere eventclass <> 15order by T.durationdesc
Here you can see the row number. use SQL profiler to open the trace file, you can locate the context of the problem statement.
References:
Reading a SQL Profiler Trace file
Http://sql2005ted.blogspot.com/2009/06/reading-sql-profiler-trace-file.html