tkprof用法

来源:互联网 发布:淘宝快速备案注销 编辑:程序博客网 时间:2024/06/06 20:11


作用:格式化跟踪文件,例如格式化sqltrace,10046产生的输出文件。

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' SQLstatements.
  aggregate=yes|no
  insert=filename  ListSQL statements and data inside INSERT statements.
  sys=no        TKPROF doesnot list SQL statements run as user SYS.
  record=filename  Recordnon-recursive statements found in the trace file.
  waits=yes|no    Recordsummary for any wait events found in the trace file.
  sort=option     Set of zeroor more of the following sort options:
   prscnt  number of times parse wascalled
   prscpu  cpu time parsing
   prsela  elapsed timeparsing
   prsdsk  number of disk readsduring parse
   prsqry  number of buffers forconsistent read during parse
    prscu  number of buffers for current read duringparse
   prsmis  number of misses inlibrary cache during parse
   execnt  number of execute wascalled
   execpu  cpu time spentexecuting
   exeela  elapsed timeexecuting
   exedsk  number of disk readsduring execute
   exeqry  number of buffers forconsistent read during execute
    execu  number of buffers for current read duringexecute
   exerow  number of rows processedduring execute
   exemis  number of library cachemisses during execute
   fchcnt  number of times fetch wascalled
   fchcpu  cpu time spentfetching
   fchela  elapsed timefetching
   fchdsk  number of disk readsduring fetch
   fchqry  number of buffers forconsistent read during fetch
    fchcu  number of buffers for current read duringfetch
   fchrow  number of rowsfetched
   userid  userid of user thatparsed the cursor

2)几个重要参数的用法

  • sys参数,如果不指定默认值为yes.这个参数的含义是,输出文件中是否包含以SYS用户运行的sql语句。这个参数还是蛮有用的,我们执行sql语句的时候,后台经常会执行很多递归的语句,比如你输入了SELECT* FROMTEST;如果这个语句是硬解析的话,那么会产生很多递归的SQL,递归的去查询表的统计信息,列的统计信息,索引的统计信息等,当然递归的不止是这些。这些递归的sql都是以SYS用户运行的,如果你不希望看到这些递归SQL,那么就加上这个参数sys=no.
  • record参数,它指定的是一个路径下的文件,这个文件用来生成在跟踪文件中找到的所有的非递归SQL。比如你在SQLPLUS里执行了三条语句,select* from a;select * from b;select * fromc;,那么如果你指定了这个参数如:record=c:\test.log,那么你用tkprof格式化跟踪文件后,这个test.log里就会记录这三个SQL。这个特性在有些时候还是满有用的,因为跟踪文件往往都会比较大,找起来会比较费劲,我们可以通过指定这个参数先大体了解下,跟踪文件里都有哪些非递归SQL。而且这个功能还有助于我们重演SQL语句(绑定变量的不可以)。
  • aggregate参数,它指定tkprof是否将同样文本内容的sql聚合处理,比如,你执行了十次select * froma,如果你指定这个参数为no(默认情况),那么产生的输出文件会有十个这样语句的执行信息,如果你指定的是yes,那么tkprof会把这十次的执行信息汇总显示。这个参数怎么指定就看你的需要了,个人觉得还是满有用的一个参数。
  • sort参数,这个参数是经常使用到的一个参数,它用来指定tkprof输出文件里sql语句按照什么排序,默认是按照执行的先后顺序排序的,我们可以指定它按照其他方式排序,比如磁盘读取数,CPU时间等。这个参数最经常用的方式是:sort=prsela,exeela,fchela,其实这三个值加起来就是响应时间,即按照响应时间排序。这里别产生误解,tkprof会根据prsela,exeela,fchela三个值的和进行排序,而不是像SQL语句似的一个个的排序。
  • print参数,它经常搭配sort参数一起使用,用来指定tkprof输出sql语句的数量。这两个参数搭配使用起来就比较妙,比如你想知道一个跟踪文件里响应时间排前十的SQL,那么你就可以sort=prsela,exeela,fchelaprint=10来搭配使用。
  • explain参数,这个参数的含义是为每一个SQL提供一个执行计划。使用的方法是explain=用户名/密码,其实原理很简单,就是通过你指定的用户名,密码登陆数据库,然后为每一个sql执行以下explainplan for sql,输出到plan_table里,最后添加到输出文件里。注意,由于explain plan for命令要求执行操作的用户要对sql语句里包含的对象都有执行权限,如果包含视图,也要对视图基于的基础表有执行权限,否则产生不了执行计划。注意增加了这个参数后,执行tkprof会比较慢。
  • wait参数,指定输出文件中包含不包含等待事件,默认是包含的。一般都取默认值。
基本最常用到的就这些,其他的我就不介绍了
 
下面是个简单的例子:
 
先得到要分析得TRACE文件

TRACE_FILE_NAME                                                                
--------------------------------------------------------------------------------
f:\app\administrator\diag\rdbms\orcl\orcl\trace/orcl_ora_3040.trc 

           
--使用tkprof分析trace文件
C:\Documents andSettings\Administrator>tkprof f:\app\administrator\diag\rdbms\orcl\orcl\trace/orcl_ora_4020.trc  f:\4020.trc.txt  aggregate=yes sys=no waits=yessort=fchela
--tkprocf输出了以下文件:f:\4020.trc.txt

TKPROF: Release11.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 currentmode (usually for update)
rows    = number of rows processed by the fetch or execute call

 

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

OVERALL TOTALS FOR ALLNON-RECURSIVE STATEMENTS

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

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


OVERALL TOTALS FOR ALLRECURSIVE STATEMENTS

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

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

    user  SQL statements insession.
    internal SQL statements in session.
    SQL statements in session.
********************************************************************************
Trace file: f:\4020.trc
Trace file compatibility: 11.01.00
Sort options: fchela 
       session in tracefile.
       user  SQL statements in tracefile.
       internal SQL statements in trace file.
       SQL statements in trace file.
       unique SQL statements in trace file.
    107  lines in trace file.
    124  elapsed seconds in trace file.


0 0
原创粉丝点击