温馨提示:如果是要通过分析跟踪文件得到消耗高的语句/存储过程,不需要花哨的图表数据,建议移步至ClearTrace^_-


很早以前有看到过关于使用RML Utilities工具分析SQL Trace(.trc)的文章,但一直没有具体实践。最近接管一台数据库服务器,跟踪出一批高消耗的语句,老大需要跟踪分析报表,罗列出过程(语句)按CPU、Duration、Reads的执行情况(总消耗、平均消耗、执行次数)。很多存储过程调用或动态语句总体是一样的,只是带的参数会有不同。所以重点是针对这一类的跟踪结果进行处理。
一开始是使用fn_trace_gettable对跟踪文件进行分析,按TextData排序,通过截取TextData左边N位尝试分组,观察总体相同的过程或语句中的关键字,逐一得出跟踪分析报表。之后再次使用这种方法分析了跟踪文件,感觉这样分析太过于傻瓜,而且耗时。于是搜索RML Utilities的使用方法:
Step1:生成trc文件
开启服务端跟踪,对生产服务器进行跟踪一段时间,生成HighDuration20151212.trc文件,将文件从服务器拷贝到本地F:\TroubleShooting\Trace\HighDuration20151212.trc
Step2:打开RML Utilities Command Prompt工具
该工具在:开始->所有程序->RML Utilities for SQL Server->RML Cmd Prompt 或者进入安装目录(我的安装目录是:D:\Program Files\Microsoft Corporation\RMLUtils\)双击RML.cmd文件,打开的界面如图:
RML Utilities for SQL Server
Step3:开启本地SQL server 服务
我本地安装有SQL08R2和SQL12两个实例,本次使用SQL08R2实例。
Step4:运行导入命令

ReadTrace -I"F:\TroubleShooting\Trace\HighDuration20151212.trc" -o"F:\TroubleShooting\Trace\output" -S"127.0.0.1,7777" -d"PerfAnalysis_CL" -E

注意,这里的参数是区分大小写的。具体参数说明(-I:输入文件,-o:输出文件,-S:服务器,-d:数据库,-E:windows认证),-d后面的数据库如果存在,先删除库下ReadTrace架构下的表,然后重新创建此类表;-d后面的数据库如果不存在,则创建指定数据库,并创建ReadTrace相关表。
输出结果如下:

