Académique Documents
Professionnel Documents
Culture Documents
1 of 11
http://dbaora.com/plsql-hierarchical-profiler-oracle-database-11g-release...
3/29/2015 6:32 PM
2 of 11
http://dbaora.com/plsql-hierarchical-profiler-oracle-database-11g-release...
NOTE Oracle sqldeveloper as default use directory plshprof_dir for profiler so I use the name to be consistent with
Oracle sqldeveloper
connect / as sysdba
create directory plshprof_dir as 'c:\temp';
grant read, write on directory plshprof_dir to tomasz;
3. Create hierarchical profiler tables in user schema. Call script dbmshptab.sql from $ORACLE_HOME.
connect tomasz@ora11g
@?/rdbms/admin/dbmshptab.sql
Verification
New objects are created in user schema
OBJECT_TYPE
------------------TABLE
TABLE
SEQUENCE
TABLE
Table
Description
DBMSHP_RUNS
DBMSHP_FUNCTION_INFO
DBMSHP_PARENT_CHILD_INFO
Testing
First we need to create test code
3/29/2015 6:32 PM
3 of 11
http://dbaora.com/plsql-hierarchical-profiler-oracle-database-11g-release...
Now we can run hierarchical profiler. It will create file with collected statistics. File is created in directory specified by
3/29/2015 6:32 PM
4 of 11
http://dbaora.com/plsql-hierarchical-profiler-oracle-database-11g-release...
parameter location.
begin
dbms_hprof.start_profiling
( location => 'PLSHPROF_DIR',
filename => 'plshprof_file.txt' );
test_pkg.test_1_prc;
dbms_hprof.stop_profiling;
end;
/
Here is part of the generated file. Remember it has been created in directory PLSHPROF_DIR so you need to have access
to review it.
P#V
P#!
P#C
P#X
P#C
P#X
P#C
P#X
P#C
P#X
P#R
P#X
P#C
P#X
P#R
...
P#C
P#X
P#R
P#X
P#C
P#X
P#R
P#X
P#R
SQL."TOMASZ"."TEST_PKG"::11."__static_sql_exec_line17" #17
37831
17
SQL."TOMASZ"."TEST_PKG"::11."__static_sql_exec_line17" #17
40269
11
3/29/2015 6:32 PM
5 of 11
http://dbaora.com/plsql-hierarchical-profiler-oracle-database-11g-release...
P#X 1
P#R
P#C PLSQL."SYS"."DBMS_HPROF"::11."STOP_PROFILING"#980980e97e42f8ec #59
P#R
P#! PL/SQL Timer Stopped
set serveroutput on
declare
v_runid number;
begin
v_runid := dbms_hprof.analyze
( location
=> 'PLSHPROF_DIR',
filename
=> 'plshprof_file.txt',
run_comment => 'First run' );
dbms_output.put_line('Run id: '||v_runid);
end;
/
anonymous block completed
Run id: 1
DBMS_HPROF.ANALYZE (
location
VARCHAR2,
filename
VARCHAR2,
summary_mode
BOOLEAN
trace
VARCHAR2
skip
PLS_INTEGER
collect
PLS_INTEGER
DEFAULT
DEFAULT
DEFAULT
DEFAULT
FALSE,
NULL,
0,
NULL,
3/29/2015 6:32 PM
6 of 11
run_comment
RETURN NUMBER;
VARCHAR2
http://dbaora.com/plsql-hierarchical-profiler-oracle-database-11g-release...
DEFAULT NULL)
Parameters description
location directory for profiler data
filename file name with profiler data
summary_mode default FALSE detailed analysis are done. If TRUE only top-level analysis are done
trace analyze only specified part of code. As default is NULL so analyzes are done for entire run. The trace entry
must be specified in a special quoted qualified format (including the schema name, module name & function name) as
in for example, SCOTT.PKG.FOO or ..__plsql_vm. If multiple overloads exist for the specified name, all of
them will be analyzed.
skip used only if trace parameter is specified. Specifies how much first invocations are skipped. The default is 0.
collect used only if trace is specified. Specified how much invocations are traced. Starts from skip+1th invocation.
The default is 1.
run_comment user comment
Review data in tables
DBMSHP_RUNS shows in micro seconds how much time it took to complete our procedure
DBMSHP_FUNCTION_INFO shows aggregated information for each profiled function. For example you can find out how
much time was consumed by a function or subprogram calls from the function.
select
owner, module, type, function, line#, namespace, calls,
function_elapsed_time, subtree_elapsed_time
from dbmshp_function_info
where runid=1;
OWNER MODULE
TYPE
FUNCTION
LINE# NAMESPACE CALLS FUNCTION_ELAPSED
------ ---------- ------------ ------------------------ ----- --------- ----- ---------------SYS
DBMS_HPROF PACKAGE BODY STOP_PROFILING
59 PLSQL
1
3/29/2015 6:32 PM
7 of 11
SYS
TOMASZ
TOMASZ
TOMASZ
TOMASZ
TOMASZ
DBMS_LOCK
TEST_PKG
TEST_PKG
TEST_PKG
TEST_PKG
TEST_PKG
PACKAGE
PACKAGE
PACKAGE
PACKAGE
PACKAGE
PACKAGE
BODY
BODY
BODY
BODY
BODY
BODY
http://dbaora.com/plsql-hierarchical-profiler-oracle-database-11g-release...
SLEEP
TEST_1_PRC
TEST_2_PRC
TEST_3_PRC
__static_sql_exec_line17
__static_sql_exec_line29
197
3
9
23
17
29
PLSQL
PLSQL
PLSQL
PLSQL
SQL
SQL
5
1
1
1
5
5
49
1
2
select
lpad(' ', level, ' ')||pf.function||' -> '||cf.function call,
pc.subtree_elapsed_time,
pc.function_elapsed_time,
pc.calls,
cf.line#
from
(select * from dbmshp_parent_child_info where runid=1) pc,
dbmshp_function_info pf,
dbmshp_function_info cf
where pc.runid=pf.runid
and pc.parentsymid=pf.symbolid
and pc.runid=cf.runid
and pc.childsymid=cf.symbolid
connect by prior pc.childsymid=pc.parentsymid
start with pc.parentsymid = 3;
CALL
SUBTREE_ELAPSED_TIME FUNCTION_ELAPSED_TIME
CAL
------------------------------------------ -------------------- --------------------- -------TEST_1_PRC -> TEST_2_PRC
5412750
93
TEST_2_PRC -> TEST_3_PRC
5228468
190
TEST_3_PRC -> SLEEP
4971896
4971896
TEST_3_PRC -> __static_sql_exec_line29
256382
256382
TEST_2_PRC -> __static_sql_exec_line17
184189
184189
plshprof tool
Another option to analyze your profiled code is to use command line utility plshprof.
It generates simple HTML reports directly from the raw profiler data, so can be used instead of loading data into Oracle
tables.
$ORACLE_HOME\bin\plshprof
PLSHPROF: Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 64bit Production
3/29/2015 6:32 PM
8 of 11
http://dbaora.com/plsql-hierarchical-profiler-oracle-database-11g-release...
(no default)
(default=0)
plshprof c:\temp\plshprof_file.txt
PLSHPROF: Oracle Database 12c
Enterprise Edition Release 12.1.0.1.0 - 64bit Production
[7 symbols processed]
[Report written to 'c:\temp\plshprof_file.txt.html']
You can review output in browser to get details. Its much easier then review data from tables.
Example screens
3/29/2015 6:32 PM
9 of 11
http://dbaora.com/plsql-hierarchical-profiler-oracle-database-11g-release...
Sqldeveloper support
Sqldeveloper fully supports PL/SQL Hierarchical profiler and with a few simple clicks you can quickly get profiler data for
your code.
You just need to select code that you want to profile and select Profile option. There are some extra screen (Im not
showing it here) where you can define more details what to profile. Once data are collected you can see it in tab Profiles
for your procedure, function, package etc.
Sqldeveloper requires to create profiler tables in own schema and expects directory plshprof_dir. You are informed about
the requirements when you first try to profile your data.
3/29/2015 6:32 PM
10 of 11
http://dbaora.com/plsql-hierarchical-profiler-oracle-database-11g-release...
Have a fun
Tomasz
LIK E TH IS :
3/29/2015 6:32 PM
11 of 11
http://dbaora.com/plsql-hierarchical-profiler-oracle-database-11g-release...
This entry was posted in Uncategorized by admin. Bookmark the permalink [http://dbaora.com/plsql-hierarchicalprofiler-oracle-database-11g-release-2-11-2/] .
3/29/2015 6:32 PM