------------------------------------------------------------
-- file ashepctecl.sql
-- desc ASH system level by event, client id, wait pct (min partial event)
-- author Craig A. Shallahamer, craig@orapub.com
-- orig 30-May-08
-- lst upt 30-May-08
-- copyright (c)2008 OraPub, Inc.
-- It is possible to get percentages greater/lesser than 100% because there
-- is a time lag between the total calculations and the report query
------------------------------------------------------------
def sleep_time_min=&1
def partial_event=&2
set echo off
set feedback off
set heading on
set verify off
set termout on
def osm_prog = 'ashpctecl.sql'
def osm_title = 'System Level ASH By Event, client ID, Wait Percent (last &sleep_time_min min)'
start osmtitle
col event format a30 heading "Wait Event" trunc
col time_pct format 990.00 heading "% Time|Waited"
col client_id format a25 heading "Client ID"
-- select by_sess.event,by_sess.session_id,by_sess.wait_time,by_event.wait_time,by_sess.wait_time/by_event.wait_time pct_thing
select by_sess.event,
by_sess.client_id,
100*(by_sess.tw_time/by_event.tw_time) time_pct
from (
select ash.event,ash.client_id,
sum(ash.wait_time+ash.time_waited) tw_time
from v$active_session_history ash
where ash.sample_time between (sysdate-&sleep_time_min/(60*24)) and sysdate
and ash.event like '%&partial_event%'
group by ash.event,ash.client_id
) by_sess,
(
select tot.event,sum(tot.wait_time+tot.time_waited) tw_time
from v$active_session_history tot
where tot.sample_time between (sysdate-&sleep_time_min/(60*24)) and sysdate
and tot.event like '%&partial_event%'
group by tot.event
) by_event
where by_sess.event = by_event.event
and by_event.tw_time 0
and 100*(by_sess.tw_time/by_event.tw_time) 0.001
order by 1,3 desc,2
/
start osmclear
--This may be helpful
--select to_char(sysdate,'DD-Mon-YY HH24:MI:SS') now,
-- to_char(sysdate-24/24,'DD-Mon-YY HH24:MI:SS') one_day_prior,
-- to_char(sysdate-1/24,'DD-Mon-YY HH24:MI:SS') one_hour_prior,
-- to_char(sysdate-1/(60*24),'DD-Mon-YY HH24:MI:SS') one_min_prior,
-- to_char(sysdate-30/(60*24),'DD-Mon-YY HH24:MI:SS') thirty_min_prior
--from dual;