现在的位置: 首页 > 综合 > 正文

使用TKPROF工具进行跟踪ORACLE中程序运行状况

2013年12月13日 ⁄ 综合 ⁄ 共 2333字 ⁄ 字号 评论关闭

1.生成跟踪文件
alter session set timed_statistics=true;
alter session set events '10046 trace name context forever,level 12';
Session altered.
Session altered.

2.获得跟踪文件名

select rtrim(c.value,'/')||'/'||d.instance_name||'_ora_'||ltrim(to_char(a.spid))||'.trc'
from v$process a,v$session b,v$parameter c,v$instance d
where a.addr=b.paddr
and b.audsid=sys_context('userenv','sessionid')
and c.name='user_dump_dest';

RTRIM(C.VALUE,'/')||'/'||D.INSTANCE_NAME||'_ORA_'||LTRIM(TO_CHAR(A.SPID))||'.TRC
--------------------------------------------------------------------------------
/home/oracle/admin/ora10/udump/ora10_ora_18864.trc

3.创建TKPROF报告
tkprof /home/oracle/admin/ora10/udump/ora10_ora_16424.trc /tmp/t.txt

注意 /home/oracle/admin/ora10/udump/ora10_ora_16424.trc 这个文件只能是
ORACLE 用户才能读出

4.读报告
vi /tmp/t.txt

 

 

 

  1. ---运行程序
  2. select count(*) 
  3. from
  4.  t
  5. 查询和执行统计
  6.              执行次数  CPU时间量 占用时间  磁盘IO   查询       当前          行
  7. call调用     count       cpu    elapsed       disk      query    current        rows
  8. -------     ------  -------- ---------- ---------- ---------- ----------  ----------
  9. Parse分析        1      0.00       0.00          0          0          0           0
  10. Execute执行      1      0.00       0.00          0          0          0           0
  11. Fetch提取        2      0.04       1.63        689        708          0           1
  12. -------     ------  -------- ---------- ---------- ---------- ----------  ----------
  13. total合计        4      0.04       1.64        689        708          0           1
  14. Misses in library cache during parse: 1 高速缓冲错误1
  15. Optimizer mode: ALL_ROWS优化方式
  16. Parsing user id: 54  分析用户ID
  17. Rows     Row Source Operation
  18. -------  ---------------------------------------------------
  19.          cr为一致方式读取,显示一致读取数(逻辑I/O) pr 是物理读取 pw为物理写入 time=(以百万分之一秒计占用时间)
  20.       1  SORT AGGREGATE (cr=708 pr=689 pw=0 time=1638784 us)
  21.   51018   TABLE ACCESS FULL T (cr=708 pr=689 pw=0 time=765387 us)
  22. 等候时间
  23. Elapsed times include waiting on following events:
  24.   Event waited on                             Times   Max. Wait  Total Waited
  25.   ----------------------------------------   Waited  ----------  ------------
  26.   SQL*Net message to client                       2        0.00          0.00
  27.   db file scattered read                         51        0.07          1.60
  28.   SQL*Net message from client                     2        0.00          0.00
  29. ********************************************************************************

 

抱歉!评论已关闭.