版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 企業(yè)內(nèi)部管理咨詢顧問合同
- 會計(jì)勞動合同
- 知識產(chǎn)權(quán)法作業(yè)指導(dǎo)書
- 企業(yè)質(zhì)量管理體系建設(shè)作業(yè)指導(dǎo)書
- 人才獵頭服務(wù)合作協(xié)議
- 農(nóng)業(yè)種植行業(yè)農(nóng)作物病蟲害防治協(xié)議
- 電子商務(wù)物流配送協(xié)議
- 成人職業(yè)發(fā)展輔導(dǎo)故事
- 冷鏈物流項(xiàng)目合作協(xié)議
- 寶坻小升初分班數(shù)學(xué)試卷
- 顳下頜關(guān)節(jié)疾病試題
- 非甾體抗炎藥圍術(shù)期鎮(zhèn)痛專家共識(2024 版)解讀
- 安全使用文具班會課
- 假期師生讀書活動方案2024年
- Unit 5 Dinner's ready Read and write(說課稿)-2024-2025學(xué)年人教PEP版英語四年級上冊
- 第3章智能網(wǎng)聯(lián)汽車高精度地圖與定位技術(shù)
- 2018年國家公務(wù)員行測考試真題-省級(含答案)
- 2024中華人民共和國學(xué)前教育法學(xué)習(xí)解讀課件
- 計(jì)量經(jīng)濟(jì)學(xué)復(fù)習(xí)資料-概念和問答
- 2024年秋新人教PEP版3年級上冊英語教學(xué)課件 Unit 4 第4課時(shí) Part B Let's talk
- 企業(yè)發(fā)展部部門管理手冊
評論
0/150
提交評論