OraPub System Monitor (OSM) Toolkit
Get Complete OSM Toolkit (free)

ashclp.sql
ashclpct.sql
ashp.sql
ashpctcpu.sql
ashpcte.sql
ashpctecl.sql
ashpctes.sql
ashpcts.sql
ashrt.sql
ashrt_old.sql
ashsp.sql
ashspct.sql
ashsqlcl.sql
ashsqle.sql
ashsqlpctcl.sql
ashsqlpctcpu.sql
ashsqlpcte.sql
ashsqlpcts.sql
ashsqlpctt.sql
ashsqls.sql
avgexplore.sql
bc.sql
bc7.sql
bcmap.sql
bcmap7.sql
bcobjfb.sql
chr.sql
clone.sql
cr_rtsp.sql
cu.sql
cycledb6
cycledb9
dboc.sql
delete.me
dev_list.txt
dfio.sql
dfl.sql
diag.sql
ds.sql
ds7.sql
dsn.sql
eval1.sql
event_type.sql
event_type_nc.sql
fgidx.sql
fgtbl.sql
hashchk.sql
idx.sql
iosum.sql
iosum9.sql
iosum9x.sql
iosumx.sql
ip.sql
ipcbc.sql
ipx.sql
irtviews.sql
istat.sql
latch.sql
latch8.sql
latch_old.sql
latchchild.sql
latchclass.sql
latchx.sql
lc.sql
lock.sql
loghist8.sql
lruno.sql
mkodo.sql
mkodo_ouch.sql
mts.sql
mysess.sql
objfb.sql
objloc.sql
ogbigld.sql
ogcrobj.sql
ogdoit.sql
ogobjlst.sql
ogobjset.sql
oracpu.sql
oracputext.sql
oracpux.sql
oracpux1.sql
oracpux2.sql
oscpux.sql
oscpux1.sql
oscpux10.sql
oscpux2.sql
oscpux210.sql
osmclear.sql
osmi.sql
osmprep.sql
osmtitle.sql
osmtitlel.sql
osmtitlell.sql
osmtitlem.sql
osmtitles.sql
rbs.sql
rdohist.sql
readme.txt
rlog.sql
rtc.sql
rtcx.sql
rtio.sql
rtow.sql
rtpctx.sql
rtsess.sql
rtsess9.sql
rtsessx.sql
rtsum.sql
rtsys.sql
rtsysx.sql
rtsysx8.sql
sessinfo.sql
sessinfo9.sql
sesstat.sql
sga.sql
simsql1.sql
simsql2.sql
snap_stats.sql
spspinfo.sql
sqls1.sql
sqls18.sql
sqls19.sql
sqls2.sql
sqls3.sql
sqls4.sql
stu.sql
supers.sql
swenq.sql
swenqc.sql
swenqnew.sql
swenqx.sql
swhist.sql
swhist.sql.sav
swhistx.sql
swhistx.sql.sav
swpct.sql
swpctidle.sql
swpctx.sql
swpctxidle.sql
swsessid.sql
swsid.sql
swsw.sql
swswc.sql
swswp.sql
swsys.sql
sysstat.sql
tbfsum.sql
tcsizing.sql
tcstats.sql
test.sql
timechk.sql
topcpu
topdml.sql
tp.sql
tp9.sql
tsmap.sql
tss.sql
undo.sql
users.sql
-- ********************************************************************
-- * Copyright Notice   : (c)2004 OraPub, Inc.
-- * Filename           : cr_rtsp.sql 
-- * Author             : Craig A. Shallahamer
-- * Original           : 11-oct-04
-- * Last Update        : 11-oct-04
-- * Description        : cr_rtsp.sql  - Create RT session profile procedure
-- * Usage              : start cr_rtsp.sql
-- ********************************************************************

-- rt  = st + qt + uat
-- qt  = qiot + qnc + qot
-- rt  = st + qiot + qnc + qot + uat
--
-- where:	rt  = response time
--		qt  = queue time (wait event time + cpu system time)
--		st  = service time (cpu user time)
--		uat = unaccounted for time (tool usage error, uninstrumented time, etc.)
--		qiot= queue io time
--		qnc = queue idle time (network delay, client prog processing)
--		qot = queue other time (various wait events)

connect sys
grant select on v_$mystat to osmmon;
grant select on v_$sesstat to osmmon;
grant select on v_$session_event to osmmon;
grant select on v_$event_name to osmmon;

----------------------------------------
-- Create the supporting objects
----------------------------------------
connect osmmon/osmmon

