Вы находитесь на странице: 1из 3

1. Use display statements - You can insert dbms_output.put_line and utl_file.

put_line statements
to display variable states. But advanced PL/SQL can be problematic. The display components of
PL/SQL (dbms_output and utl_file) provide limited PL/SQL debugging capabilities.
2. dbms_debug Utility – It is a useful programming utility for PL/SQL Developers.
3. Use dbms_profiler - The dbms_profiler package can aid in PL/SQL debugging.
4. Conditional Compilation - In Oracle10g, PL/SQL conditional compilation is ideal for debugging
PL/SQL
5. PL/SQL debugger - You can use Oracle's PL/SQL debugger (part of the free SQL Developer suite)
to step through the PL/SQL code, one line at a time, and find any error:

Note:- dbms_profiler is to PL/SQL, what tkprof and Explain Plan are to SQL.

Using dbms_profiler(was used in agcs)- http://www.dba-oracle.com/t_dbms_profiler.htm


(Incomplete detail here)

The dbms_profiler package is a built-in set of procedures to capture performance information from
PL/SQL. It gathers information at the PLSQL virtual machine level. Ex- total number of times each line
has executed and amount of time spent on executing that line. Also min and max time that have been
spent on a particular execution of that line.

The dbms_profiler package has these procedures:


Now after Profiler get setup and execute the profiler for any procedure. Three tables are
created that can be joined to analyze the profiler data.
PLSQL_PROFILER_RUNS- This contains information relared to the profileing sessions. Run-
id,run_date,Total_duration,run_owner

PLSQL_PROFILER_UNITS – Holds details of each unit that run during a profiler run.

PLSQL_PROFILER_DATA – Execution statistics for each line of code contained in the PLSQL code.

dbms_profiler.start_profiler

dbms_profiler.flush_data

dbms_profiler.stop_profiler

Oracle - Starting a Profiling Session

The profiler does not begin capturing performance information until the call to start_profiler is
executed.

SQL> exec dbms_profiler.start_profiler ('Test of raise procedure by Scott');

Flushing Data during a Profiling Session

The flush command enables the developer to dump statistics during program execution without
stopping the profiling utility. The only other time Oracle saves data to the underlying tables is when
the profiling session is stopped, as shown below:

SQL> exec dbms_profiler.flush_data();

PL/SQL procedure successfully completed.


Stopping a Profiling Session

Once the developer stops the profiler, all the remaining (unflushed) data is loaded into the profiler
tables.

Now the below query can be use to get program running


execution profiler data for each of the line of code-
SELECT c.line#, u.text, c.total_occur,

c.total_time /1000000000 line_tot_secs,

c.min_time /1000000000 MIN_TIME,

c.max_time /1000000000 MAX_TIME,

a.run_total_time/1000000000 Tot_run_secs,

a.run_owner

FROM plsql_profiler_runs a, plsql_profiler_units b, plsql_profiler_data c, user_source u

WHERE a.runid =b.runid AND a.runid =c.runid AND b.unit_name=u.name AND c.line# =u.line;

The basic idea behind profiling with dbms_profiler is for the developer to understand where their code
is spending the most time, so they can detect and optimize it. The profiling utility allows Oracle to
collect data in memory structures and then dumps it into tables as application code is executed.
dbms_profiler is to PL/SQL, what tkprof and Explain Plan are to SQL.

Once you have run the profiler, Oracle will place the results inside the dbms_profiler tables.

The dbms_profiler procedures are not a part of the base installation of Oracle. Two tables need to be
installed along with the Oracle supplied PL/SQL package. In the $ORACLE_HOME/rdbms/admin
directory, two files exist that create the environment needed for the profiler to execute.

Вам также может понравиться