ITPub博客

首页 > 应用开发 > IT综合 > events跟踪tkprof用法

events跟踪tkprof用法

原创 IT综合 作者:xiaokadba 时间:2011-09-13 15:08:17 0 删除 编辑
EVENTS:
设定跟踪:
1、设定跟踪文件大小不受限制
SQL>ALTER SESSION SET max_dump_file_size = UNLIMITED;
2、打开10046跟踪
SQL>ALTER SESSION SET EVENTS '10046 trace name context forever, level 12';
3、执行语句
... ...
4、关闭跟踪
SQL>ALTER SESSION SET EVENTS '10046 trace name context off';
5、查看跟踪文件路径
show parameter user_dump_dest
我测试机上为
D:appAdministratordiagrdbmsorclorcltrace
TKPROF:
作用:格式化跟踪文件,例如格式化sql trace,10046产生的输出文件。
目的是将sql trace 生成的跟踪文件转换成用户可以理解的格式。
1、TKPROF的参数:
不输入任何参数,直接输入tkprof,回车,可以获得一个完整的参数列表.C:>tkprof
Usage: tkprof tracefile outputfile [explain= ] [table= ]
[print= ] [insert= ] [sys= ] [sort= ]
table=schema.tablename Use 'schema.tablename' with 'explain=' option.
explain=user/password Connect to ORACLE and issue EXPLAIN PLAN.
print=integer List only the first 'integer' SQL statements.
aggregate=yes|no
insert=filename List SQL statements and data inside INSERT statements.
sys=no TKPROF does not list SQL statements run as user SYS.
record=filename Record non-recursive statements found in the trace file.
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:
prscnt number of times parse was called
prscpu cpu time parsing
prsela elapsed time parsing
prsdsk number of disk reads during parse
prsqry number of buffers for consistent read during parse
prscu number of buffers for current read during parse
prsmis number of misses in library cache during parse
execnt number of execute was called
execpu cpu time spent executing
exeela elapsed time executing
exedsk number of disk reads during execute
exeqry number of buffers for consistent read during execute
execu number of buffers for current read during execute
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
fchela elapsed time fetching
fchdsk number of disk reads during fetch
fchqry number of buffers for consistent read during fetch
fchcu number of buffers for current read during fetch
fchrow number of rows fetched
userid userid of user that parsed the cursor
参数和选项:
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 按返回数据时处理的数据数量排序
2、几个重要参数的用法
  • sys参数,如果不指定默认值为yes.这个参数的含义是,输出文件中是否包含以SYS用户运行的sql语句。这个参数还是蛮有用的,我们执行sql语句的时候,后台经常会执行很多递归的语句,比如你输入了SELECT * FROM TEST;如果这个语句是硬解析的话,那么会产生很多递归的SQL,递归的去查询表的统计信息,列的统计信息,索引的统计信息等,当然递归的不止是这些。这些递归的sql都是以SYS用户运行的,如果你不希望看到这些递归SQL,那么就加上这个参数sys=no.
  • record参数,它指定的是一个路径下的文件,这个文件用来生成在跟踪文件中找到的所有的非递归SQL。比如你在SQLPLUS里执行了三条语句,select * from a;select * from b;select * from c;,那么如果你指定了这个参数如:record=c:test.log,那么你用tkprof格式化跟踪文件后,这个test.log里就会记录这三个SQL。这个特性在有些时候还是满有用的,因为跟踪文件往往都会比较大,找起来会比较费劲,我们可以通过指定这个参数先大体了解下,跟踪文件里都有哪些非递归SQL。而且这个功能还有助于我们重演SQL语句(绑定变量的不可以)。
  • aggregate参数,它指定tkprof是否将同样文本内容的sql聚合处理,比如,你执行了十次select * from a,如果你指定这个参数为no(默认情况),那么产生的输出文件会有十个这样语句的执行信息,如果你指定的是yes,那么tkprof会把这十次的执行信息汇总显示。这个参数怎么指定就看你的需要了,个人觉得还是满有用的一个参数。
  • sort参数,这个参数是经常使用到的一个参数,它用来指定tkprof输出文件里sql语句按照什么排序,默认是按照执行的先后顺序排序的,我们可以指定它按照其他方式排序,比如磁盘读取数,CPU时间等。这个参数最经常用的方式是:sort=prsela,exeela,fchela,其实这三个值加起来就是响应时间,即按照响应时间排序。这里别产生误解,tkprof会根据prsela,exeela,fchela三个值的和进行排序,而不是像SQL语句似的一个个的排序。
  • print参数,它经常搭配sort参数一起使用,用来指定tkprof输出sql语句的数量。这两个参数搭配使用起来就比较妙,比如你想知道一个跟踪文件里响应时间排前十的SQL,那么你就可以sort=prsela,exeela,fchela print=10来搭配使用。
  • explain参数,这个参数的含义是为每一个SQL提供一个执行计划。使用的方法是explain=用户名/密码,其实原理很简单,就是通过你指定的用户名,密码登陆数据库,然后为每一个sql执行以下explain plan for sql,输出到plan_table里,最后添加到输出文件里。注意,由于explain plan for 命令要求执行操作的用户要对sql语句里包含的对象都有执行权限,如果包含视图,也要对视图基于的基础表有执行权限,否则产生不了执行计划。注意增加了这个参数后,执行tkprof会比较慢。
  • wait参数,指定输出文件中包含不包含等待事件,默认是包含的。一般都取默认值。

