
def exec_todo=&1

!ps -eaf|grep 'quick'|grep 'sqlplus'|grep -v grep|awk '{print $2}' > /tmp/bogus_ppid.txt
!ps -eaf|grep `cat /tmp/bogus_ppid.txt` |grep "oracle${ORACLE_SID}" | grep -v grep | awk '{print $2}' > /tmp/bogus_spid.txt
!procstat `cat /tmp/bogus_spid.txt` | grep 'utime\|stime' | awk '{print $2}' | awk '{sum+=$1} END {print sum}' >/tmp/procCpuT0.txt

begin
declare
  sleep_time_v number := 3.00;
  mysid_v number;
  execs_total_v number;
  time_t0_v timestamp;
  time_t1_v timestamp;
  time_delta_s_v number;
  cpu_t0_v number;
  cpu_t1_v number;
  cpu_delta_s_v number;
  wait_All_t0_v number;
  wait_All_t1_v number;
  wait_All_delta_s_v number;
  wait_NIdle_t0_v number;
  wait_NIdle_t1_v number;
  wait_NIdle_delta_s_v number;
  wait_Idle_t0_v number;
  wait_Idle_t1_v number;
  wait_Idle_delta_s_v number;
  avg_time_s_per_exec_v number;
  bogus1_v number;
  bogus2_v number;
  cpu_sql_t0_v number;
  cpu_sql_t1_v number;
  cpu_sql_delta_s_v number;
  bogus_date_v date;
begin

execs_total_v  := 0;

select sid into mysid_v from v$mystat where rownum=1;

select value into cpu_t0_v from v$sess_time_model where sid=mysid_v and stat_name = 'DB CPU';
select current_timestamp into time_t0_v from dual;

while ( execs_total_v < &exec_todo )
loop
      	select count(object_id), sum(object_id) 
	into   bogus1_v, bogus2_v 
	from   customers;

      	execs_total_v  := execs_total_v + 1 ;
end loop;

dbms_lock.sleep(sleep_time_v);

select value into cpu_t1_v from v$sess_time_model where sid=mysid_v and stat_name = 'DB CPU';
select current_timestamp into time_t1_v from dual;

select (cpu_t1_v-cpu_t0_v)/1000000 into cpu_delta_s_v from dual;
select op_get_interval_s(time_t1_v-time_t0_v)-sleep_time_v into time_delta_s_v from dual;

avg_time_s_per_exec_v := time_delta_s_v / execs_total_v ;

delete from op_sql_results;

wait_All_delta_s_v := 0;
wait_NIdle_delta_s_v := 0;
wait_Idle_delta_s_v := 0;

insert into op_sql_results 
	values (execs_total_v, time_delta_s_v, cpu_delta_s_v, 
                wait_All_delta_s_v, wait_NIdle_delta_s_v, wait_Idle_delta_s_v, 
                avg_time_s_per_exec_v );
commit;

end;
end;
/

!procstat `cat /tmp/bogus_spid.txt` | grep 'utime\|stime' | awk '{print $2}' | awk '{sum+=$1} END {print sum}' >/tmp/procCpuT1.txt

exit;




