view time.pl @ 0:54da0bd509b0

commit
author pitagora <ryota.yamanaka@riken.jp>
date Tue, 31 Mar 2015 03:21:33 +0900
parents
children
line wrap: on
line source

use Time::Local 'timegm';
use POSIX 'strftime';

my $file = "/home/galaxy/galaxy-dist/paster.log";
open(my $fh, "<", $file)
  or die "Cannot open $file: $!";

my %dic_sta;
my %dic_end;

while (my $line = readline $fh) {
  if ($line =~ /([0-9]+)-([0-9]+)-([0-9]+) ([0-9]+):([0-9]+):([0-9]+),[0-9]+ \(([0-9]+)\) Job dispatched/) {
    #print $line;
    $sec_sta = timegm($6, $5, $4, $3, $2 - 1, $1);
    $dic_sta{$7} = $sec_sta;
  }
  if ($line =~ /galaxy.jobs DEBUG ([0-9]+)-([0-9]+)-([0-9]+) ([0-9]+):([0-9]+):([0-9]+),[0-9]+ job ([0-9]+) ended/) {
    #print $line;
    $sec_end = timegm($6, $5, $4, $3, $2 - 1, $1);
    $dic_end{$7} = $sec_end;
  }
}

foreach (sort {$b<=>$a} keys %dic_sta) {
  $time_sta = $dic_sta{$_};
  $time_end = $dic_end{$_};
  print "Dataset ", $_, "\t", strftime("%Y-%m-%d %H:%M:%S", localtime($time_sta)), "\t";
  if ($time_end != "") {
    $total = $time_end - $time_sta;
    $hour  = int($total/60/60);
    $min   = int(($total - $hour*60*60)/60);
    $sec   = $total - $hour*60*60 - $min*60;
    print strftime("%Y-%m-%d %H:%M:%S", localtime($time_end)), "\t", $hour, " hour\t", $min, " min\t", $sec,  " sec\n";
  } else {
    print "Running or aborted.\t-\t-\t-\n";
  }
}