ITPub博客

首页 > 应用开发 > IT综合 > tkprof 转换trc文件

tkprof 转换trc文件

原创 IT综合 作者:oo0yuki0oo 时间:2010-05-06 00:32:09 0 删除 编辑
tkprof 的目的是将sql trace 生成的跟踪文件转换成用户可以理解的格式
1. 格式
tkprof inputfile outputfile [optional | parameters ]
参数和选项:
explain=user/password 执行explain命令将结果放在SQL trace的输出文件中
table=schema.table 指定tkprof处理sql trace文件时临时表的模式名和表名
insert=scriptfile 创建一个文件名为scriptfile的文件,包含了tkprof存放的输出sql语句
sys=[yes/no] 确定系统是否列出由sys用户产生或重调的sql语句
print=number 将仅生成排序后的第一条sql语句的输出结果
record=recordfile 这个选项创建一个名为recorderfile的文件,包含了所有重调用的sql语句
sort=sort_option 按照指定的方法对sql trace的输出文件进行降序排序
sort_option 选项
prscnt 按解析次数排序
prscpu 按解析所花cpu时间排序
prsela 按解析所经历的时间排序
prsdsk 按解析时物理的读操作的次数排序
prsqry 按解析时以一致模式读取数据块的次数排序
prscu 按解析时以当前读取数据块的次数进行排序
execnt 按执行次数排序
execpu 按执行时花的cpu时间排序
exeela 按执行所经历的时间排序
exedsk 按执行时物理读操作的次数排序
exeqry 按执行时以一致模式读取数据块的次数排序
execu 按执行时以当前模式读取数据块的次数排序
exerow 按执行时处理的记录的次数进行排序
exemis 按执行时库缓冲区的错误排序
fchcnt 按返回数据的次数进行排序
fchcpu 按返回数据cpu所花时间排序
fchela 按返回数据所经历的时间排序
fchdsk 按返回数据时的物理读操作的次数排序
fchqry 按返回数据时一致模式读取数据块的次数排序
fchcu 按返回数据时当前模式读取数据块的次数排序
fchrow 按返回数据时处理的数据数量排序
例子:

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->tkprof D:oracleproduct10.2.0adminorcludump1.trc d:2.txt explain=hqt/hqt sys=no
启动SQL Trace 之后收集的信息包括
1.解析、执行、返回数据的次数
2.cpu和执行命令的时间
3.物理读和逻辑读的次数
4.系统处理的记录数
5.库缓冲区错误
SQL Trace 的输出结果
count:提供OCI过程的执行次数
CPU: 提供执行CPU所花的时间单位是秒
Elapsed:提供了执行时所花的时间。单位是秒。这个参数值等于用户响应时间
Disk:提供缓存区从磁盘读取的次数
Query:以一致性模式从缓存区获得数据的次数
Current:以当前模式从缓存区获得数据的次数
ROWs: 返回调用或执行调用时,处理的数据行的数量。

需要调整的语句符合以下几点:

(1),CPU占用过多

(2),Parse,Execute,Fetch花费太多时间

(3),DISK读取太多,query/current(SGA)中数据块读取太少

(4),访问许多块,只返回2行

[@more@]

=============================

使用tkprof格式化trace文件
Usage: tkprof tracefile outputfile [explain= ] [table= ] [print= ] [insert= ] [sys= ] [sort= ]
输入文件 格式化后的输出文件
table=schema.tablename Use 'schema.tablename' with 'explain=' option.
用于指定在将执行规划写进输出文件之前,TKPROF用于临时存放执行规划所用表的架构和名称
explain=user/password Connect to ORACLE and issue EXPLAIN PLAN.
print=integer List only the first 'integer' SQL statements. 只列出输出文件中的第一个INTEGER的SQL语句,若忽略,则TKPROF将列出所有跟踪的SQL语句
aggregate=yes|no 若用户指定AGGREGATE=NO,TKPROF将不会对相同SQL文本的多个用户进行汇总
insert=filename List SQL statements and data inside INSERT statements. SQL脚本的一种,用于将跟踪文件的动机信息存储到数据库中
sys=no TKPROF does not list SQL statements run as user SYS. 于启动或禁止将用户SYS所发布的SQL语句列表到输出文件之中,也包括递归SQL(为执行用户的SQL语句,ORACLE还必须执行一些附加语句)语句在内。默认为YES
record=filename Record non-recursive statements found in the trace file. 对于跟踪文件中的所用非递归SQL语句,TKPROF 将以指定的名称来创建某个SQL脚本。用于对跟踪文件中的用户时间进行重放
waits=yes|no Record summary for any wait events found in the trace file.
sort=option Set of zero or more of the following sort options: 在将被跟踪的SQL语句列表输出到跟踪文件之前,先将其按照指定排序选项的降序关系对其进行排序;若指定了多种排序选项,那么根据排序选项所指定值的和的降序关系对其进行排序;若忽略此参数,那么TKPROF将按照使用次序把语句列表到输出文件中
prscnt number of times parse was called 语句解析的数目
prscpu cpu time parsing 语句解析所占用的CPU时间
prsela elapsed time parsing 语句解析所占用的时间(总是大于或等于CPU时间);
prsdsk number of disk reads during parse 语句解析期间,从磁盘进行物理读取的数目
prsqry number of buffers for consistent read during parse 语句解析期间,一致模式块读取(CONSISTENT MODE BLOCK READ)的数目
prscu number of buffers for current read during parse 语句解析期间,当前模式读取(CURRENT MODE BLOCK READ)的数目
prsmis number of misses in library cache during parse 语句解析期间,库缓存失败的数目

execnt number of execute was called 语句执行的数目
execpu cpu time spent executing 语句执行所占用的CPU时间
exeela elapsed time executing 语句执行所占用的时间(总是大于或等于CPU时间)
exedsk number of disk reads during execute 语句执行期间,从磁盘进行物理读取的数目
exeqry number of buffers for consistent read during execute 语句执行期间,一致模式块读取(CONSISTENT MODE BLOCK READ)的数目
execu number of buffers for current read during execute 语句执行期间,当前模式读取(CURRENT MODE BLOCK READ)的数目
exerow number of rows processed during execute 语句执行期间,所处理的语句行数
exemis number of library cache misses during execute 语句执行期间,库缓存失败的数目

fchcnt number of times fetch was called 取数据的数目
fchcpu cpu time spent fetching 取数据所占用的CPU时间
fchela elapsed time fetching 取数据所占用的时间(总是大于或等于CPU时间)
fchdsk number of disk reads during fetch 取数据期间,从磁盘进行物理读取的数目
fchqry number of buffers for consistent read during fetch 取数据期间,一致模式块读取(CONSISTENT MODE BLOCK READ)的数目
fchcu number of buffers for current read during fetch 取数据期间,当前模式读取(CURRENT MODE BLOCK READ)的数目
fchrow number of rows fetched 所获取的行数
userid userid of user that parsed the cursor

------------------------------------------------

SELECT a.VALUE||b.symbol||c.instance_name||'_ora_'||d.spid||'.trc' TRACE_FILE_NAME
FROM (SELECT VALUE FROM v$parameter WHERE NAME='user_dump_dest') a,
(SELECT SUBSTR(VALUE,-6,1) symbol FROM v$parameter WHERE NAME='user_dump_dest') b,
(SELECT instance_name FROM v$instance) c,
(SELECT spid FROM v$session s,v$process p,v$mystat m
WHERE s.paddr=p.addr AND s.SID=m.SID AND m.statistic#=0) d

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8337095/viewspace-1033402/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-04-22

  • 博文量
    62
  • 访问量
    82176