#!/bin/bash

AVGLEN=10

for f in tpcc.*.res
do 
  ../ts_extract.pl <$f >$f.dat
  ../mv_average.pl -i $AVGLEN <$f.dat >$f.dat.avg
done

for f in pfs.tpcc.*.txt
do
  b=${f%%.txt}
  for m in log_sys_mutex log_flush_order_mutex flush_list_mutex buf_pool_mutex
  do
    ../pfs_extract.pl $m <$f >$b.$m
    ../mv_average3.pl -i $AVGLEN <$b.$m >$b.$m.avg
  done
done

for f in pfs.oltp.load.txt
do
  b=${f%%.txt}
  for m in log_latch lock_latch fil_space_latch flush_list_mutex
  do
    ../pfs_extract.pl $m <$f >$b.$m
    ../mv_average3.pl -i $AVGLEN <$b.$m >$b.$m.avg
  done
done

for f in status.*.txt
do
  b=${f%%.txt} 
  for v in Innodb_checkpoint_age Innodb_buffer_pool_pages_data Innodb_buffer_pool_pages_dirty Innodb_history_list_length
  do
    ../status_extract.pl $v <$f >$b.$v
    ../mv_average.pl -i $AVGLEN <$b.$v >$b.$v.avg
  done 
  for v in Innodb_buffer_pool_pages_flushed Innodb_buffer_pool_pages_lru_flushed Innodb_os_log_written Innodb_data_written Innodb_os_log_fsyncs Innodb_pages_created Innodb_buffer_pool_pages_split Com_commit Handler_commit
  do
    ../status_extract.pl -r $v <$f >$b.$v
    ../mv_average.pl -i $AVGLEN <$b.$v >$b.$v.avg
  done
  for v in Innodb_os_log_fsyncs Innodb_os_log_written Com_commit
  do
    join $b.$v     $b.Handler_commit     >$b.${v}_per_commit
    join $b.$v.avg $b.Handler_commit.avg >$b.${v}_per_commit.avg
  done
done

for f in iostat.tpcc.*.txt iostat.oltp.load.txt
do
  ../iostat_extract.pl -c 10 <$f >${f%%.txt}.cpu
  ../iostat_extract.pl --nocpu -d sdc 10 <$f >${f%%.txt}.disk
  ../mv_average3.pl -i $AVGLEN <${f%%.txt}.disk >${f%%.txt}.disk.avg
done

./tpcc_ts.gluplot

