View and Analyze Traces with SQL Server Profiler
2013-01-09 14:11
399 查看
Use SQL Server Profiler to view captured event data in a trace. SQL Server Profiler displays data based on defined trace properties. One way to analyze SQL Server data is to copy the data to another program, such as SQL Server or Database Engine Tuning Advisor.
Database Engine 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 Database Engine Tuning Advisor, use the predefined Tuning template that is supplied with SQL Server Profiler.
When you open a trace by using SQL Server Profiler, the trace file does not need to have the .trc file extension if the file was created by either SQL Server Profiler or SQL Trace system stored procedures.
You can configure the SQL Server Profiler date and time display format to assist in trace analysis.
Troubleshooting Data
Using SQL Server Profiler, 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 Transact-SQL to query the event data. For example, to determine which
SQL:BatchCompleted events had excessive wait time, execute the following:
Copy
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:
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.
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 SQL Server Profiler to help you find values in the trace). Note the values in the
ClientProcessIDand
Start Timedata columns of the events you trace.
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, Application Name, or another event class to view related activity in chronological order.
See Also
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)
Database Engine 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 Database Engine Tuning Advisor, use the predefined Tuning template that is supplied with SQL Server Profiler.
When you open a trace by using SQL Server Profiler, the trace file does not need to have the .trc file extension if the file was created by either SQL Server Profiler or SQL Trace system stored procedures.
Note |
---|
SQL Server Profiler 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. |
Troubleshooting Data
Using SQL Server Profiler, 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 Transact-SQL to query the event data. For example, to determine which
SQL:BatchCompleted events had excessive wait time, execute the following:
Copy
SELECT TextData, Duration, CPU FROM trace_table_name WHERE EventClass = 12 -- SQL:BatchCompleted events AND CPU < (Duration * 1000)
Note |
---|
Beginning with SQL Server 2005, the server reports the duration of an event in microseconds (one millionth, or 10-6, of a second) and the amount of CPU time used by the event in milliseconds (one thousandth, or 10-3, of a second). In SQL Server 2005 and later, the SQL Server Profiler 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. |
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:
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.
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 SQL Server Profiler to help you find values in the trace). Note the values in the
ClientProcessIDand
Start Timedata columns of the events you trace.
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, Application Name, or another event class to view related activity in chronological order.
See Also
Tasks
View a Saved Trace (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)
Reference
sys.fn_trace_getinfo (Transact-SQL)相关文章推荐
- SQL Cache Dependency with SQL Server, LINQ and ASP.NET 3.5
- The Microsoft Data Warehouse Toolkit: With SQL Server 2005 and the Microsoft Business Intelligence T
- .NET Enterprise Design with Visual Basic .NET and SQL Server 2000
- SQL SERVER – Introduction to SQL Server Encryption and Symmetric Key Encryption Tutorial with Script
- RDBMS and listener log (xml) from SQL*Plus with V$DIAG_ALERT_EXt view [ADR - Automatic Diagnostic Re
- SQL server Profiler and excution plan usage for CPU usage high analysis
- Issue 71 - pymssql - Undefined symbols on Mac, CentOS, Redhat with pre-compiled build - A fast MS SQL Server client library for Python directly using C API instead of ODBC. It is Python DB-API 2.0 compliant. Works on Linux, *BSD, Solaris, Mac OS X and Win
- Beginning Transact-SQL With SQL Server 2000 and 2005 by Paul Turley
- Importing Excel data with SQL Server Integration Services and dealing with unicode and non-unicode data issues
- Professional ADO.NET 2: Programming with SQL Server 2005, Oracle, and MySQL by Wallace B. McClure
- Using OpenLDAP with Microsoft SQL Server and Oracle Backend Databases
- Stored procedures versioning with SQL Server and Visual SourceSafe
- Using ROW_NUMBER() to paginate your data with SQL Server 2005 and ASP.NET
- Using ROW_NUMBER() to paginate your data with SQL Server 2005 and ASP.NET
- Beginning Transact-SQL With SQL Server 2000 and 2005
- Professional SQL Server 2005 CLR Programming: with Stored Procedures, Functions, Triggers, Aggregates and Types
- Steps to install SQL Server 2008 R2 Express Edition or Developer Edition with profiler
- MS SQL错误:SQL Server failed with error code 0xc0000000 to spawn a thread to process a new login or connection. Check the SQL Server error log and the Windows event logs for information about possible related problems
- Remote Data Access Synchronization with SQL Server 2005 Compact Edition and Visual C#.NET
- Cannot connect to WMI provider.You do not have permission or the server is unreachable.Note that you can only manager SQL Server 2005 and later version with SQL Server Configuration Manager.Invalid namespace [0x8004100e]