home *** CD-ROM | disk | FTP | other *** search
- ...
- ... $Header: tkprof.doc,v 6002701.1 89/06/15 23:01:35 rcs Exp $ tkprof.doc Copyr (c) 1989 Oracle
- ...
-
- This document describes the SQL level profiling facility.
-
- SQL level profiling consists of two parts: generating raw statistics,
- and processing the statistics into a useable forms.
-
-
- 1. Generating Statistics
-
- To generate the statistics you must run a session against the kernel
- with sql tracing enabled. Sql tracing causes a record to be written
- to the trace file every time a SQL statement is parsed or executed or
- a row is fetched.
-
- You can enable sql tracing either on a per session basis or globally.
- To enable it on a per session basis, execute the following 'alter
- session' SQL statement within the session:
-
- alter session set sql_trace true;
-
- To enable it globally (for all sessions) include the following line
- in your init.ora file and restart the instance:
-
- sql_trace = true
-
- If you would like to profile execution times for SQL statments, you
- must also enable the gathering of timing statistics in your database.
- This is done by putting the following line in your init.ora file:
-
- timed_statistics = true
-
-
- 2. Processing Statistics
-
- Once you have produced a trace file containing execution time
- statistics, you can format it into a human readable form using the
- tkprof program. The program is invoked as follows:
-
- TKPROF TRACEFILE OUTPUTFILE [SORT] [PRINT] [EXPLAIN]
-
- Where:
- Tracefile - name of trace file to which statistics were dumped. Trace
- files are written to the directory specified by the init.ora parameter
- user_dump_dest or to a default directory if this parameter is not
- specified.
-
- Outputfile - file to which human readable statistics should be written.
-
- Sort - optional argument that causes the statistics in the
- outputfile to be written in a sorted order. For example, you can sort
- by cpu time spent executing a statement, or you can sort by the number
- of physical reads that occured while fetching rows. Invoking the
- tkprof program with no arguments will cause a list of sortoptions to
- be printed. You can also give more than one sortoption in which case
- the output will be sorted by the sum of the values specified by the
- sortoptions.
-
- Print - this optional argument causes only the top NUM statements to be
- printed to the outputfile
-
- Explain - this optional argument instructs tkprof to run EXPLAIN PLAN on all
- the SQL statements it prints out. To do so it will login to the database
- using the username/password given on the command line. Username
- must have resource privilege in order for tkprof to create the plan
- table that EXPLAIN PLAN uses. DDL and recursive SQL statements will
- not be explained.
-
-
- Example:
-
- tkprof sqldba_jrl_005.trc run1.prf sort=(execpu,fchcpu) print=20
- explain=scott/tiger
-
- This command runs the tkprof program on the statistics in the file
- 'sqldba_jrl_005.trc'. Tkprof will generate summary statistics for
- each sql statement and sort the statistics by the sum of cpu time
- spent executing (execpu) and the cpu time spent fetching rows
- (fchcpu). Only the top 20 statements will be printed out, and an
- execution plan will be printed for each statement. The output of
- tkprof will be written to the file 'run1.prf'.
-
- If you enable the trace globally (in the init.ora file), you can obtain
- global summary statistics by appending the trace files produced by all
- sessions into a new file, and running tkprof on the new file.
-
-
- 3. Output of Tkprof
-
- This section gives a short description of the statistics that are output
- by tkprof. Be warned that some of these statistics are hard to interpret
- without an intimate knowledge of the internals of the database kernel.
- A sample of the output of tkprof is included at the end of this file.
-
- COUNT - the number of times that the OCI operation (parse, execute, or
- fetch) was called.
-
- CPU - total cpu time for the operation measured in hundreths of seconds.
-
- Note that because the granularity of our clock is a hundreth of a
- second, any operation on a cursor that takes on the order of a
- hundreth of a second or less will not be timed accurately.
- Unfortunately, this applies to a large number of SQL statements,
- especially simple queries. Therefore, you must be very careful when
- interpreting these numbers. Be especially wary of queries that are
- executed frequently, but have low cpu and elapsed times.
-
- ELAP - total elapsed time for the operation measured in hundreths of
- seconds.
-
- PHYS - total number of physical reads of buffers (from disk).
-
- CR - number of buffers gotten for consistent read. A buffer is gotten
- for consistent read when a read consistent version of the data in the
- buffer is needed.
-
- In order to select a row out of a table, the buffer containing that row
- must be gotten for consistent read. In order to update a row in a
- table, the buffer containing the row must be gotten for consistent
- read to verify the 'where' clause of the update. In order to read a
- value out of an index, the leaf block containing the value and all the
- branch blocks above the leaf block must be gotten for consistent read.
- A table scan requires getting all the buffers in the table for
- consistent read.
-
- CUR - number of buffers gotten in current mode. A buffer is gotten in
- current mode when the most recent version of the buffer is needed.
-
- In order to insert a row into a buffer, the buffer must be gotten in
- current mode. In order to update a row in a buffer, the buffer must be
- gotten in current mode. In order to insert or delete a value in an
- index, the leaf block containing the value and all the branch blocks
- above the leaf block must be gotten in current mode. (values in an
- index are updated by deleting the old value and inserting the new
- one). In order to perform a table scan, the segment header block for
- the table must be gotten in current mode. Any time a change is made
- to either an index block or a table block, the appropriate transaction
- table must be gotten in current mode, and an undo block must be gotten
- in current mode.
-
- ROWS - total number of rows processed by the SQL statement. This
- number does not include the number of rows processed by subqueries of
- the SQL statement.
-
-
- 4. Caveats
-
- You should also be careful when adding up the statistics for several
- sql statements by hand to not double count statistics for recursive
- sql statements. The cpu time, elapsed time, physical, consistent, and
- current reads for recursive sql statements are included in the
- statistics of the sql statement that caused the recursive execution.
- The rest of the statistics are not.
-
- Another init.ora parameter that you should be aware of is
- max_dump_file_size. It controls the maximum size that the trace files
- can grow to. If your runs are long and you find that your trace
- files are overflowing, you should increase this value.
-
- You should probably not look at the first few trace files that are
- created after starting a database. They will contain disproportionate
- values until the various caches in the database get filled.
-
- If you set the trace globally (in the init.ora file) you should make
- sure that the directory to which the trace files are being written has
- a high version limit on files.
-
-
- The current implementation of the profiling facility should be
- considered a prototype. At some point in the future it will be
- reworked to dump statistics into the database rather than to trace
- files. It is also possible that the tkprof program will be merged
- into SQL*DBA at some point in the future.
-
-
- 5. Sample Output of Tkprof
-
-
- This sample output is taken from oracle mail.
-
- ============================================================================
- SELECT MSG_ID,MSG_NODE FROM M_HEADER MINUS(SELECT MSG_ID,MSG_NODE FROM M_INS
- TANCE UNION SELECT INCLUSION_ID,INCLUSION_NODE FROM M_HEADER UNION SELECT I
- NTR_ID,INTR_NODE FROM M_USER)
-
- count cpu elap phys cr cur rows
- Parse: 1 27 38 0 12 0
- Execute: 4 7842 13222 5961 6732 1112 0
- Fetch: 36 2306 2894 224 201 394 682
-
- Execution plan:
- PROJECTION
- MINUS
- SORT (UNIQUE)
- TABLE ACCESS (FULL) OF 'M_HEADER'
- UNION
- UNION
- SORT (UNIQUE)
- TABLE ACCESS (FULL) OF 'M_INSTANCE'
- SORT (UNIQUE)
- TABLE ACCESS (FULL) OF 'M_HEADER'
- SORT (UNIQUE)
- TABLE ACCESS (FULL) OF 'M_USER'
- ============================================================================
- DELETE FROM M_BODY WHERE MSG_ID=:b1 AND MSG_NODE=:b2 AND ROWNUM<:b3
-
- count cpu elap phys cr cur rows
- Parse: 1 1 0 0 0 0
- Execute: 662 6760 12988 998 5354 21142 2504
- Fetch: 0 0 0 0 0 0 0
-
- Execution plan:
- COUNT
- FILTER
- INDEX (RANGE SCAN) OF 'M_BODY_KEY' (NON-UNIQUE)
- ============================================================================
- SELECT DISTINCT TYPE,MTA_NODE,FOR_DOMAIN FROM M_RECIPIENT M WHERE MSG_ID=:b1
- AND MSG_NODE=:b2 AND TYPE BETWEEN 50 AND 99 AND NOT EXISTS(SELECT MSG_ID,M
- SG_NODE FROM T_INSTANCE T WHERE T.MSG_ID=:b3 AND T.MSG_NODE=:b4 AND M.MTA_N
- ODE=T.NODE_ID AND T.FOLDER_ID=1)
-
- count cpu elap phys cr cur rows
- Parse: 488 1823 2138 0 0 0
- Execute: 488 1623 1634 6 2041 0 0
- Fetch: 488 57 64 0 0 0 72
-
- Execution plan:
- SORT (UNIQUE)
- FILTER
- TABLE ACCESS (BY ROWID) OF 'M_RECIPIENT'
- INDEX (RANGE SCAN) OF 'M_RECP_KEY' (NON-UNIQUE)
- INDEX (RANGE SCAN) OF 'T_INST_KEY' (NON-UNIQUE)
-