Use hires time to give better bandwidth reporitng

This commit is contained in:
Isaac Connor 2019-07-23 14:34:26 -04:00
parent d4eae18055
commit bb653b172c
1 changed files with 10 additions and 9 deletions

View File

@ -41,6 +41,7 @@ require Number::Bytes::Human;
require Date::Parse; require Date::Parse;
require POSIX; require POSIX;
use Date::Format qw(time2str); use Date::Format qw(time2str);
use Time::HiRes qw(gettimeofday tv_interval);
#our @ISA = qw(ZoneMinder::Object); #our @ISA = qw(ZoneMinder::Object);
use parent qw(ZoneMinder::Object); use parent qw(ZoneMinder::Object);
@ -595,7 +596,7 @@ Debug("Files to move @files");
for my $file (@files) { for my $file (@files) {
next if $file =~ /^\./; next if $file =~ /^\./;
( $file ) = ( $file =~ /^(.*)$/ ); # De-taint ( $file ) = ( $file =~ /^(.*)$/ ); # De-taint
my $starttime = time; my $starttime = [gettimeofday];
Debug("Moving file $file to $NewPath"); Debug("Moving file $file to $NewPath");
my $size = -s $file; my $size = -s $file;
if ( ! $size ) { if ( ! $size ) {
@ -610,7 +611,7 @@ Debug("Files to move @files");
if ( ! $bucket->add_key($filename, $file_contents) ) { if ( ! $bucket->add_key($filename, $file_contents) ) {
die "Unable to add key for $filename"; die "Unable to add key for $filename";
} }
my $duration = time - $starttime; my $duration = tv_interval($starttime);
Debug('PUT to S3 ' . Number::Bytes::Human::format_bytes($size) . " in $duration seconds = " . Number::Bytes::Human::format_bytes($duration?$size/$duration:$size) . '/sec'); Debug('PUT to S3 ' . Number::Bytes::Human::format_bytes($size) . " in $duration seconds = " . Number::Bytes::Human::format_bytes($duration?$size/$duration:$size) . '/sec');
} # end foreach file. } # end foreach file.
@ -641,20 +642,20 @@ Debug("Files to move @files");
my @files = glob("$OldPath/*"); my @files = glob("$OldPath/*");
if ( ! @files ) { if ( ! @files ) {
$ZoneMinder::Database::dbh->commit(); $ZoneMinder::Database::dbh->commit();
return "No files to move."; return 'No files to move.';
} }
for my $file (@files) { for my $file (@files) {
next if $file =~ /^\./; next if $file =~ /^\./;
( $file ) = ( $file =~ /^(.*)$/ ); # De-taint ( $file ) = ( $file =~ /^(.*)$/ ); # De-taint
my $starttime = time; my $starttime = [gettimeofday];
Debug("Moving file $file to $NewPath"); Debug("Moving file $file to $NewPath");
my $size = -s $file; my $size = -s $file;
if ( ! File::Copy::copy( $file, $NewPath ) ) { if ( ! File::Copy::copy( $file, $NewPath ) ) {
$error .= "Copy failed: for $file to $NewPath: $!"; $error .= "Copy failed: for $file to $NewPath: $!";
last; last;
} }
my $duration = time - $starttime; my $duration = tv_interval($starttime);
Debug('Copied ' . Number::Bytes::Human::format_bytes($size) . " in $duration seconds = " . ($duration?Number::Bytes::Human::format_bytes($size/$duration):'inf') . '/sec'); Debug('Copied ' . Number::Bytes::Human::format_bytes($size) . " in $duration seconds = " . ($duration?Number::Bytes::Human::format_bytes($size/$duration):'inf') . '/sec');
} # end foreach file. } # end foreach file.
} # end if ! moved } # end if ! moved