benchmark.pl: Skip ecryptfs if mount.ecryptfs is not available

Allows the benchmark to work on OS X or when ecryptfs is not
installed.
Also, introduce stopwatch_start/stop helpers to cut down copy-paste
code.
This commit is contained in:
Jakob Unterwurzacher 2014-12-14 16:59:47 +01:00
parent 3643924ba3
commit 517c7bc948

View File

@ -5,6 +5,7 @@
use Time::HiRes qw( time ); use Time::HiRes qw( time );
use File::Temp; use File::Temp;
use warnings; use warnings;
use feature 'state';
require("tests/common.pl"); require("tests/common.pl");
@ -53,6 +54,12 @@ sub mount_encfs {
} }
sub mount_ecryptfs { sub mount_ecryptfs {
if(system("which mount.ecryptfs > /dev/null") != 0) {
print "skipping ecryptfs\n";
return "";
}
my $workingDir = shift; my $workingDir = shift;
my $c = "$workingDir/ecryptfs_ciphertext"; my $c = "$workingDir/ecryptfs_ciphertext";
@ -76,54 +83,70 @@ sub ms {
return $milliseconds; return $milliseconds;
} }
# stopwatch_start($name)
# start the stopwatch for test "$name"
sub stopwatch_start {
stopwatch(1, shift);
}
# stopwatch_stop(\@results)
# stop the stopwatch, save time into @results
sub stopwatch_stop {
stopwatch(0, shift);
}
sub stopwatch {
state $start_time;
state $name;
my $start = shift;
if($start) {
$name = shift;
print("# $name... ");
$start_time = time();
} else {
my $delta = ms(time() - $start_time);
print("$delta ms\n");
my $results = shift;
push( $results, [ $name, $delta, 'ms' ] );
}
}
sub benchmark { sub benchmark {
my $dir = shift; my $dir = shift;
my $start;
our $linuxgz; our $linuxgz;
my $delta;
my $line;
my @results = (); my @results = ();
system("sync"); system("sync");
print("# stream_write... "); stopwatch_start("stream_write");
$start = time();
writeZeroes( "$dir/zero", 1024 * 1024 * 100 ); writeZeroes( "$dir/zero", 1024 * 1024 * 100 );
system("sync"); system("sync");
$delta = time() - $start; stopwatch_stop(\@results);
push( @results, [ 'stream_write', int( 100 / $delta ), "MiB/s" ] );
printf("done\n");
unlink("$dir/zero"); unlink("$dir/zero");
system("sync"); system("sync");
system("cat $linuxgz > /dev/null"); system("cat $linuxgz > /dev/null");
print("# extract... "); stopwatch_start("extract");
$start = time();
system("tar xzf $linuxgz -C $dir"); system("tar xzf $linuxgz -C $dir");
system("sync"); system("sync");
$delta = ms( time() - $start ); stopwatch_stop(\@results);
push( @results, [ 'extract', $delta, "ms" ] );
print("done\n");
$du = qx(du -sm $dir | cut -f1); $du = qx(du -sm $dir | cut -f1);
push( @results, [ 'du', $du, 'MB' ] ); push( @results, [ 'du', $du, 'MiB' ] );
printf( "# disk space used: %d MB\n", $du ); printf( "# disk space used: %d MiB\n", $du );
system("echo 3 > /proc/sys/vm/drop_caches"); system("echo 3 > /proc/sys/vm/drop_caches");
$start = time(); stopwatch_start("rsync");
system("rsync -an $dir /tmp"); system("rsync -an $dir /tmp");
$delta = time() - $start; stopwatch_stop(\@results);
push( @results, [ 'rsync', ms($delta), 'ms' ] );
printf( "# rsync took %d ms\n", ms($delta) );
system("echo 3 > /proc/sys/vm/drop_caches"); system("echo 3 > /proc/sys/vm/drop_caches");
system("sync"); system("sync");
$start = time(); stopwatch_start("rm");
system("rm -Rf $dir/*"); system("rm -Rf $dir/*");
system("sync"); system("sync");
$delta = time() - $start; stopwatch_stop(\@results);
push( @results, [ 'delete', ms($delta), 'ms' ] );
printf( "# delete took %d ms\n", ms($delta) );
return \@results; return \@results;
} }
@ -134,7 +157,10 @@ sub tabulate {
$r = shift; $r = shift;
my @encfs = @{$r}; my @encfs = @{$r};
$r = shift; $r = shift;
my @ecryptfs = @{$r}; my @ecryptfs;
if($r) {
@ecryptfs = @{$r};
}
print " Test | EncFS | eCryptfs | EncFS advantage\n"; print " Test | EncFS | eCryptfs | EncFS advantage\n";
print ":---------------|-------------:|-------------:|---------------:\n"; print ":---------------|-------------:|-------------:|---------------:\n";
@ -144,12 +170,17 @@ sub tabulate {
my $unit = $encfs[$i][2]; my $unit = $encfs[$i][2];
my $en = $encfs[$i][1]; my $en = $encfs[$i][1];
my $ec = $ecryptfs[$i][1]; my $ec = 0;
my $ratio = 0;
my $ratio = $ec / $en; if( @ecryptfs ) {
$ec = $ecryptfs[$i][1];
$ratio = $ec / $en;
if ( $unit =~ m!/s! ) { if ( $unit =~ m!/s! ) {
$ratio = $en / $ec; $ratio = $en / $ec;
} }
}
printf( "%-15s | %6d %-5s | %6d %-5s | %2.2f\n", printf( "%-15s | %6d %-5s | %6d %-5s | %2.2f\n",
$test, $en, $unit, $ec, $unit, $ratio ); $test, $en, $unit, $ec, $unit, $ratio );
} }
@ -180,7 +211,10 @@ sub main {
print "# mounting ecryptfs\n"; print "# mounting ecryptfs\n";
$mountpoint = mount_ecryptfs($workingDir); $mountpoint = mount_ecryptfs($workingDir);
my $ecryptfs_results = benchmark($mountpoint); my $ecryptfs_results;
if($mountpoint) {
$ecryptfs_results = benchmark($mountpoint);
}
cleanup($workingDir); cleanup($workingDir);