AWR(DBA_HIST*)から待機イベントクラス別のDB時間を抽出して時系列グラフにしたときのSQL。
かなり力技・・・
SELECT runtime ,
e.wait_class,
SUM(e.time_waited)
FROM
(
SELECT e1.snap_id ,
e1.dbid ,
e1.instance_number,
e1.EVENT_NAME ,
e1.wait_class ,
(e1.TIME_WAITED_MICRO-e2.time_waited_micro)/1000000 "TIME_WAITED"
FROM dba_hist_system_event e1,
dba_hist_system_event e2
WHERE e1.snap_id =e2.snap_id+1
AND e1.dbid =e2.dbid
AND e1.instance_number=e2.instance_number
AND e1.event_id =e2.EVENT_ID
AND e1.DBID =:dbid
AND e1.wait_class !='Idle'
) e,
(
SELECT snap_id ,
dbid ,
instance_number,
TO_CHAR(BEGIN_INTERVAL_TIME, 'YY-MM-DD HH24:MI:SS') runtime
FROM dba_hist_snapshot
WHERE DBID =:dbid
AND begin_interval_time > :start_time
AND begin_interval_time < :end_time
ORDER BY snap_id DESC
) s
WHERE e.snap_id =s.snap_id
AND e.dbid =s.dbid
AND e.instance_number=s.instance_number
GROUP BY runtime,
wait_class
ORDER BY runtime