Whenever a customer has an issue with slowness, we request a trace file to help us figure out where the problem may be. The trace allows us to see which procs are called most often, and which are taking up the most time.
I used to import the trace file into a temporary table, then run my own queries on the file to pinpoint issues. While that works well, it requires me to make additional copies of the customer's data which all has to be tracked due to in-house security rules. Since I don't like having to do excessive paperwork, I found a way to easily read in the data from where it sits rather than importing it into SQL server:
Select ObjectName
, substring(DatabaseName, 1, 18) as dbname
, 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 cumexpense
from fn_trace_gettable ('C:\Temp\MyTraceFile.trc', DEFAULT)
group by ObjectName, substring(DatabaseName, 1, 18)
order by avgreads desc
The above query orders the items in the trace by average number of reads. Next, order the list by Average CPU then Average Duration. Any queries that are consistently at the top of the list are the first candidates for tuning.
I've also used the following to zero in on data regarding specific procs:
select DatabaseName, ObjectName, TextData, CPU, Reads, Writes
from fn_trace_gettable ('C:\Temp\MyTraceFile.trc', DEFAULT)
where ObjectName ='MyStoredProc' or ObjectName='YourStoredProc'
Have fun analyzing your trace files.
Subscribe to:
Post Comments (Atom)
Deep Dives, Best Practices, and What's Coming in Microsoft Fabric - FabCon 2026 - Part 2
FabCon 2026 — Recap Part 2 Deep Dives, Best Practices, and What's Coming in Microsoft Fabric My notes from Fabcon sessions covering De...
-
I've been playing with PowerBI recently, and have discovered their Gallery of Custom Visuals . I decided to try some to see what they ...
-
I've been playing with PowerBI recently and have discovered their Gallery of Custom Visuals . I decided to try a few to see what they d...
-
After working on a rather long and tedious programming project using Cursor AI, I asked Cursor to clean up the code directory and consolidat...
No comments:
Post a Comment