Skip to content

Latest commit

 

History

History
90 lines (66 loc) · 7.86 KB

File metadata and controls

90 lines (66 loc) · 7.86 KB
title View and Analyze Traces with SQL Server Profiler | Microsoft Docs
ms.custom
ms.date 03/14/2017
ms.prod sql-server-2016
ms.reviewer
ms.suite
ms.technology
database-engine
ms.tgt_pltfrm
ms.topic article
helpviewer_keywords
Profiler [SQL Server Profiler], viewing traces
SQL Server Profiler, viewing traces
traces [SQL Server], viewing
SQL Server Profiler, troubleshooting
troubleshooting [SQL Server], traces
events [SQL Server], finding inside trace
Profiler [SQL Server Profiler], troubleshooting
traces [SQL Server], events
ms.assetid 17e821ca-a12e-4192-acc1-96765d9ae266
caps.latest.revision 38
author JennieHubbard
ms.author jhubbard
manager jhubbard

View and Analyze Traces with SQL Server Profiler

Use [!INCLUDEssSqlProfiler] to view captured event data in a trace. [!INCLUDEssSqlProfiler] displays data based on defined trace properties. One way to analyze [!INCLUDEssNoVersion] data is to copy the data to another program, such as [!INCLUDEssNoVersion] or [!INCLUDEssDE] Tuning Advisor. [!INCLUDEssDE] Tuning Advisor can use a trace file that contains SQL batch and remote procedure call (RPC) events if the Text data column is included in the trace. To make sure that the correct events and columns are captured for use with [!INCLUDEssDE] Tuning Advisor, use the predefined Tuning template that is supplied with [!INCLUDEssSqlProfiler].

When you open a trace by using [!INCLUDEssSqlProfiler], the trace file does not need to have the .trc file extension if the file was created by either [!INCLUDEssSqlProfiler] or SQL Trace system stored procedures.

Note

[!INCLUDEssSqlProfiler] can also read SQL Trace .log files and generic SQL script files. When opening a SQL Trace .log file that does not have a .log file extension, such as trace.txt, specify SQLTrace_Log as the file format.

You can configure the [!INCLUDEssSqlProfiler] date and time display format to assist in trace analysis.

Troubleshooting Data

Using [!INCLUDEssSqlProfiler], you can troubleshoot data by grouping traces or trace files by the Duration, CPU, Reads, or Writes data columns. Examples of data you might troubleshoot are queries that perform poorly or that have exceptionally high numbers of logical read operations.

Additional information can be found by saving traces to tables and using [!INCLUDEtsql] to query the event data. For example, to determine which SQL:BatchCompleted events had excessive wait time, execute the following:

SELECT  TextData, Duration, CPU  
FROM    trace_table_name  
WHERE   EventClass = 12 -- SQL:BatchCompleted events  
AND     CPU < (Duration * 1000)  

Note

The server reports the duration of an event in microseconds (10^-6 seconds) and the amount of CPU time used by the event in milliseconds (10^-3 seconds). The [!INCLUDEssSqlProfiler] graphical user interface displays the Duration column in milliseconds by default, but when a trace is saved to either a file or a database table, the Duration column value is written in microseconds.

Displaying Object Names When Viewing Traces

If you wish to display the name of an object rather than the object identifier (Object ID), you must capture the Server Name and Database ID data columns along with the Object Name data column.

If you choose to group by the Object ID data column, make sure you group by the Server Name and Database ID data columns first, and then by the Object ID data column. Similarly, if you choose to group by the Index ID data column, make sure you group by the Server Name, Database ID, and Object ID data columns first, and then by the Index ID data columns. You must group in this order because object and index IDs are not unique among servers and databases (and among objects for index IDs).

Finding Specific Events Within a Trace

To find and group events in a trace, follow these steps:

  1. Create your trace.

    • When defining the trace, capture the Event Class, ClientProcessID, and Start Time data columns in addition to any other data columns you want to capture. For more information, see Create a Trace (SQL Server Profiler).

    • Group the captured data by the Event Classdata column, and capture the trace to a file or table. To group the captured data, click Organize Columns on the Events Selection tab of the Trace Properties dialog box. For more information, see Organize Columns Displayed in a Trace (SQL Server Profiler).

    • Start the trace and stop it after the appropriate time has passed or number of events have been captured.

  2. Find the target events.

    • Open the trace file or table, and expand the node of the desired event class; for example, Deadlock Chain. For more information, see Open a Trace File (SQL Server Profiler) or Open a Trace Table (SQL Server Profiler).

    • Search through the trace data until you find the events for which you are looking (use the Find command on the Edit menu of [!INCLUDEssSqlProfiler] to help you find values in the trace). Note the values in the ClientProcessID and Start Time data columns of the events you trace.

  3. Display the events in context.

    • Display the trace properties, and group by the ClientProcessIDdata column rather than by the Event Class data column.

    • Expand the nodes of each client process ID you want to view. Search through the trace manually, or use Find until you find the previously noted Start Timevalues of the target events. The events are displayed in chronological order with the other events that belong to each selected client process ID. For example, the Deadlock and Deadlock Chainevents, captured within the trace, appear immediately after the SQL:BatchStartingevents within the expanded client process ID.

The same technique can be used to find any grouped events. Once you have found the events you seek, group them by ClientProcessID, ApplicationName, or another event class to view related activity in chronological order.

See Also

View a Saved Trace (Transact-SQL)
sys.fn_trace_getinfo (Transact-SQL)
View Filter Information (SQL Server Profiler)
View Filter Information (Transact-SQL)
Open a Trace File (SQL Server Profiler)
Open a Trace Table (SQL Server Profiler)