Use the SQL Server Profiler (in the tool menu in SSMS) to create a trace that logs these events:
RPC:Completed SP:Completed SP:StmtCompleted SQL:BatchCompleted SQL:StmtCompleted
You can start with a standard trace template and crop it. You did not indicate whether it was for a specific database or the entire server, if it was for specific Db, enable the DatabaseID column and set a filter for your database ( SELECT DB_ID('dbname') ). Verify that the Reads data column is enabled for each event. Set the trace to write to the file. If you leave this trace unattended in the background, it is recommended to set the maximum trace file size to 500 MB or 1 GB if you have a lot of space (it all depends on how much activity is on the server, so you have to suck it and see).
Run the trace briefly and then pause it. Goto File-> Export โ Script Define a trace and select the version of your database and save the file. Now you have a sql script that creates tracing with much less overhead than working with the profiler GUI. When you run this script, it will display the trace identifier (usually @ID=2 ); pay attention to this.
As soon as you have a trace file (.trc) (either the trace is completed due to reaching the maximum file size, or the running trace is stopped using
EXEC sp_trace_setstatus @ID, 0
EXEC sp_trace_setstatus @ID, 2
You can load the trace into the profiler or use ClearTrace (very convenient) or load it into the table as follows:
SELECT * INTO TraceTable FROM ::fn_trace_gettable('C:\location of your trace output.trc', default)
Then you can run a query to aggregate data such as this:
SELECT COUNT(*) AS TotalExecutions, EventClass, CAST(TextData as nvarchar(2000)) ,SUM(Duration) AS DurationTotal ,SUM(CPU) AS CPUTotal ,SUM(Reads) AS ReadsTotal ,SUM(Writes) AS WritesTotal FROM TraceTable GROUP BY EventClass, CAST(TextData as nvarchar(2000)) ORDER BY ReadsTotal DESC
Once you have identified costly requests, you can create and analyze actual execution plans.
Mitch Wheat Nov 03 '08 at 4:35 2008-11-03 04:35
source share