日期:2014-05-16 浏览次数:20728 次
使用图形化界面工具实施PL/SQL Profiler 易用直观,但是并不是所有的环境都可以使用图形界面软件连接到数据库。对于只能在命令行下进行剖析又需要直观呈现剖析结果的情形,Oracle为我们提供了脚本来直接生成html文档。本文即是基于这种情形进行演示并加以说明。
有关PL/SQL Profiler的文章可以参考:
使用 DBMS_PROFILER 定位 PL/SQL 瓶颈代码
对比 PL/SQL profiler 剖析结果
使用PL/SQL Developer剖析PL/SQL代码
1、实施PL/SQL Profiler步骤
--下面的步骤直接参考了Metalink文档(ID 243755.1)
a、If needed, create the PL/SQL Profiler Tables under your application schema: @?/rdbms/admin/proftab.sql
b、If needed, install the DBMS_PROFILER API, connected as SYS: @?/rdbms/admin/profload.sql
c、Start PL/SQL Profiler in your application: EXEC DBMS_PROFILER.START_PROFILER('optional comment');
d、Execute your transaction to be profiled. Calls to PL/SQL Libraries are expected.
e、Stop PL/SQL Profiler: EXEC DBMS_PROFILER.STOP_PROFILER;
f、Connect as your application user, execute script profiler.sql provided in this document: @profiler.sql
g、Provide to profiler.sql the "runid" out of a displayed list.
h、Review HTML report generated by profiler.sql.
2、演示PL/SQL Profiler
--由于我们已经配置好了Profiler,因此下面直接进行剖析 a、开始Profiler XXX_ADMIN@SYBO2> EXEC DBMS_PROFILER.START_PROFILER('PREPARE TRADE TBL '); PL/SQL procedure successfully completed. b、执行需要剖析的过程 XXX_ADMIN@ORAID> DECLARE 2 TRADE_DATE_IN VARCHAR2(32767); 3 ERR_NUM NUMBER; 4 ERR_MSG VARCHAR2(32767); 5 6 BEGIN 7 TRADE_DATE_IN := '20130911'; 8 ERR_NUM := NULL; 9 ERR_MSG := NULL; 10 11 XXX_ADMIN.XXX_GEN_DTL_PKG.PREPARE_TRADE_DTL_TBL ( TRADE_DATE_IN, ERR_NUM, ERR_MSG ); 12 COMMIT; 13 END; 14 / PL/SQL procedure successfully completed. c、停止profiler XXX_ADMIN@ORAID> EXEC DBMS_PROFILER.STOP_PROFILER; PL/SQL procedure successfully completed. --Author : Leshami --Blog : http://blog.csdn.net/leshami d、生成Profiler报告 XXX_ADMIN@ORAID> @profiler RUNID RUN_OWNER RUN_DATE RUN_COMMENT ------ ------------------------- --------------- ------------------------------ 3 XXX_ADMIN 29-SEP-13 11:53 PREPARE TRADE TBL Parameter 1: RUNID (required) Enter value for 1: 3 --->输入对应的Profiler的运行ID Value passed: ~~~~~~~~~~~~ RUNID: "3" PROFILER file has been created: profiler_SID_xxxxxdb01uv_10.2.0.3.0_20130929_115525.html.
3、Profiler剖析报告结果样例
单击相关的top下对应的id,或者Total Time对应的链接即可跳转到相应的代码部分,如下:
更多参考<