set echo off;
set feedback off;
set verify off;

connect sys/manion3;


Rem ********************************************************************
Rem                Gather Ending Statistics
Rem ********************************************************************

insert into stats$end_file select * from stats$file_view;


Rem ********************************************************************
Rem                Create Summary Tables
Rem ********************************************************************
 
alter session set nls_date_format = 'YYYY-MM-DD-HH-mi';

insert into sys.filestat@sa9
(
select 
       sysdate,
       &1,
       substr(b.name,
           (instr(b.name,'/',1,3)+1),
           ((instr(b.name,'/',1,4)-1)-(instr(b.name,'/',1,3)))),
       b.ts,
       substr(b.name,
           (instr(b.name,'/',1,4)+1),
           (length(b.name)-(instr(b.name,'/',1,3)-1))),
       e.pyr-b.pyr,
       e.pbr-b.pbr,
       e.prt-b.prt,
       e.pyw-b.pyw,
       e.pbw-b.pbw,
       e.pwt-b.pwt
  from stats$begin_file b, stats$end_file e
       where b.name=e.name
);


      insert into sys.sum_filestat@sa9 (
      select
         to_date(to_char(samp_date,'YYYY-MM-DD-HH-MI'),'YYYY-MM-DD-HH-MI') ,
         b.mount_point    ,
         &1,
         sum(phys_blks_rd)   ,
         sum(phys_blks_wr)   ,
         sum(phys_rd_time)   ,
         sum(phys_wrt_tim)   
      from
         sys.vol_grp a,
         sys.filestat b
      where
         a.mount_point = b.mount_point
      and
      to_char(samp_date,'YYYY-MM-DD-HH-MI') in
      (select max(to_char(samp_date,'YYYY-MM-DD-HH-MI')) from sys.filestat)
      group by
         to_date(to_char(samp_date,'YYYY-MM-DD-HH-MI'),'YYYY-MM-DD-HH-MI') ,
         b.mount_point    
      );
