Profiling Stored Functions in Oracle

Is it possible in Oracle11g to profile stored functions that are called in plsql code from the SELECT ... INTO ... ?

For profiling, I use the DBMS_HPROF utility. After running the profiling in the DBMSHP_FUNCTION_INFO table DBMSHP_FUNCTION_INFO I can see everything except the functions that were called inside SELECT ... INTO ...

+6
source share
3 answers

In 11g2, my HPROF results include strings in package functions called

 SELECT my_pkg.my_func(x) INTO y FROM dual; 

Now I do not see every line - usually only SQL statements. For example, I profiled "main_test" in the following package.

 ALTER SESSION SET PLSQL_OPTIMIZE_LEVEL=0; CREATE OR REPLACE PACKAGE matt_t1 AS FUNCTION p (a NUMBER) RETURN NUMBER; PROCEDURE main_test; END matt_t1; CREATE OR REPLACE TYPE my_num_tab_type IS TABLE OF NUMBER; CREATE OR REPLACE PACKAGE BODY matt_t1 AS FUNCTION p (a NUMBER) RETURN NUMBER IS x NUMBER := 0; t my_num_tab_type; BEGIN t := new my_num_tab_type(); for i in 1..10000 loop x := ln (x+i); t.extend(); t(i) := x; END loop; SELECT SUM(column_value) INTO x FROM TABLE(t); RETURN x; END p; PROCEDURE main_test IS x NUMBER; BEGIN FOR i IN 1 .. 100 LOOP x := matt_t1.p (i); DBMS_OUTPUT.put_line (x); END LOOP; END main_test; END matt_t1; 

In the HPROF results, I see entries for

 SELECT SUM(column_value) INTO x FROM TABLE(t); 

But not, for example,

 x := ln (x+i); 

I get the same results if I call the p function as SELECT INTO vs if I just assign the value directly through PL / SQL. In any case, all the time for 10,000 natural logarithms is kept under the HPROF heading for the line

 FUNCTION p (a NUMBER) 

I also get the same results if I just profile the call directly in MATT_T1.P ().

So, I think that HPROF may have some restrictions regarding what types of PL / SQL lines it can include, but it seems to me that the calling method (SELECT..INTO) has nothing to do with it.

+3
source

I see the whole function in DBMSHP_FUNCTION_INFO with the exception of the sql function, because the Dbms_hprof dosen't trace sql function (e.g. ln, nvl ... etc.).

 create or replace function addNum(p1 number,p2 number) return as begin return p1+p2; end; BEGIN sys.DBMS_HPROF.START_PROFILING('TMP', 'test.trc'); END; / declare n number; n2 number; n3 number; BEGIN select sum(1),max(1),ln(1) into n,n2,n3 from dual; select max(addNum(1,level)) into n from dual connect by level<10; END; / BEGIN DBMS_HPROF.STOP_PROFILING; END; / 

So let's get into the trc file.
select sum(1) into n from dual; denoted as P#C SQL."".""."__static_sql_exec_line6" #6 , which means that static sql was executed on line 6.
select max(addNum(1,level)) into n from dual connect by level<10; this selection starts at the beginning of P#C SQL."".""."__static_sql_exec_line7" #7 on line 6, and then it switches to PLSQL VM to smooth out the result of the addition. __plsql_vm and ADDNUM appere 9 times in trc.

 P#C SQL."".""."__static_sql_exec_line7" #7 P#X 3338 P#C PLSQL."".""."__plsql_vm" <--switch context P#X 2 P#C PLSQL."ALUKASIEWICZ"."ADDNUM"::8."ADDNUM"#a7f835561d3611ed #1 <-- execut function 
+1
source

Did you try to enable the profiler inside the stored function? This can create a separate trace (another runId).

0
source

All Articles