-- ********************************************************************
-- * Copyright Notice : (c)1998-2007 OraPub, Inc.
-- * Filename : sqls1.sql
-- * Author : Craig A. Shallahamer
-- * Original : 17-AUG-98
-- * Last Update : 16-mar-07
-- * Description : Identify top SQL statements.
-- * Usage : start sqls1.sql min disk rds min buff rds
-- * Thanks 1) Thanks to Geert van Lierop for tip to use
-- * "address" instead of "hash_value".
-- * 2) Thanks to Ghassan Salem for taking the time
-- * to create the core wait based loading code.
-- ********************************************************************
def min_blocks=&&1
prompt For proper sort and output, swpctx.sql must have been run.
prompt
def osm_prog = 'sqls1.sql'
def osm_title = 'Intelligent Top SQL Statement Activity Summary'
col mod heading 'Stmt Addr' format a16
col dr heading 'Phys Rds|(k)' format 999,999
col bg heading 'Log Rds|(k)' format 999,999
col cpu heading 'CPU Time|(min)' format 999,990.0
col sr heading 'Sorts' format 9,999
col exe heading 'Runs' format 999,999
col rows_p heading 'Rows|(k)' format 99,990
col load heading 'Load Factor' format 999,999 noprint
col pio_time heading 'Sec/PIO' format 90.000
col lio_time heading 'Sec/LIO' format 90.000
col exe_time heading 'Sec/EXE' format 9,990.00
col etime heading 'Tot Time|(min)' format 99,990.0
col stype heading 'Stmt|Type' format a5
start osmtitlem
select
a.address mod,
(a.elapsed_time/1000000)/(a.executions+0.0000001) exe_time,
a.disk_reads/1000 dr,
a.buffer_gets/1000 bg,
a.elapsed_time/1000000/60 etime,
a.cpu_time/1000000/60 cpu,
(a.elapsed_time/1000000)/(a.disk_reads+0.00000001) pio_time,
(a.elapsed_time/1000000)/(a.buffer_gets+0.00000001) lio_time,
a.executions exe,
a.rows_processed/1000 ROWS_p,
a.sorts sr,
substr(a.sql_text,1,5) stype,
case when b.type ='io' then a.disk_reads else a.buffer_gets end load
from
v$sqlarea a,
(
select /*+ no_merge*/ type
from ( select substr(b.type,1,2) type,
sum(a.time_waited-c.time_waited) wt--,
from v$system_event a,
o$event_type b,
system_event_snap c
where a.event=b.event
and a.event=c.event
and b.type not in ('bogus','idle')
group by substr(b.type,1,2)
order by 2 desc
)
where rownum=1
) b
where
case when b.type ='io' then a.disk_reads else a.buffer_gets end &min_blocks
order by
load desc
/
undef min_blocks
start osmclear