Professional Documents
Culture Documents
Agenda
SQL Trace / TKPROF PL/SQL Profiler
Presentation_ID
Cisco Confidential
SQL TRACE
Presentation_ID
Cisco Confidential
SQL Trace
It is a diagnostic/debugging facility that provides runtime performance statistics for individual SQL statements that your application runs. It also records the execution plan that was used to execute each SQL statement. In most cases, enabled at the session level. It is a text file, but raw.
Presentation_ID
Cisco Confidential
SQL Trace
Level 1 - Standard Sql Trace Level 4 - Level 1 PLUS Bind values
BINDS #1: bind 0: dty=2 mxl=22(22) mal=00 scl=00 pre=00 oacflg=03 oacfl2=0 size=24 offset=0 bfp=80000001000cbc78 bln=22 avl=04 flg=05 value=144867
Level 12 - Level 1 PLUS Bind values and Wait Statistics In >80% cases, Standard Sql Trace is good enough
Presentation_ID 2006-2007 dbPerf Inc. All rights reserved. Cisco Confidential
SQL Trace
sql_trace=false
Enables sql tracing for the entire instance
timed_statistics=true
Enables collection of CPU and elapsed times
max_dump_file_size=val [K|M]|unlimited
Specifies max size of the trace file
user_dump_dest=<directory>
Specifies location where trace files should be written
tracefile_identifier=string
Creates trace files with the name sid_ora_pid_string.trc
_trace_files_public=true
Creates trace files with mode 644 instead of 600
Presentation_ID 2006-2007 dbPerf Inc. All rights reserved. Cisco Confidential
dbms_session.set_sql_trace(true); dbms_support.start_trace(waits=>true,binds=>true);
Presentation_ID
Cisco Confidential
Presentation_ID
Cisco Confidential
Presentation_ID
Cisco Confidential
10
Presentation_ID
Cisco Confidential
11
Presentation_ID
Cisco Confidential
12
Presentation_ID
Cisco Confidential
13
This will trace all the sessions of that user at level <x>
The trace file name will be of the format :
sid_ora_spid_CLASSXX.trc
- It is not recommended to use this method to enable trace for an application that uses a connection pools as it can dirty the pool with connections with SQL trace on. - Examples of applications using connection pools -OA FWK -JTF Stack
Presentation_ID 2006-2007 dbPerf Inc. All rights reserved. Cisco Confidential
14
TKPROF
Presentation_ID
Cisco Confidential
15
TKPROF
Utility that read the raw SQL trace file and produces a user readable output file Summarizes information from the raw trace file
Presentation_ID
Cisco Confidential
16
TKPROF
Contains the following information
The text of the SQL statement. The SQL trace statistics in tabular form. The number of library cache misses for the parsing and execution of the statement. The user initially parsing the statement. Runtime Execution Plan, listed under Row Source Operation The execution plan generated by EXPLAIN PLAN. Wait Statistics ( 9i onwards )
Presentation_ID
Cisco Confidential
17
TKPROF
tkprof tracefile outputfile [Optional Params] Optional Parameters
Explain=username/password
Table=<username>.<tablename> Sys=yes|no Sort=sort option(s)
FCH
fetch
ELA
Elapsed Time
18
TKPROF
Sample Output
select party_name from hz_parties where party_id=:b1
count 1 1
disk 0 0
query 0 0
current 0 0
rows ---------0 0
------- ------
Fetch
total
2
4
0.00
0.00
0.06
0.07
3
3
4
4
0
0
1
---------1
------- ------
Misses in library cache during parse: 1 Optimizer goal: CHOOSE Parsing user id: 33 (APPS)
Presentation_ID
Cisco Confidential
19
TKPROF
Rows ------1 1 Row Source Operation --------------------------------------------------TABLE ACCESS BY INDEX ROWID HZ_PARTIES INDEX UNIQUE SCAN (object id 34093)
Rows ------0 1 1
Execution Plan --------------------------------------------------SELECT STATEMENT TABLE ACCESS INDEX (UNIQUE) GOAL: CHOOSE GOAL: ANALYZED (BY INDEX ROWID) OF 'HZ_PARTIES'
Elapsed times include waiting on following events: Event waited on ---------------------------------------SQL*Net message to client db file sequential read file open Times Waited 2 3 2 Max. Wait ---------0.00 0.03 0.01 Total Waited -----------0.00 0.06 0.01
9.99
9.99
Presentation_ID
Cisco Confidential
20
TKPROF
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS call Parse Execute Fetch total count 538 560 363 1461 cpu 0.70 4.11 0.44 5.25 elapsed 0.95 6.20 4.34 11.49 disk 1 0 278 279 query 670 44942 3401 49013 current 0 45 52 97 rows ---------0 224 1157 ---------1381
------- ------
------- ------
OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS call Parse Execute Fetch total count 4578 10944 29021 44543 cpu 4.30 2.47 6.49 13.26 elapsed 4.71 3.19 34.64 42.54 disk 2 109 2583 2694 query 38 1365 287337 288740 current 3 3048 1902 4953 rows ---------0 580 29597
------- ------
---------30177
Presentation_ID
Cisco Confidential
21
TKPROF
Interpreting tkprof Statistics
Each row corresponds to one of the three phases of SQL processing Parse Execute Fetch The columns display the statistic value for each phase Count The number of times each statement was parsed, executed or fetched CPU Total CPU time in seconds for all parse, execute, or fetch calls for the statement Elapsed Total elapsed time in seconds for all parse, execute, or fetch calls for the statement
Presentation_ID 2006-2007 dbPerf Inc. All rights reserved. Cisco Confidential
22
TKPROF
Disk Total number of data blocks physically read from the datafiles on disk for all parse, execute, or fetch calls Query
Total number of buffers retrieved in consistent mode for all parse, execute, or fetch calls
Current Total number of buffers retrieved in current mode
Rows
Total number of rows processed by the SQL statement Does not include the rows processed by the sub-queries of the SQL statement
Presentation_ID
Cisco Confidential
23
TKPROF
TKPROF also lists the number of library cache misses resulting from parse and execute steps for each SQL statement. This implies a HARD parse. Run Time Execution Plan Row Source Counts
Row source counts are displayed when the cursor is closed Do not call sql_trace=false, otherwise the cursors will not be closed. Instead, exit from the session.
TKPROF generated Execution Plan, if tkprof was run with the EXPLAIN option Totals of Recursive and Non-recursive SQL statements
Presentation_ID
Cisco Confidential
24
TKPROF
Interpreting Output - what to look out for
High Physical and Logical reads High CPU Time High Elapsed Time A large gap between elapsed and CPU time indicates that the server process was waiting for something, most often the waits are due to the process having to do physical I/O Check the number of physical reads and try to account for them Wait statistics (level 8 / level 12 sql trace ) are usually provide sufficient information to pin-point the cause Multiple parse calls for one statement Multiple execute calls for one statement
Presentation_ID
Cisco Confidential
25
TKPROF
Misses in library cache during parse -> Hard Parse Rows fetched per fetch Totals for Non-Recursive and Recursive statements Check for Throw-away. Throw-away can be caused by: Full scans Unselective range scans Late predicate filters Wrong join order Late predicate operations Throw-away Example :
Rows ------Row Source Operation ---------------------------------------------------
11
107317043 11
FILTER
TABLE ACCESS FULL CFI_RRR_AR_ACTUALS INDEX UNIQUE SCAN SYS_C00307768 (object id 38788)
Presentation_ID
Cisco Confidential
26
TKPROF
What does raw trace have that TKPROF does not?
Bind information Most important are the bind values and their datatypes Specific execution, instead of aggregates Chronological execution order Recursive Level RPC procedure (server side) calls from Forms
Presentation_ID
Cisco Confidential
27
TKPROF
A truncated trace file will provide incomplete information. Go to the end of the trace file and check for the following line.
*** DUMP FILE SIZE IS LIMITED TO 12345 BYTES***
Make sure there are not discrepancies between run-time execution plan and tkprof-generated execution plan If the trace file has been generated on 9i, use the 9i tkprof executable.
Presentation_ID
Cisco Confidential
28
PL/SQL PROFILER
Presentation_ID
Cisco Confidential
29
PL/SQL Profiler
API to profile PL/SQL applications and identify performance bottlenecks Introduced in 8i
Presentation_ID
Cisco Confidential
30
Presentation_ID
Cisco Confidential
31
Execute dbms_profiler.stop_profiler;
Flushes data into profiler tables and stops profiler data collection Exiting session does not save data automatically Profiler data is stored in memory. You can call dbms_profiler.flush_data at various points in your code save incremental data and free memory, if you expect a lot of data to be generated
Presentation_ID
Cisco Confidential
32
You can also refer to a script available on Metalink. Refer to Note 243755.1 for details.
Presentation_ID
Cisco Confidential
33
7
8 9 22 23 24 25
1
1 18 17 1 1 1
-- Log ON state
Presentation_ID
Cisco Confidential
34
Presentation_ID
Cisco Confidential
35
Presentation_ID
Cisco Confidential
36
37
Presentation_ID
Cisco Confidential
38
Presentation_ID
Cisco Confidential
39
Presentation_ID
Cisco Confidential
40
Presentation_ID
Cisco Confidential
41
Presentation_ID
Cisco Confidential
42
Presentation_ID
Cisco Confidential
43
REPORTS TRACE
Presentation_ID
Cisco Confidential
44
Reports Trace
Enabled by appending tracing parameters to command line
ar60run TRACEFILE=<file> TRACE_OPTS=(<trace options>) TRACEMODE=trace_replace|trace_append Where trace options can be one or more of the following :
TRACE_ALL : log all possible trace information in the trace file. (DEFAULT) TRACE_APP : log trace information on all the report objects in the trace file. TRACE_BRK : list breakpoints in the trace file.
Presentation_ID
Cisco Confidential
45
Reports Trace
Sign-on to Apps with System Administrator responsibility Go to Concurrent -> Program -> Define Query up your Reports concurrent program
Running the concurrent program now will generate the reports trace file as specified by TRACEFILE
Caution : Since this involves changes at the report definition level, this operation should be performed on the test instance when no other user is running this report.
Presentation_ID 2006-2007 dbPerf Inc. All rights reserved. Cisco Confidential
46
Reports Trace
LOG :
Report: /u01/CRMPERF/appl/fnd/11.5.0/reports/US/FNDSCURS.rdf Logged onto server: Username: . . . . . . . . 23:59:57 23:59:57 23:59:57 APP ... ( APP ... ) APP ... ( Generic Graphical Object B_SECURITY_GROUP_NAME1 Generic Graphical Object B_SECURITY_GROUP_NAME1 Generic Graphical Object B_USER_NAME1 +-------------------------------------+ | Report Builder Profiler statistics | +-------------------------------------+ TOTAL ELAPSED Time: Reports Time: 2243.04 seconds
. . . . . . . .
1196.62 seconds (53.34% of TOTAL) 1046.41 seconds (46.65% of TOTAL) 1046.00 seconds 0.40 seconds 904.71 seconds
Cisco Confidential
47
Reports Trace
From the profile output, it is possible to see :
Execution time (total elapsed time) for the report Time that was spent on formatting the data (Reports Time)
UPI time is the time spent in establishing the database connection and parsing and executing the SQL.
The SQL time is the time spent on fetching the data by the database server (percent of time spent executing SRW.DO_SQL() statements, EXEC_SQL statements, PL/SQL Cursors, etc.).
Presentation_ID 2006-2007 dbPerf Inc. All rights reserved. Cisco Confidential
48
Q&A
Presentation_ID 2006-2007 dbPerf Inc. All rights reserved. Cisco Confidential
49
Presentation_ID
Cisco Confidential
50