Trace Analysis Reports
Script: trace_reports.sql
Section titled “Script: trace_reports.sql”column dum1 noprint;column dum2 noprint;set term on;set linesize 4000;set verify on;set echo off;set heading on;set pagesize 60;
promptaccept traceid prompt ' Enter Trace id number : 'promptpromptdefine spoolp1 = d:\temp\trace_obs_&traceid..txtdefine spoolp2 = d:\temp\trace_rec_&traceid..txtdefine spoolp3 = d:\temp\trace_Hdr_&traceid..txt
set term off;set feedback off;set verify off;set echo off;set heading off;set trimspool on;set truncate on;set pagesize 0;
set term onprompt spooling observations to &spoolp1set term offspool &spoolp1
SELECT 5 dum1, ranking dum2, ' 'FROM TRCANLZR.TRCA$_CURSORWhereTRACE_ID = &traceidand uid$ <> 0and ranking is not nullUNIONSELECT 10 dum1, ranking dum2, '-- HashValue: '||HV||' Rank: '||rankingFROM TRCANLZR.TRCA$_CURSORWhere TRACE_ID = &traceidand uid$ <> 0and ranking is not nullUNIONSELECT 20 dum1, ranking dum2, '-- Idle Waits Secs: '||idle_wait_secs||' Non-Idle Waits Secs: '||non_idle_wait_secsFROM TRCANLZR.TRCA$_CURSORWhere TRACE_ID = &traceidand uid$ <> 0and ranking is not nulland (idle_wait_secs > 0 or non_idle_wait_secs >0 )UNIONselect 30 dum1,ranking dum2 , '-- Statement Cost: '||cost||' CPU Cost: '||cpu_cost||' I/O Cost: '||io_cost from trca$_cursor a, trca$_plan_table b WHERE TRACE_ID = &traceid and uid$ <> 0 and ranking is not null and b.statement_id = trace_id||'-'||cursor_id and b.id = 0UNIONSELECT 40 dum1, ranking dum2, '-- Calls: '||call_count||' CPU: '||ltrim(to_char(cpu_secs,'990.999'))||' Elapsed: '||ltrim(to_char(elapsed_secs,'990.999'))||' DISK: '||nvl(disk_blocks,0)||' Logical: '||(nvl(query_blocks,0)+nvl(current_blocks,0)) ||' Rows: '||nvl(rows_returned,0) FROM trca$_call_summary cs, trca$_cursor cu WHERE cs.CALL = 'Total' AND cs.trace_id = cu.trace_id AND cs.cursor_id = cu.cursor_id AND cu.cursor_id = cu.same_as_cursor_id AND cu.uid$ <> 0 AND cu.dep = 0 AND cu.trace_id = &traceid AND ranking IS NOT NULLunionSELECT 50 dum1, ranking dum2, ' 'FROM TRCANLZR.TRCA$_CURSORWhereTRACE_ID = &traceidand uid$ <> 0and ranking is not nullUNIONSELECT 60 dum1, ranking dum2, trim( trailing ' ' from (replace(substr(SQL_STATEMENT_SMALL,1,LENGTH(SQL_STATEMENT_SMALL)),chr(10),' '))) || ';'FROM TRCANLZR.TRCA$_CURSORWhereTRACE_ID = &traceidand uid$ <> 0and ranking is not nullunionSELECT 70 dum1, ranking dum2, ' 'FROM TRCANLZR.TRCA$_CURSORWhereTRACE_ID = &traceidand uid$ <> 0and ranking is not nulland rownum < 21order by dum2, dum1;
spool off;
set term onprompt spooling Recommendatios to &spoolp2set term off
spool &spoolp2
select * from (SELECT 10 dum1, ranking dum2, '-- HashValue: '||HV||' Rank: '||rankingFROM TRCANLZR.TRCA$_CURSORWhereTRACE_ID = &traceidand uid$ <> 0and ranking is not nullUNIONselect 20 dum1,ranking dum2 , '* '||operation||' '||options||' ON '||object_owner||'.'||object_name from trca$_cursor a, trca$_plan_table b WHERE TRACE_ID = &traceid and uid$ <> 0 and ranking is not null and b.statement_id = trace_id||'-'||cursor_id and (options like '%FULL%' or options like '%CARTESIAN%')UNIONSELECT 35 dum1, ranking dum2, ' 'FROM TRCANLZR.TRCA$_CURSORWhereTRACE_ID = &traceidand uid$ <> 0order by dum2, dum1)where rownum < 80;
spool off;
set term onprompt spooling Trace Header to &spoolp3set term off
spool &spoolp3
set linesize 80set truncate offset heading off
SELECT 'End_Date: '||to_char(END_DATE,'dd-MON-yyyy hh24:mi:ss'), 'Instance Name: '||INSTANCE_NAME, 'Schema Name: '||USERNAME, 'Test Number: '||TRACE_ID, 'SQL Count: '||SQL_STATEMENTS_USER||'/'||UNIQUE_SQL_USER, 'Total CPU (secs): '||C_TOTAL, 'Total Elapsed (Secs): '||E_TOTAL, 'Total Physical IO: '||DISK_TOTAL, 'Total Logical IO: '||(QUERY_TOTAL+CURRENT_TOTAL), 'Row Count: '||ROWS_TOTAL, 'Trace File: '||TRACE_FILENAME FROM TRCANLZR.DUT_TRCA$_TRACE WHERE TRACE_ID = &traceid;
spool off
set term on;set feedback 6;set verify on;set echo off;set heading on;set pagesize 60;
Purpose
Section titled “Purpose”This script generates three comprehensive reports from trace data that has been processed by Oracle’s Trace Analyzer (TRCANLZR) utility. It provides detailed analysis of SQL statements, performance metrics, and optimization recommendations.
Key Features
Section titled “Key Features”- Three Report Types: Observations, recommendations, and header summary
- Performance Ranking: SQL statements ranked by resource consumption
- Cost Analysis: Shows CPU, I/O, and total costs
- Optimization Hints: Identifies FULL scans and CARTESIAN joins
Prerequisites
Section titled “Prerequisites”- Trace Analyzer Installation: TRCANLZR must be installed
- Processed Trace Data: Trace files must be loaded into TRCA$ tables
- Access Privileges: SELECT access on TRCANLZR schema objects
- Windows Path: Default output path is d:\temp\ (modify as needed)
Generated Reports
Section titled “Generated Reports”1. Observations Report (trace_obs_*.txt)
Section titled “1. Observations Report (trace_obs_*.txt)”- SQL statement rankings
- Wait time analysis (idle vs non-idle)
- Statement costs (CPU, I/O)
- Performance metrics per SQL
- Actual SQL text
2. Recommendations Report (trace_rec_*.txt)
Section titled “2. Recommendations Report (trace_rec_*.txt)”- Problematic operations (FULL scans, CARTESIAN joins)
- Specific objects involved
- Optimization opportunities
3. Header Report (trace_Hdr_*.txt)
Section titled “3. Header Report (trace_Hdr_*.txt)”- Trace summary information
- Total resource consumption
- SQL statement counts
- Original trace file reference
SQL> @trace_reports.sql Enter Trace id number : 12345
spooling observations to d:\temp\trace_obs_12345.txtspooling Recommendations to d:\temp\trace_rec_12345.txtspooling Trace Header to d:\temp\trace_Hdr_12345.txt
Report Contents
Section titled “Report Contents”Observations Include
Section titled “Observations Include”- Hash values and rankings
- Wait times (idle and non-idle)
- Statement costs
- Execution statistics (CPU, elapsed, I/O, rows)
- SQL text
Recommendations Focus On
Section titled “Recommendations Focus On”- FULL table scans
- CARTESIAN joins
- Objects requiring optimization
Header Summary Shows
Section titled “Header Summary Shows”- End date and time
- Instance and schema information
- SQL counts (total and unique)
- Resource totals (CPU, elapsed, I/O)
- Original trace filename
Customization Options
Section titled “Customization Options”- Output Directory: Change from d:\temp\ to your preferred location
- Result Limits: Modify rownum restrictions for more/fewer results
- Filter Criteria: Add additional WHERE clauses for specific analysis
Best Practices
Section titled “Best Practices”- Trace Collection: Use proper trace levels (binds and waits)
- Regular Analysis: Process traces promptly after collection
- Baseline Comparison: Compare with known good performance
- Action Tracking: Document optimizations implemented
Related Tools
Section titled “Related Tools”- TKPROF: Oracle’s basic trace file formatter
- OraSRP: Session Resource Profiler
- Method-R Profiler: Commercial trace analysis tool