




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Profiling and Tracing PL/SQL CodeObjectivesAfter completing this lesson, you should be able to do the following:Trace PL/SQL program executionProfile PL/SQL applicationsLesson AgendaTracing PL/SQL program executionProfiling PL/SQL applicationsEnable specific subprograms for tracing (optional)Start t
2、racing sessionTracing PL/SQL ExecutionTracing PL/SQL execution provides you with a better understanding of the program execution path, and is possible by using the dbms_trace package.Trace dataTrace dataRun application to be tracedStop tracing sessionTracing PL/SQL ExecutionThe dbms_trace package co
3、ntains:set_plsql_trace (trace_level INTEGER)clear_plsql_traceplsql_trace_versionTracing PL/SQL ExecutionUsing set_plsql_trace, select a trace level to identify how to trace calls, exceptions, SQL, and lines of code.Trace-level constants:trace_all_calls trace_enabled_calls trace_all_sqltrace_enabled_
4、sql trace_all_exceptions trace_enabled_exceptions trace_enabled_linestrace_all_lines trace_stoptrace_pausetrace_resumeTracing PL/SQL: StepsEnable specific program units for trace data collection.Use dbms_trace.set_plsql_trace to identify a trace level.Start tracing by running your PL/SQL code.Use db
5、ms_trace.clear_plsql_trace to stop tracing data.Read and interpret the trace information.12345ALTER PROCEDURE | FUNCTION | PACKAGE subprogram-name COMPILE DEBUG BODY;Step 1: Enable Specific SubprogramsEnable specific subprograms with one of the two methods:Enable a subprogram by compiling it with th
6、e debug option: pile a specific subprogram with the debug option:ALTER SESSION SET PLSQL_DEBUG=true;CREATE OR REPLACE .Steps 2 and 3: Identify a Trace Level and Start TracingSpecify the trace level by using dbms_trace.set_plsql_trace:Execute the code that is to be traced:EXECUTE my_programEXECUTE DB
7、MS_TRACE.SET_PLSQL_TRACE - (tracelevel1 + tracelevel2 .)EXECUTE DBMS_TRACE.CLEAR_PLSQL_TRACEStep 4: Turn Off Tracing Remember to turn tracing off by using the dbms_trace.clear_plsql_trace procedure.Step 5: Examine the Trace InformationExamine the trace information:Call tracing writes out the program
8、 unit type, name, and stack depth.Exception tracing writes out the line number.plsql_trace_runs and plsql_trace_eventsTrace information is written to the following dictionary views:plsql_trace_runs dictionary viewplsql_trace_events dictionary viewRun the tracetab.sql script to create the dictionary
9、views.You need privileges to view the trace information in the dictionary views.PROC_NAME PROC_LINE EVENT_PROC_NAME MENT- - - -P5 1 Procedure CallP4 1 P5 Procedure Call 2 rows selected.plsql_trace_runs and plsql_trace_eventsALTER SESSION SET PLSQL_DEBUG=TRUE;ALTER PROCEDURE P5 COMPILE DEBUG;EXECUTE
10、DBMS_TRACE.SET_PLSQL_TRACE(DBMS_TRACE.trace_all_calls)EXECUTE p5EXECUTE DBMS_TRACE.CLEAR_PLSQL_TRACESELECT proc_name, proc_line, event_proc_name, ment FROM sys.plsql_trace_eventsWHERE event_proc_name = P5OR PROC_NAME = P5;Lesson AgendaTracing PL/SQL program executionProfiling PL/SQL applicationsHier
11、archical Profiling ConceptsDefinition:Used to identify hotspots and performance tuning opportunities in PL/SQL applicationsReports the dynamic execution profile of a PL/SQL program organized by function callsReports SQL and PL/SQL execution times separatelyProvides function level summariesBenefits:P
12、rovides more information than a flat profilerCan be used to understand the structure and control flow of complex programsHierarchical Profiling ConceptsThe PL/SQL hierarchical profiler consists of the:Data collection componentAnalyzer componentUsing the PL/SQL ProfilerBy using the PL/SQL profiler, y
13、ou can find:The number of calls to a functionThe function time, not including descendantsThe subtree time, including descendantsParent-children information for each functionWho were the callers of a given function?What functions were called from a particular function?How much time was spent in funct
14、ion X when called from function Y?How many calls to function X came from function Y?How many times did X call Y?Using the PL/SQL ProfilerSample data for profiling:CREATE OR REPLACE PACKAGE BODY credit_card_pkgIS PROCEDURE update_card_info (p_cust_id NUMBER, p_card_type VARCHAR2, p_card_no VARCHAR2)
15、IS v_card_info typ_cr_card_nst; i INTEGER; BEGIN SELECT credit_cards . END update_card_info; PROCEDURE display_card_info (p_cust_id NUMBER) IS v_card_info typ_cr_card_nst; i INTEGER; BEGIN SELECT credit_cards . END display_card_info; END credit_card_pkg; - package bodyUsing the PL/SQL ProfilerBEGIN-
16、 start profiling DBMS_HPROF.START_PROFILING(PROFILE_DATA, pd_cc_pkg.txt);END;1BEGIN DBMS_HPROF.STOP_PROFILING;END;3DECLARE v_card_info typ_cr_card_nst;BEGIN- run application credit_card_pkg.update_card_info (154, Discover, 123456789);END;2Understanding Raw Profiler DataP#! PL/SQL Timer StartedP#C PL
17、SQL._plsql_vmP#X 3P#C PLSQL._anonymous_blockP#X 1634P#C PLSQL.OE.CREDIT_CARD_PKG:11.UPDATE_CARD_INFO#71749359b90ac246 #24P#X 7P#C PLSQL.OE.CREDIT_CARD_PKG:11.CUST_CARD_INFO#c2ad85321cb9b0ae #4P#X 11P#C SQL.OE.CREDIT_CARD_PKG:11._static_sql_exec_line10 #10P#X 1502P#R.P#C PLSQL._plsql_vmP#X 3P#C PLSQL
18、._anonymous_blockP#X 15P#C PLSQL.SYS.DBMS_HPROF:11.STOP_PROFILING#980980e97e42f8ec #53P#RP#RP#! PL/SQL Timer StoppedUsing the Hierarchical Profiler TablesUpload the raw profiler data into the database tables. Run the dbmshptab.sql script that is located in the /home/rdbms/admin folder to set up the
19、profiler tables.Creates these tables:CONNECT OE- run this only once per schema - under the schema where you want the profiler tables locatedD:appAdministratorproduct11.1.0db_1RDBMSADMINdbmshptab.sqlTableDescriptionDBMSHP_RUNSContains top-level information for each run commandDBMSHP_FUNCTION_INFOCont
20、ains information on each function profiledDBMSHP_PARENT_CHILD_INFOContains parent-child profiler informationUsing DBMS_HPROF.ANALYZEDBMS_HPROF.ANALYZE:Analyzes the raw profiler dataGenerates hierarchical profiler information in the profiler database tablesDefinition:DBMS_HPROF.ANALYZE( location IN V
21、ARCHAR2, filename IN VARCHAR2, summary_mode IN BOOLEAN DEFAULT FALSE, trace IN VARCHAR2 DEFAULT NULL, skip IN PLS_INTEGER DEFAULT 0, collect IN PLS_INTEGER DEFAULT NULL, ment IN VARCHAR2 DEFAULT NULL)RETURN NUMBER;Using DBMS_HPROF.ANALYZE to Write to Hierarchical Profiler TablesUse the DBMS_HPROF.AN
22、ALYZE function to upload the raw profiler results into the database tables.This function returns a unique run identifier for the run. You can use this identifier to look up results corresponding to this run from the hierarchical profiler tables.DECLARE v_runid NUMBER;BEGIN v_runid := DBMS_HPROF.ANAL
23、YZE (LOCATION = PROFILE_DATA, FILENAME = pd_cc_pkg.txt); DBMS_OUTPUT.PUT_LINE(Run ID: | v_runid);END;RUN_ID- 1 Sample Analyzer Output from the DBMSHP_RUNS Table Query the DBMSHP_RUNS table to find top-level information for each run:SELECT runid, run_timestamp, total_elapsed_timeFROM dbmshp_runs WHER
24、E runid = 1; RUNID RUN_TIMESTAMP TOTAL_ELAPSED_TIME - - - 2 12-DEC-07 84000 PM 122650Sample Analyzer Output from the DBMSHP_FUNCTION_INFO Table Query the DBMSHP_FUNCTION_INFO table to find information about each function profiled:SELECT owner, module, type, function line#, namespace, calls
25、, function_elapsed_timeFROM dbmshp_function_infoWHERE runid = 1;OWNER MODULE TYPE LINE# NAMESPACE CALLS TIME- - - - - - - _anonymous_block PLSQL 2 1650 _plsql_vm PLSQL 2 10OE CREDIT_CARD PACKAGE BODY CUST_CARD_INFO PLSQL 1 66 _PKGOE CREDIT_CARD PACKAGE BODY UPDATE_CARD_INFO PLSQL 1 38 _PKGSYS DBMS_HPROF PACKAGE BODY STOP_PROFILING PLSQL 1 0 _PKGOE CREDIT_CARD PACKAGE BODY _static_sql_exec_line10 SQL 1 1502 _PKGOE CREDIT_CARD PACKAGE BODY _static_sql_exec_line41SQL 1 8999 _PKGplshprof: A Simple HTML Report Generatorplshprof is a command-
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 基础语文知识课程
- 卫生健康教育防治春季传染病
- 初中生应了解的理财知识
- 投标部门职责培训
- 合同签订后的注意事项
- 外贸合同附加协议
- 本地化服务分包合同
- 呼吸衰竭专科培训课件
- 幼儿园老师法治培训
- 摄影入门基础培训
- 光伏电站工程标准化监理作业手册(完整版)资料
- GB/T 19189-2011压力容器用调质高强度钢板
- GB 8537-2018食品安全国家标准饮用天然矿泉水
- 保安公司客户满意度调查表
- 小学五年级语文说明方法爆款课件
- 简约中国戏曲文化鉴赏工作汇报工作总结PPT模板
- 一文读懂泡泡玛特
- 2022年《江苏省机动车维修费用结算清单》格式
- Q∕GDW 11304.15-2021 电力设备带电检测仪器技术规范 第15部分:SF6气体泄漏红外成像检测仪
- GB∕T 41441.1-2022 规模化畜禽场良好生产环境 第1部分:场地要求
- 品质异常奖罚规定001
评论
0/150
提交评论