Oracle PL/SQL Profiler应用指南

** Oracle PL/SQL Profiler ** ** 应用指南 ** **

**

Profiler 是 ORACLE PL/SQL 的一个调试优化跟踪方案的应用

相对 sqltrace+tkprof 工具调试优化跟踪方案来说 , Profiler 有最直观更方便的优点,因为不需要生成和读取服务器端的跟踪文件,它是将跟踪数据全部存储的数据库表里,所以也得到了一些第三方工具的支持,如 PL/SQL DEVELOPER 。

注: Profiler 生成的跟踪信息远远没有 trace 生成的详细,它没有执行计划、没有 CPU 及 IO 信息,它只是生成主要的执行时间信息,所以分析起来比较快,比较直观,可以让我们以最快的时间定位要优化的 SQL 。

下面将介绍 ORACLE PL/SQL profiler 的详细应用

1 、安装

安装总共要运行两个 ORALCE 自带的服务脚本

( 1 )、创建 profiler 的基础结构

@$ORACLE_HOME\rdbms\admin\proftab.sql;

proftab.sql 会在当前用户下创建如下表结构及序列:

plsql_profiler_runs - profiler 运行信息

plsql_profiler_units - profiler 每个单元信息

plsql_profiler_data - profiler 每个单元的详细数据

plsql_profiler_runnumber 用来生成 profiler 唯一运行编号的序列

( 2 )、创建数据库服务运行包

@$ORACLE_HOME\rdbms\admin\profload.sql;

profload.sql 主要是创建 sys.dbms_profiler 包

包主要的函数过程有

start_profiler,

stop_profiler,

pause_profiler,

resume_profiler,

flush_data,

internal_version_check,

get_version,

rollup_unit,

rollup_run

主要使用的函数是

start_profiler-- 启动 profiler

stop_profiler-- 停止 profiler

其它为一些辅助函数

2 、应用实例

declare

v_run_number integer;

v_temp1 integer;

begin

--1. 启动 profiler

sys.dbms_profiler.start_profiler(run_number => v_run_number);

-- 显示当前跟踪的运行序号 ( 后面查询要用 )

dbms_output.put_line('run_number:'||v_run_number);

--2. 运行要跟踪的 PL/SQL

--select count(*) into v_temp1 from scott.emp t;

--select count(*) into v_temp1 from scott.dept t;

--3. 停止 profiler

sys.dbms_profiler.stop_profiler;

end;

3 、查询结果

select u.unit_name,-- 单元名称

d.line,-- 代码行号

d.total_time,-- 总共运行时间 ( 单位: 10000 亿分之一秒 )

d.total_occur,-- 总共运行次数

d.min_time,-- 最小运行时间

d.max_time,-- 最大运行时间

s.text-- 源代码

from plsql_profiler_data d, sys.all_source s, plsql_profiler_units u

where d.runid = 33-- 运行号 v_run_number

and u.runid = d.runid

and d.unit_number = u.unit_number

and d.total_occur <> 0

and s.type(+) = u.unit_type

and s.owner(+) = u.unit_owner

and s.name(+) = u.unit_name

and d.line# = nvl(s.line, d.line#)

order by u.unit_number, d.line#

以上介绍的是通过手工方法应用 Profiler ,使用相对比较烦杂,最后查询也不直观,下面将详细介绍在 PL/SQL DEVELOPER 应用 Profiler

** 1、 ** ** 打开 test window

**

方法一、新建一个 test window

方法二、选择要跟踪运行的过程,快捷菜单 test ,如下图所示

在 test window 中输入你要执行的 PL/SQL 脚本

** 2 ** ** 、打开 Profiler ,如下图所示

**

如果在打开 Profiler 出现出错提示则说明你没有安装 Profiler ,详细安装步骤见上文的安装过程。

** 3 ** ** 、 F8 执行脚本,执行完成后,切换到 profiler 选项卡,如下图所示 **

**

**

每列的详细意义如下:

unit -- 单元名称

line-- 代码行号

total time-- 总共运行时间 ( 本行代码的执行时间与最长代码执行时间的百分比图 )

occurrences-- 总共运行次数

text-- 源代码

Average time— 平均运行时间

maximum time-- 最大运行时间

minimum time-- 最小运行时间

列表中显示的源代码只显不一行,如果要定位则可以在对应的行中打开右键,选择

[Go to unit line] ,这样就会直接跳到对应的源代码位置。

工具栏

1、 显示配置对话框

2、 刷新

3、 删除当前运行号的数据

4 、 Run :显示当前的系统的所有 Profiler 列表,缺省为当前的跟踪

5 、 Unit :显示本次跟踪的单元列表信息(执行时间),缺省为所有单元的执行时间

** 配置 PL/SQL Developer 的 Profiler 选项,如下图所示 **

**

**

Available Columns :可用列

Selected Columns :选择要查看的列

Time units :时间单位 ( 秒、毫秒、微秒 )

Show 0 occurrences :是否显示执行 0 次的处理语句

Graphical time display :用图形显示处理时间的颜色深度百分比

叶正盛

2005-04-17

Published At
Categories with 数据库类
comments powered by Disqus