From 400d87892748fe2093edb99fe5a6ac6c4b464956 Mon Sep 17 00:00:00 2001 From: martinahansen Date: Sat, 6 Jun 2009 15:22:43 +0000 Subject: [PATCH] fixing status git-svn-id: http://biopieces.googlecode.com/svn/trunk@486 74ccb610-7750-0410-82ae-013aeee3265d --- bp_bin/split_vals | 16 ++++------- code_perl/Maasha/Biopieces.pm | 53 +++++++++++++++++++++++++++++++++++ code_perl/Maasha/Common.pm | 45 +++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 10 deletions(-) diff --git a/bp_bin/split_vals b/bp_bin/split_vals index bdd8104..f7249f8 100755 --- a/bp_bin/split_vals +++ b/bp_bin/split_vals @@ -33,7 +33,7 @@ use Maasha::Biopieces; # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -my ( $run_time_beg, $run_time_end, $options, $in, $out, $record, @vals, $i ); +my ( $options, $in, $out, $record, @vals, $i ); $options = Maasha::Biopieces::parse_options( [ @@ -68,26 +68,22 @@ while ( $record = Maasha::Biopieces::get_record( $in ) ) Maasha::Biopieces::put_record( $record, $out ); } +Maasha::Biopieces::close_stream( $in ); +Maasha::Biopieces::close_stream( $out ); + # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< BEGIN { - $run_time_beg = Maasha::Biopieces::run_time(); - - Maasha::Biopieces::log_biopiece(); + Maasha::Biopieces::status_set(); } END { - Maasha::Biopieces::close_stream( $in ); - Maasha::Biopieces::close_stream( $out ); - - $run_time_end = Maasha::Biopieces::run_time(); - - Maasha::Biopieces::run_time_print( $run_time_beg, $run_time_end, $options ); + Maasha::Biopieces::status_log(); } diff --git a/code_perl/Maasha/Biopieces.pm b/code_perl/Maasha/Biopieces.pm index 44369a8..414c630 100644 --- a/code_perl/Maasha/Biopieces.pm +++ b/code_perl/Maasha/Biopieces.pm @@ -56,6 +56,59 @@ $SIG{ 'INT' } = \&sig_handler; $SIG{ 'TERM' } = \&sig_handler; +sub status_set +{ + my ( $time_stamp, $script, $user, $pid, $file, $fh ); + + $time_stamp = Maasha::Common::time_stamp(); + $user = Maasha::Common::get_user(); + $script = Maasha::Common::get_scriptname(); + $pid = Maasha::Common::get_processid(); + + $file = "$ENV{ 'BP_TMP' }/" . join( ".", $user, $script, $pid ) . ".status"; + $fh = Maasha::Filesys::file_write_open( $file ); + + print $fh join( ";", $time_stamp, join( " ", @ARGV ) ) . "\n"; + + close $fh; +} + + +sub status_log +{ + my ( $time0, $time1, $script, $user, $pid, $file, $fh, $elap, $fh_global, $fh_local, $line, $args ); + + $time1 = Maasha::Common::time_stamp(); + $user = Maasha::Common::get_user(); + $script = Maasha::Common::get_scriptname(); + $pid = Maasha::Common::get_processid(); + + $file = "$ENV{ 'BP_TMP' }/" . join( ".", $user, $script, $pid ) . ".status"; + $fh = Maasha::Filesys::file_read_open( $file ); + $line = <$fh>; + chomp $line; + close $fh; + + unlink $file; + + ( $time0, $args ) = split /;/, $line; + + $elap = Maasha::Common::time_stamp_diff( $time0, $time1 ); + + $fh_global = Maasha::Filesys::file_append_open( "$ENV{ 'BP_LOG' }/biopieces.log" ); + $fh_local = Maasha::Filesys::file_append_open( "$ENV{ 'HOME' }/.biopieces.log" ); + + print $fh_global join( "\t", $time0, $time1, $elap, $user, $script, $args ) . "\n"; + print $fh_local join( "\t", $time0, $time1, $elap, $user, "$script $args" ) . "\n"; + + $fh_global->autoflush( 1 ); + $fh_local->autoflush( 1 ); + + close $fh_global; + close $fh_local; +} + + sub log_biopiece { # Martin A. Hansen, January 2008. diff --git a/code_perl/Maasha/Common.pm b/code_perl/Maasha/Common.pm index d998d80..83c9633 100644 --- a/code_perl/Maasha/Common.pm +++ b/code_perl/Maasha/Common.pm @@ -601,6 +601,51 @@ sub time_stamp } +sub time_stamp_diff +{ + # Martin A. Hansen, June 2009. + + # Return the difference between two time stamps in + # the time stamp format. + + my ( $t0, # time stamp 0 + $t1, # time stamp 1 + ) = @_; + + # Returns a time stamp string. + + my ( $year0, $mon0, $day0, $hour0, $min0, $sec0, + $year1, $mon1, $day1, $hour1, $min1, $sec1, + $year, $mon, $day, $hour, $min, $sec ); + + $t0 =~ /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/; + $year0 = $1; + $mon0 = $2; + $day0 = $3; + $hour0 = $4; + $min0 = $5; + $sec0 = $6; + + $t1 =~ /(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/; + $year1 = $1; + $mon1 = $2; + $day1 = $3; + $hour1 = $4; + $min1 = $5; + $sec1 = $6; + + $year = $year1 - $year0; + $mon = $mon1 - $mon0; + $day = $day1 - $day0; + $hour = $hour1 - $hour0; + $min = $min1 - $min0; + $sec = $sec1 - $sec0; + + #return "$year-$mon-$day $hour:$min:$sec"; + return join( ":", sprintf( "%02d", $hour ), sprintf( "%02d", $min ), sprintf( "%02d", $sec ) ); +} + + sub process_running { # Martin A. Hansen, July 2008. -- 2.39.5