oracle| Performance
Oracle ' s dbms_profiler:pl/sql performance tuning
Dbms_profiler Package Examples
Here's a simple example of how I can use configuration, run a configuration file to test the performance of the following routines. The custom script used by the routine is immediately followed.
1. Create the process.
Create or Replace procedure Am_perf_chk (pi_seq in number,
Pio_status in Out nocopy varchar2) is
L_dat Date: = Sysdate;
Begin
If trunc (l_dat) = ' 21-sep-02 ' and pi_seq = 1 Then
Pio_status: = ' OK ';
Else
Pio_status: = ' Invalid tape loaded ';
End If;
exception
When others then
Pio_status: = ' Error in Am_perf_chek ';
End
2. Using the configuration file to invoke the routine
Replace the previous routine, execute the Call_profiler.sql script (see below for scripting code), and pass in the pi_seq=2
Sql> @d:\am\call_profiler.sql
Profiler started
Invalid Tape Loaded
Pl/sql procedure successfully completed.
Profiler stopped
Profiler flushed
Runid:8
3. Assessment of Implementation time:
Execute Eavluate_profiler_results.sql script, get time statistics
4. As you can see, the third line of execution time is raised to 86 milliseconds. But changing the IF statement and then performing the procedure above will result in new results:
5. As you can see, the third line of execution time in this scenario is reduced from 86 milliseconds to 8 milliseconds, the extra time is caused by the built-in trunc () function. If the first condition is false, the trunc () function is not executed. This is just a simple example, when you're testing a routine that's bigger , the challenges you face are even greater.
This configuration result also shows how many lines of code are overwritten during execution, allowing us to know the scope of code in performance monitoring. If any pl/sql block performance problems, it can also extract the various scenarios of the code being executed and check the configuration results, so as to identify the problem.
6. For a particular scenario, if a particular piece of code is executed, a reasonable analysis can be obtained, even if the code is not running at all.
Creation of the environment
The Dbms_profiler package is not installed automatically when the default installation or database is created, and the DBA creates it with a profload.sql script. Create a table that stores statistics with a larger or a single user. If
Created with a user such as SYS, the DML permissions are granted to other users, and a common shorthand name is created for those tables.
The table is created as follows:
Plsql_profiler_runs table: Run details for pl/sql configuration.
Plsql_profiler_units table: Information for each library unit in a run.
Plsql_profiler_data table: Cumulative data for all profiles at run time.
The Plsql_profiler_runnumber sequence provides a Runid
Running and interpreting configuration data
Oracle provides three tables for counting, populating Runid. There are a number of third-party tools that can provide customized reports based on this data, Oracle provides PROFREP.SQL script evaluation data (in the <oracle_home>\plsql\demo\ directory), and the following two simple scripts are used above. Used to check the execution time of the program unit. Execution time is stored in milliseconds
From All_source S, (select U.unit_owner, U.unit_name, U.unit_type, d.line#,
D.total_occur, d.total_time/1000000 Total_time
From Plsql_profiler_data D, plsql_profiler_units u
where U.runid = &&runid
and U.runid = D.runid
and u.unit_number = D.unit_number) p
where S.owner = P.unit_owner (+)
and S.name = P.unit_name (+)
and S.type = P.unit_type (+)
and S.line = p.line# (+)
and s.name = Upper (' &&name ')
and S.owner = Upper (' &&owner ')
Order BY S.line;
Select Exec.cnt/total.cnt * "Code% coverage"
From (select COUNT (1) CNT
From Plsql_profiler_data D, plsql_profiler_units u
where D.runid = &&runid
and U.runid = D.runid
and U.unit_number = D.unit_number
and u.unit_name = Upper (' &&name ')
and U.unit_owner = Upper (' &&owner ')) Total,
(select COUNT (1) CNT
From Plsql_profiler_data D, plsql_profiler_units u
where D.runid = &&runid
and U.runid = D.runid
and U.unit_number = D.unit_number
and u.unit_name = Upper (' &&name ')
and U.unit_owner = Upper (' &&owner ')
and d.total_occur > 0) exec;
Undef Runid
UNDEF owner
undef name
Conclusion
Dbms_profiler is a very powerful tool, one of which is the ability to identify pl/sql performance problems. This tool is best used during the development period to adjust code based on a variety of application scenarios, and it also adjusts the routines already in use and takes the obvious time to execute. In short, this tool can give performance statistics to each line of code, which can help us evaluate and adjust to an excellent level, Pl/sql code should not be ignored when checking the performance problem of SQL statements, instead should be adjusted to the best results.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service