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