X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXUtil.pm;h=4477a94bef90a3ef8e5abdc5ad5814fc53eb3bbb;hb=a460c345801374bfdccaf135ab1b03e5115f4266;hp=b9afba12d29dba40bfea78cde38b570642551d70;hpb=65f4d068c56ddb6e25d1f62b7ca6fd43741386b3;p=spider.git diff --git a/perl/DXUtil.pm b/perl/DXUtil.pm index b9afba12..4477a94b 100644 --- a/perl/DXUtil.pm +++ b/perl/DXUtil.pm @@ -13,7 +13,7 @@ use Date::Parse; use IO::File; use File::Copy; use Data::Dumper; - +use Time::HiRes qw(gettimeofday tv_interval); use strict; @@ -27,6 +27,7 @@ require Exporter; print_all_fields cltounix unpad is_callsign is_latlong is_qra is_freq is_digits is_pctext is_pcflag insertitem deleteitem is_prefix dd is_ipaddr $pi $d2r $r2d localdata localdata_mv + diffms _diffms ); @@ -471,16 +472,14 @@ sub deleteitem sub localdata { my $ifn = shift; - my $ofn = "$main::data/$ifn"; + my $ofn = "$main::local_data/$ifn"; my $tfn; if (-e "$main::local_data") { - $tfn = "$main::local_data/$ifn"; + $tfn = "$main::data/$ifn"; if (-e $tfn && -e $ofn) { - $ofn = $tfn if -M $tfn < -M $ofn; - } elsif (-e $tfn) { - $ofn = $tfn; - } + $ofn = $tfn if -M $ofn < -M $tfn; + } } return $ofn; @@ -497,3 +496,27 @@ sub localdata_mv } } +# measure the time taken for something to happen; use Time::HiRes qw(gettimeofday tv_interval); +sub _diffms +{ + my $ta = shift; + my $tb = shift || [gettimeofday]; + my $a = int($ta->[0] * 1000) + int($ta->[1] / 1000); + my $b = int($tb->[0] * 1000) + int($tb->[1] / 1000); + return $b - $a; +} + +sub diffms +{ + my $call = shift; + my $line = shift; + my $ta = shift; + my $no = shift; + my $tb = shift; + my $msecs = _diffms($ta, $tb); + + $line =~ s|\s+$||; + my $s = "subprocess stats cmd: '$line' $call ${msecs}mS"; + $s .= " $no lines" if $no; + DXDebug::dbg($s); +}