drop table o$oprtsp_ev;
/
create table o$oprtsp_ev (
  run_name varchar2(2000),
  key varchar2(2000), 
  event varchar(64), 
  t0 number, 
  t1 number
)
/
drop table o$oprtsp_time;
/
create table o$oprtsp_time (
  run_name varchar2(2000),
  key varchar2(2000), 
  start_date date,
  start_time number,
  stop_time  number
)
/

----------------------------------------
-- Create the main procedure
----------------------------------------

create or replace procedure oprtsp 
  (run_name_in in varchar2, situation in number)
   -- name: The name of the run, function, or whatever
   -- situation: 1=on 0=off
is
  u_key  varchar2(2000);
  the_sid    number;

  cursor sid_cur is
	select sid from v$mystat;
  sid_cur_rec sid_cur%rowtype;

  cursor sw_cur is
  	select 	sid,event, time_waited
	from	v$session_event;
  sw_cur_rec sw_cur%rowtype;

begin
  u_key := dbms_session.unique_session_id;

  open sid_cur;
  fetch sid_cur into sid_cur_rec.sid;
  the_sid := sid_cur_rec.sid ;
  close sid_cur;
  --insert into msg values (sysdate,'SID='||sid||' u_key='||u_key);commit;

  if situation = 1
  then
    delete from o$oprtsp_ev  where u_key = u_key and run_name = run_name_in;
    insert into o$oprtsp_ev  select run_name_in,u_key,name,0,0 from v$event_name;
    insert into o$oprtsp_time values (run_name_in,u_key,sysdate,dbms_utility.get_time,dbms_utility.get_time);

    for sw_cur_rec in sw_cur loop
      if sw_cur_rec.sid = the_sid 
      then
        update o$oprtsp_ev 
        set    t0 = sw_cur_rec.time_waited,
               t1 = sw_cur_rec.time_waited
        where  run_name = run_name_in
          and  key      = u_key
          and  event    = sw_cur_rec.event;
      end if;
    end loop ;
    insert into o$oprtsp_ev
      select run_name_in,u_key,'cpu_user',value,value
      from   v$sesstat
      where  statistic# = 316
        and  sid = the_sid;
    insert into o$oprtsp_ev
      select run_name_in,u_key,'cpu_system',value,value
      from   v$sesstat
      where  statistic# = 317
        and  sid = the_sid;

  elsif situation = 0
  then
    for sw_cur_rec in sw_cur loop
      if sw_cur_rec.sid = the_sid
      then
        update o$oprtsp_ev 
        set    t1 = sw_cur_rec.time_waited
        where  key = u_key
          and  run_name = run_name_in
          and  event = sw_cur_rec.event;
      end if;
    end loop ;
    update o$oprtsp_ev
      set  t1 = ( select value from v$sesstat where statistic# = 316 and sid = the_sid)
    where  key = u_key
     and   run_name = run_name_in
     and   event = 'cpu_user';
    update o$oprtsp_ev
      set  t1 = ( select value from v$sesstat where statistic# = 317 and sid = the_sid)
    where  key = u_key
     and   run_name = run_name_in
     and   event = 'cpu_system';
    update o$oprtsp_time
    set    stop_time = dbms_utility.get_time
    where  key = u_key
     and   run_name = run_name_in;
  end if;

  commit;
end;
/

exit;

truncate table o$oprtsp_ev;
truncate table o$oprtsp_time;
exec oprtsp('t0',1);
@mkodo
exec oprtsp('t0',0);
exec oprtsp('t1',1);
@tss
@chr
exec oprtsp('t1',0);
exec oprtsp('t2',1);
select count(*) from odo;
exec oprtsp('t2',0);
exec oprtsp('t3',1);
update odo set c4=0 where c4+0=2;
exec oprtsp('t3',0);

-- This is used to determine the script overhead
exec oprtsp('t4',1);
exec oprtsp('t4',0);
exec oprtsp('t5',1);
exec oprtsp('t5',0);

-- Here is some SQL to get the information

set linesize 130
col key format a20
col run_name a5
col event format a35 trunc
select run_name,key,event,t0,t1,t1-t0 from o$oprtsp_ev where t1›0 order by run_name,key,event;
select run_name,key,to_char(start_date,'DD-Mon-YY HH24:MI:SS'),stop_time-start_time 
from o$oprtsp_time 
order by run_name;




Know what's important before it's too late!



OraPub's
Performance Training

is like no other...




More Class Pics...
Get student testimonials!



Craig Shallahamer's Blog