Technical Article

Trace Analysis script

,

Trace files are wonderful because they provide extensive information on what the SQL server is doing during the time that they are running. The main difficulty that one has when reading a trace file using SQL Server Profiler is that the data cannot be sorted or aggregated within that UI. This query allows me to pull in the data from any trace file, then aggregate the trace data by objectName to find average values for CPU Use, Reads, Writes, and duration for each stored procedure. By altering the ORDER BY clause, the worst performing items bubble up to the top of the list.

Before using this script, please be sure to change the trace file name from C:\Temp\MyTrace.trc to the correct name and location for your trace file.

Happy Tuning!

select ObjectName, substring(DatabaseName, 1, 18) as databaseName
, AVG(cpu) as CPUuse
, AVG(reads) as avgReads
, AVG(writes) as avgWrites
, COUNT(EndTime) as Instances
, AVG(duration) as avgDuration
, COUNT(EndTime) * AVG(reads) as CumulativeExpense
from fn_trace_gettable ('C:\temp\MyTrace.trc', DEFAULT) -- change trace file name
group by ObjectName,  substring(DatabaseName, 1, 18)
order by avgReads desc

Rate

3 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

3 (1)

You rated this post out of 5. Change rating