{ORACLE_HOME}/rdbms/admin/dbmspbp.sql
-- also review
{ORACLE_HOME}/plsql/demo/profsum.sql
First Available
8.1.5
Constants
Return values from DBMS_PROFILER functions
Name
Data Type
Value
error_io
BINARY_INTEGER
2
error_param
BINARY_INTEGER
1
error_version
BINARY_INTEGER
-1
major_version
BINARY_INTEGER
2
minor_version
BINARY_INTEGER
0
success
BINARY_INTEGER
0
Dependencies
DBMS_PROFILER_LIB
Exceptions
Exception Name
Error Code
Reason
profiler_error
ORA-06528
Parameter or I/O error
version_mismatch
ORA-06529
Incorrect profiler version for database
System Privileges
GRANT create session TO
<schema_name>;
GRANT create procedure TO <schema_name>;
GRANT create sequence TO <schema_name>;
GRANT create table TO <schema_name>;
GRANT create view TO <schema_name>;
GRANT create session TO
uwclass;
GRANT create procedure TO uwclass;
GRANT create sequence TO uwclass;
GRANT create table TO uwclass;
GRANT create view TO uwclass;
FLUSH_DATA
Flushes the Profiler buffer
to the Profiler tables
Overload 1
dbms_profiler.flush_data RETURN BINARY_INTEGER;
See PAUSE_PROFILER Demo
Overload 2
dbms_profiler.flush_data;
SELECT dbms_profiler.flush_data
FROM dual;
GET_VERSION
Returns the Profiler API
version
dbms_profiler.get_version(
major OUT BINARY_INTEGER,
minor OUT BINARY_INTEGER);
Roll up and calculate the
total time usage for a specific unit that has been part of a run
dbms_profiler.rollup_unit(
run_number IN NUMBER,
unit IN NUMBER);
-- executes the
following code
UPDATE plsql_profiler_units
SET total_time = (
SELECT SUM(total_time)
FROM plsql_profiler_data
WHERE runid = run_number
AND unit_number = unit);
SELECT *
FROM plsql_profiler_units;
exec dbms_profiler.rollup_unit(8, 3);
START_PROFILER
Start Profiler data collection
in the current session
Overload 1
dbms_profiler.start_profiler(
run_comment IN VARCHAR2 := SYSDATE,
run_comment1 IN VARCHAR2 := '',
run_number OUT BINARY_INTEGER)
RETURN BINARY_INTEGER;
TBD
Overload 2
dbms_profiler.start_profiler(
run_comment IN VARCHAR2 := SYSDATE,
run_comment1 IN VARCHAR2 := '',
run_number OUT BINARY_INTEGER);
TBD
Overload 3
dbms_profiler.start_profiler(
run_comment IN VARCHAR2 := SYSDATE,
run_comment1 IN VARCHAR2 := '')
RETURN BINARY_INTEGER;
TBD
Overload 4
dbms_profiler.start_profiler(
un_comment IN VARCHAR2 := SYSDATE,
run_comment1 IN VARCHAR2 := '');
INSERT INTO sources_import
(sourceno, sizeno, status, latitude, longitude, testfor)
VALUES
(Fld1, Fld2, Fld3, Fld4, Fld5, Fld6);
ELSE
vLineNo := 2;
END IF;
END LOOP;
COMMIT;
utl_file.fclose(v_InHandle);
EXCEPTION
WHEN utl_file.invalid_mode THEN
RAISE_APPLICATION_ERROR (-20051, 'Invalid Option');
WHEN utl_file.invalid_path THEN
RAISE_APPLICATION_ERROR (-20052, 'Invalid Path');
WHEN utl_file.invalid_filehandle THEN
RAISE_APPLICATION_ERROR (-20053, 'Invalid
Filehandle');
WHEN utl_file.invalid_operation THEN
RAISE_APPLICATION_ERROR (-20054, 'Invalid operation');
WHEN utl_file.read_error THEN
RAISE_APPLICATION_ERROR (-20055, 'Read Error');
WHEN utl_file.internal_error THEN
RAISE_APPLICATION_ERROR (-20057, 'Internal Error');
WHEN OTHERS THEN
RAISE;
END;
EXCEPTION
WHEN NoFileToLoad THEN
dbms_output.put_line('No File To Load Was Found');
WHEN OTHERS THEN
MyErrm := SQLERRM;
dbms_output.put_line(MyErrm);
END load_sources_import;
/
Comma To Table Procedure
CREATE OR REPLACE PROCEDURE c2t_demo IS
my_table dbms_utility.uncl_array;
cnt BINARY_INTEGER;
c_string VARCHAR2(250);
CURSOR t_cur IS
SELECT readline
FROM gtt_c2t;
t_rec t_cur%ROWTYPE;
BEGIN
OPEN t_cur;
LOOP
FETCH t_cur INTO t_rec;
EXIT WHEN t_cur%NOTFOUND;
-- move the value from the cursor to the VARCHAR2 variable
c_string := t_rec.readline;
-- use the built-in package to break it up
dbms_utility.comma_to_table(c_string,
cnt, my_table);
-- use TRANSLATE to remove the single and double quotes
my_table(1) := TRANSLATE(my_table(1), '1"''', '1');
my_table(2) := TRANSLATE(my_table(2), '1"''', '1');
my_table(3) := TRANSLATE(my_table(3), '1"''', '1');
my_table(4) := TRANSLATE(my_table(4), '1"''', '1');
my_table(5) := TRANSLATE(my_table(5), '1"''', '1');
my_table(6) := TRANSLATE(my_table(6), '1"''', '1');
INSERT INTO sources_import
(sourceno, sizeno, status,
latitude, longitude, testfor)
VALUES
(my_table(1), my_table(2), my_table(3),
my_table(4), my_table(5), my_table(6));
END LOOP;
COMMIT;
CLOSE t_cur;
END c2t_demo;
/
First Procedure To Load
Intermediary Table And
Replace Single Quotes
With Double Quotes
vInHandle utl_file.file_type;
BEGIN
StartTime := dbms_utility.get_time;
vInHandle := utl_file.fopen(vLoc, vFileName, 'r');
LOOP
BEGIN
utl_file.get_line(vInHandle, vNewLine);
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT;
END;
-- find location of the delimiting commas
BEGIN
IF vFirstLine <> 1 THEN
INSERT INTO gtt_c2t
(readline)
VALUES
(vNewLine);
END IF;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END;
END LOOP;
-- close the text file
utl_file.fclose(vInHandle);
DELETE FROM gtt_c2t
WHERE readline LIKE '%SOURCENO%';
UPDATE gtt_c2t
SET readline = TRANSLATE(readline, 'A''', 'A"');
c2t_demo; -- 2nd procedure that parses record
EXCEPTION
WHEN utl_file.invalid_mode THEN
RAISE_APPLICATION_ERROR(-20051, 'Invalid Option');
WHEN utl_file.invalid_path THEN
RAISE_APPLICATION_ERROR(-20052, 'Invalid Path');
WHEN utl_file.invalid_filehandle THEN
RAISE_APPLICATION_ERROR(-20053, 'Invalid Filehandle');
WHEN utl_file.invalid_operation THEN
RAISE_APPLICATION_ERROR(-20054, 'Invalid operation');
WHEN utl_file.read_error THEN
RAISE_APPLICATION_ERROR(-20055, 'Read Error');
WHEN utl_file.internal_error THEN
RAISE_APPLICATION_ERROR(-20057, 'Internal Error');
WHEN OTHERS THEN
RAISE;
END load_c2t_test;
/
TYPE profarray IS TABLE OF sources_import%ROWTYPE
INDEX BY BINARY_INTEGER;
l_data profarray;
BEGIN
v_InHandle := utl_file.fopen(vLoc, vFileName, 'r');
vLineNo := 1;
LOOP
BEGIN
utl_file.get_line(v_InHandle, vNewLine);
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT;
END;
vLineNo := vLineNo+1;
END LOOP;
utl_file.fclose(v_InHandle);
FORALL i IN 1..l_data.COUNT
INSERT INTO sources_import VALUES l_data(i);
DELETE FROM sources_import WHERE sourceno = 'SOURCENO';
COMMIT;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END blended;
/
Profiling Demo
Profiler Run
set serveroutput on
-- BEGIN RUN 1: BASIC CURSOR LOOP
-- clean out the profiler tables
exec profreset
-- clean out the test tables
TRUNCATE TABLE sources_import;
-- run the procedure to put it into memory
exec load_sources_import;
SELECT *
FROM sources_import;
-- truncate the table before starting again
TRUNCATE TABLE sources_import;
-- start the profiler
exec dbms_profiler.start_profiler('A')
-- run the procedure
exec load_sources_import
-- stop the profiler
exec dbms_profiler.stop_profiler;
-- get the report
@c: emp\profiler.sql
-- save the report as run1.txt
-- Examine profiler tables
set linesize 121
-- view raw profiler data
SELECT runid, unit_number, line#, total_occur, total_time,
min_time, max_time
FROM plsql_profiler_data;
SELECT runid, related_run, run_owner, run_date, run_comment,
run_total_time, run_system_info
FROM plsql_profiler_runs;
col unit_type format a20
col unit_name format a25
SELECT runid, unit_number, unit_type, unit_owner, unit_name,
unit_timestamp, total_time
FROM plsql_profiler_units;
SELECT dump(unit_timestamp)
FROM plsql_profiler_units;
-- BEGIN RUN 2: COMMA_TO_TABLE
-- clean out the profiler tables
exec profreset
-- clean out the test tables
TRUNCATE TABLE sources_import;
-- run the procedure to put it into memory
exec load_c2t_test;
SELECT * FROM sources_import;
-- clean out the test tables
TRUNCATE TABLE sources_import;
-- start the profiler
exec dbms_profiler.start_profiler('B')
-- run the procedure
exec load_c2t_test
-- stop the profiler
exec dbms_profiler.stop_profiler;
-- get the report
@c: emp\profsum.sql
-- save the report as run2.txt
-- BEGIN RUN 3: ARRAY PROCESSING
-- clean out the profiler tables
exec profreset
-- clean out the test tables
TRUNCATE TABLE sources_import;
-- run the procedure to put it into memory
exec array_load;
SELECT *
FROM sources_import;
-- truncate the table before starting again
TRUNCATE TABLE sources_import;
-- start the profiler
exec dbms_profiler.start_profiler('C')
-- run the procedure
exec array_load
-- stop the profiler
exec dbms_profiler.stop_profiler;
-- get the report
@c: emp\profsum.sql
-- save the report as run3.txt
-- BEGIN RUN 4: BLENDED PROCESSING
-- clean out the profiler tables
exec profreset
-- clean out the test tables
TRUNCATE TABLE sources_import;
-- run the procedure to put it into memory
exec blended;
SELECT *
FROM sources_import;
-- truncate the table before starting again
TRUNCATE TABLE sources_import;
-- start the profiler
exec dbms_profiler.start_profiler('D')
-- run the procedure
exec blended
-- stop the profiler
exec dbms_profiler.stop_profiler;