12/12/15 16:56:41.390 [0X00002E94] Readtrace a SQL Server trace processing utility.
Version 9.04.0013 built for x86.
Copyright © 1997-2014 Microsoft. All Rights Reserved
12/12/15 16:56:41.392 [0X00002E94]             Computer: WORK
12/12/15 16:56:41.392 [0X00002E94]          Base Module: D:\Program Files\Microsoft Corporation\RMLUtils\ReadTrace.exe
12/12/15 16:56:41.392 [0X00002E94]           Process Id: 11852
12/12/15 16:56:41.393 [0X00002E94]  Active proc mask(0): 0x0000000F
12/12/15 16:56:41.393 [0X00002E94]         Architecture: 0
12/12/15 16:56:41.393 [0X00002E94]            Page size: 4096
12/12/15 16:56:41.394 [0X00002E94]                 CPUs: 4
12/12/15 16:56:41.394 [0X00002E94]     Processor groups: 1
12/12/15 16:56:41.394 [0X00002E94]         Highest node: 0
12/12/15 16:56:41.395 [0X00002E94]   Proximity: 00  Node: 00
12/12/15 16:56:41.395 [0X00002E94] ---------------------------------------
12/12/15 16:56:41.395 [0X00002E94]                Group: 0
12/12/15 16:56:41.396 [0X00002E94] ---------------------------------------
12/12/15 16:56:41.396 [0X00002E94]         Processor(s): 0x00000003 Function units: Shared
12/12/15 16:56:41.399 [0X00002E94]         Package mask: 0x0000000F
12/12/15 16:56:41.403 [0X00002E94]         Processor(s): 0x0000000C Function units: Shared
12/12/15 16:56:41.406 [0X00002E94]         Processor(s): 0x0000000F assigned to Numa node: 0
12/12/15 16:56:41.412 [0X00002E94] Current time bias: -480 minutes -8.00 hours DST not used 
12/12/15 16:56:41.413 [0X00002E94] -IF:\TroubleShooting\Trace\HighDuration20151212.trc
12/12/15 16:56:41.416 [0X00002E94] -oF:\TroubleShooting\Trace\output
12/12/15 16:56:41.417 [0X00002E94] -S127.0.0.1,7777
12/12/15 16:56:41.419 [0X00002E94] -dPerfAnalysis_CL
12/12/15 16:56:41.421 [0X00002E94] -E
12/12/15 16:56:41.426 [0X00002E94] Using language id (LCID): 1024 [Chinese (Simplified)_People's Republic of China.936] for character formatting with NLS: 0x00060101 and Defined: 0x00060101
12/12/15 16:56:41.427 [0X00002E94] Attempting to cleanup existing RML files from previous execution
12/12/15 16:56:41.432 [0X00002E94] Using extended RowsetFastload synchronization
12/12/15 16:56:41.433 [0X00002E94] Establishing initial database connection
12/12/15 16:56:41.434 [0X00002E94] Server: 127.0.0.1,7777
12/12/15 16:56:41.436 [0X00002E94] Database: PerfAnalysis_CL
12/12/15 16:56:41.438 [0X00002E94] Authentication: Windows
12/12/15 16:56:41.563 [0X00002E94] Using SQLOLEDB version 11.0.2100.60
12/12/15 16:56:41.565 [0X00002E94] Connected to SQL Server Version, Major: 10, Minor: 50, Build: 1600
12/12/15 16:56:41.566 [0X00002E94] Creating or clearing the performance database
12/12/15 16:56:46.378 [0X00002E94] Processing file: F:\TroubleShooting\Trace\HighDuration20151212.trc (SQL 2008 / SQL 2008 R2 / SQL Azure*)
12/12/15 16:56:46.378 [0X00002E94] Validating core events exist
12/12/15 16:56:46.379 [0X00002E94] WARNING: The 'EventSequence' column for event id=10 [POST_RPC_EVENT_CLASS] is missing from the trace.
12/12/15 16:56:46.380 [0X00002E94] WARNING: The 'EventSequence' column for event id=12 [POST_LANG_EVENT_CLASS] is missing from the trace.
12/12/15 16:56:46.381 [0X00002E94] WARNING: The 'EventSequence' column for event id=13 [PRE_LANG_EVENT_CLASS] is missing from the trace.
12/12/15 16:56:46.382 [0X00002E94] WARNING: The 'EventSequence' column is missing from the trace.  Physical file order will be used and this can lead to inaccurate results.
12/12/15 16:56:46.382 [0X00002E94] Validating necessary events exist for analysis
12/12/15 16:56:46.383 [0X00002E94] WARNING: The following trace events were not captured: [RPC:Starting, SP:StmtStarting, SP:StmtCompleted, Audit:Login, Audit:Logout, Showplan Statistics]. Review the help file to ensure that you have collected the appropriate set of events and columns for your intended analysis.
12/12/15 16:56:46.384 [0X00002E94] Validating necessary events exist for RML breakout
12/12/15 16:56:46.385 [0X00002E94] WARNING: Event [Server: Server Memory Change] missing from trace
12/12/15 16:56:46.386 [0X00002E94] WARNING REPLAY: The following trace events were not captured: [Sessions:ExistingConnection, Security Audit: Audit Login, Security Audit: Audit Logout, Stored Procedures: RPC Output Parameter, Cursors:Unprepare, Cursors:CursorClose, Cursors:CursorPrepare, Cursors:CursorCreated, Cursors:CursorExecute, TSQL: Prepare SQL, TSQL: Unprepare SQL, Errors and Warnings:Attention, Transactions:SQLTransaction, Transactions:DTCTransaction, Transactions:TM:Begin Tran starting, Transactions:TM:Begin Tran completed, Transactions:TM:Commit Tran starting, Transactions:TM:Commit Tran completed, Transactions:TM:Rollback Tran starting, Transactions:TM:Rollback Tran completed, Transactions:TM:Save Tran starting, Transactions:TM:Save Tran completed, Transactions:TM:Promote Tran starting, Transactions:TM:Promote Tran completed, RPC:Starting and RPC:Completed]. Review the help file to ensure that you have collected the appropriate set of events and columns for RML replay needs.  Lack of these events can lead to severe replay problems.
12/12/15 16:56:46.387 [0X00002E94] ERROR: RML output has been disabled because the required events or columns were not captured. Consult the log and help file for the recommended set of trace events and necessary columns. 
Trace flag -T28 disables the check allowing RML output processing. *** Use with caution as the output and behavior could be unpredictable.
12/12/15 16:56:46.418 [0X00002E94] Events Read: 1000 Queued: 977 Processed/sec: 4
12/12/15 16:56:46.456 [0X00002E94] Events Read: 2000 Queued: 1641 Processed/sec: 70
12/12/15 16:56:46.471 [0X00002E94] Events Read: 3000 Queued: 2634 Processed/sec: 71
12/12/15 16:56:46.483 [0X00002E94] Reached the end of the trace; found [TRACE_STOP_EVENT].
12/12/15 16:56:46.493 [0X00002E94] Reads completed
12/12/15 16:56:46.493 [0X00002E94] Signaling worker threads to complete final actions.
12/12/15 16:56:46.496 [0X00002E94] Waiting for the worker threads to complete final actions.
12/12/15 16:56:46.839 [0X00002E94] Performing general cleanup actions.
12/12/15 16:56:46.839 [0X00002E94] Reducing cached memory in background
12/12/15 16:56:46.841 [0X00002E94] Total Events Processed: 3839
12/12/15 16:56:46.841 [0X00002E94]  Total Events Filtered: 0
12/12/15 16:56:46.866 [0X00002E94] Table ReadTrace.tblUniqueBatches: loaded ~26 rows
12/12/15 16:56:46.866 [0X00002E94] Table ReadTrace.tblUniqueStatements: loaded ~0 rows
12/12/15 16:56:46.867 [0X00002E94] Table ReadTrace.tblUniquePlans: loaded ~0 rows
12/12/15 16:56:46.867 [0X00002E94] Table ReadTrace.tblUniquePlanRows: loaded ~0 rows
12/12/15 16:56:46.924 [0X00002E94] Table ReadTrace.tblBatches: loaded ~3837 rows
12/12/15 16:56:46.926 [0X00002E94] Table ReadTrace.tblStatements: loaded ~0 rows
12/12/15 16:56:46.928 [0X00002E94] Table ReadTrace.tblPlans: loaded ~0 rows
12/12/15 16:56:46.929 [0X00002E94] Table ReadTrace.tblPlanRows: loaded ~0 rows
12/12/15 16:56:46.930 [0X00002E94] Table ReadTrace.tblInterestingEvents: loaded ~0 rows
12/12/15 16:56:46.946 [0X00002E94] Table ReadTrace.tblConnections: loaded ~61 rows
12/12/15 16:56:46.950 [0X00002E94] WARNING: One or more warning conditions exist that may affect the quality of the analysis data.  See PerfAnalysis_CL.ReadTrace.tblWarnings table and the ReadTrace log for complete details.
12/12/15 16:56:46.954 [0X00002E94] INFO: Cleaning up unique batch hash table
12/12/15 16:56:46.955 [0X00002E94] INFO: Cleaning up unique statement hash table
12/12/15 16:56:46.956 [0X00002E94] INFO: Cleaning up unique plan hash table
12/12/15 16:56:46.957 [0X00002E94] INFO: Cleaning up unique procedure hash table
12/12/15 16:56:46.958 [0X00002E94] Indexing tables...
12/12/15 16:56:49.691 [0X00002E94] Doing post-load data cleanup...
12/12/15 16:56:51.311 [0X00002E94] Computing partial aggregates...
12/12/15 16:56:53.180 [0X00002E94] Building analysis indexes ...
12/12/15 16:56:53.188 [0X00002E94] Data load completed.
12/12/15 16:56:53.189 [0X00002E94] Using execution path: D:\Program Files\Microsoft Corporation\RMLUtils\
12/12/15 16:56:53.190 [0X00002E94] Launching [D:\Program Files\Microsoft Corporation\RMLUtils\Reporter.exe]
12/12/15 16:56:53.195 [0X00002E94] Launch failure exit code: 259
12/12/15 16:56:53.195 [0X00002E94] Attempt to launch Reporter failed.  Check the error log and your RML installation.
12/12/15 16:56:53.196 [0X00002E94] *******************************************************************************
* ReadTrace encountered one or more ERRORS. An error condition typically      *
* stops processing early and the ReadTrace output may be unusable.            *
* Review the log file for details.                                            *
*******************************************************************************
12/12/15 16:56:53.197 [0X00002E94] ***** ReadTrace exit code: -23
View Code

相关文章:

  • 2021-07-30
  • 2022-12-23
  • 2021-07-27
  • 2021-08-13
  • 2022-02-19
  • 2022-12-23
  • 2021-06-28
猜你喜欢
  • 2021-11-03
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2021-08-04
相关资源
相似解决方案