3、输出的结果
使用tkprof分析trace文件
C:Documents and SettingsAdministrator>tkprof f:appadministratordiagrdbmsorclorcltrace/orcl_ora_4020.trc f:4020.trc.txt aggregate=yes sys=no waits=yes sort=fchela
--tkprocf输出了以下文件:f:4020.trc.txt

TKPROF: Release 11.1.0.6.0 - Production on 星期一 3月 29 13:50:42 2010

Copyright (c) 1982, 2007, Oracle. All rights reserved.

Trace file: f:4020.trc
Sort options: fchela
********************************************************************************
count = number of times OCI procedure was executed
cpu = cpu time in seconds executing
elapsed = elapsed time in seconds executing
disk = number of physical reads of buffers from disk
query = number of buffers gotten for consistent read
current = number of buffers gotten in current mode (usually for update)
rows = number of rows processed by the fetch or execute call

count:提供OCI过程的执行次数

CPU: 提供执行CPU所花的时间单位是秒

Elapsed:提供了执行时所花的时间。单位是秒。这个参数值等于用户响应时间

Disk:提供缓存区从磁盘读取的次数

Query:以一致性模式从缓存区获得数据的次数

Current:以当前模式从缓存区获得数据的次数

ROWs: 返回调用或执行调用时,处理的数据行的数量。

********************************************************************************

OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 6 0.01 5403.67 0 1 0 0
Execute 7 0.00 0.00 0 0 0 0
Fetch 8 0.03 0.07 137 2080 0 4
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 21 0.04 5403.75 137 2081 0 4

Misses in library cache during parse: 2
Misses in library cache during execute: 1


OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS

call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 2 0.00 0.05 0 0 0 0
Execute 2 0.00 0.01 0 0 0 0
Fetch 2 0.00 0.08 379 67 0 1
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 6 0.00 0.15 379 67 0 1

Misses in library cache during parse: 2
Misses in library cache during execute: 1

7 user SQL statements in session.
2 internal SQL statements in session.
9 SQL statements in session.
********************************************************************************
Trace file: f:4020.trc
Trace file compatibility: 11.01.00
Sort options: fchela
1 session in tracefile.
7 user SQL statements in trace file.
2 internal SQL statements in trace file.
9 SQL statements in trace file.
6 unique SQL statements in trace file.
107 lines in trace file.
124 elapsed seconds in trace file.

[@more@]

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

上一篇: RMAN恢复
请登录后发表评论 登录
全部评论
  • 博文量
    14
  • 访问量
    11169