From 517c7bc948e07f701b8127b7757cca93b74d7c79 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 14 Dec 2014 16:59:47 +0100 Subject: [PATCH 1/3] 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. --- tests/benchmark.pl | 106 ++++++++++++++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 36 deletions(-) diff --git a/tests/benchmark.pl b/tests/benchmark.pl index f1ef1b2..26d9624 100755 --- a/tests/benchmark.pl +++ b/tests/benchmark.pl @@ -5,6 +5,7 @@ use Time::HiRes qw( time ); use File::Temp; use warnings; +use feature 'state'; require("tests/common.pl"); @@ -53,6 +54,12 @@ sub mount_encfs { } sub mount_ecryptfs { + + if(system("which mount.ecryptfs > /dev/null") != 0) { + print "skipping ecryptfs\n"; + return ""; + } + my $workingDir = shift; my $c = "$workingDir/ecryptfs_ciphertext"; @@ -76,54 +83,70 @@ sub ms { 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 { my $dir = shift; - my $start; our $linuxgz; - my $delta; - my $line; my @results = (); system("sync"); - print("# stream_write... "); - $start = time(); - writeZeroes( "$dir/zero", 1024 * 1024 * 100 ); - system("sync"); - $delta = time() - $start; - push( @results, [ 'stream_write', int( 100 / $delta ), "MiB/s" ] ); - printf("done\n"); + stopwatch_start("stream_write"); + writeZeroes( "$dir/zero", 1024 * 1024 * 100 ); + system("sync"); + stopwatch_stop(\@results); unlink("$dir/zero"); system("sync"); system("cat $linuxgz > /dev/null"); - print("# extract... "); - $start = time(); - system("tar xzf $linuxgz -C $dir"); - system("sync"); - $delta = ms( time() - $start ); - push( @results, [ 'extract', $delta, "ms" ] ); - print("done\n"); + stopwatch_start("extract"); + system("tar xzf $linuxgz -C $dir"); + system("sync"); + stopwatch_stop(\@results); $du = qx(du -sm $dir | cut -f1); - push( @results, [ 'du', $du, 'MB' ] ); - printf( "# disk space used: %d MB\n", $du ); + push( @results, [ 'du', $du, 'MiB' ] ); + printf( "# disk space used: %d MiB\n", $du ); system("echo 3 > /proc/sys/vm/drop_caches"); - $start = time(); - system("rsync -an $dir /tmp"); - $delta = time() - $start; - push( @results, [ 'rsync', ms($delta), 'ms' ] ); - printf( "# rsync took %d ms\n", ms($delta) ); + stopwatch_start("rsync"); + system("rsync -an $dir /tmp"); + stopwatch_stop(\@results); system("echo 3 > /proc/sys/vm/drop_caches"); system("sync"); - $start = time(); - system("rm -Rf $dir/*"); - system("sync"); - $delta = time() - $start; - push( @results, [ 'delete', ms($delta), 'ms' ] ); - printf( "# delete took %d ms\n", ms($delta) ); + stopwatch_start("rm"); + system("rm -Rf $dir/*"); + system("sync"); + stopwatch_stop(\@results); return \@results; } @@ -134,7 +157,10 @@ sub tabulate { $r = shift; my @encfs = @{$r}; $r = shift; - my @ecryptfs = @{$r}; + my @ecryptfs; + if($r) { + @ecryptfs = @{$r}; + } print " Test | EncFS | eCryptfs | EncFS advantage\n"; print ":---------------|-------------:|-------------:|---------------:\n"; @@ -144,12 +170,17 @@ sub tabulate { my $unit = $encfs[$i][2]; my $en = $encfs[$i][1]; - my $ec = $ecryptfs[$i][1]; + my $ec = 0; + my $ratio = 0; - my $ratio = $ec / $en; - if ( $unit =~ m!/s! ) { - $ratio = $en / $ec; + if( @ecryptfs ) { + $ec = $ecryptfs[$i][1]; + $ratio = $ec / $en; + if ( $unit =~ m!/s! ) { + $ratio = $en / $ec; + } } + printf( "%-15s | %6d %-5s | %6d %-5s | %2.2f\n", $test, $en, $unit, $ec, $unit, $ratio ); } @@ -180,7 +211,10 @@ sub main { print "# mounting ecryptfs\n"; $mountpoint = mount_ecryptfs($workingDir); - my $ecryptfs_results = benchmark($mountpoint); + my $ecryptfs_results; + if($mountpoint) { + $ecryptfs_results = benchmark($mountpoint); + } cleanup($workingDir); From f8a563bdcd77c116799f60f8ab6a155cafebc759 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Fri, 26 Dec 2014 22:37:47 +0100 Subject: [PATCH 2/3] encfsctl: define a default PATH_MAX Unless it is already defined. Fixes build errors with musl libc. --- encfs/encfsctl.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/encfs/encfsctl.cpp b/encfs/encfsctl.cpp index b3640e1..c59cf79 100644 --- a/encfs/encfsctl.cpp +++ b/encfs/encfsctl.cpp @@ -44,6 +44,10 @@ #include "i18n.h" #include "shared_ptr.h" +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + using namespace rlog; using namespace std; using gnu::autosprintf; From 553f65a014afdcbbce32f26553955f29b3238fc6 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sat, 27 Dec 2014 14:52:32 +0100 Subject: [PATCH 3/3] benchmark.pl: Improve help text, add Makefile target Performing a benchmark on /var/tmp now is as easy as "make benchmark". --- Makefile.am | 4 ++++ tests/benchmark.pl | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Makefile.am b/Makefile.am index 6689589..981ddbd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,3 +22,7 @@ test: .PHONY: test-verbose test-verbose: perl -MTest::Harness -e '$$Test::Harness::verbose=1; runtests @ARGV;' tests/*.t.pl + +.PHONY: benchmark +benchmark: + sudo tests/benchmark.pl /var/tmp diff --git a/tests/benchmark.pl b/tests/benchmark.pl index 26d9624..0e134a4 100755 --- a/tests/benchmark.pl +++ b/tests/benchmark.pl @@ -11,8 +11,8 @@ require("tests/common.pl"); # Download linux-3.0.tar.gz unless it already exists ("-c" flag) sub dl { - our $linuxgz = "/tmp/linux-3.0.tar.gz"; - print "# downloading linux-3.0.tar.gz... "; + our $linuxgz = "/var/tmp/linux-3.0.tar.gz"; + print "# downloading linux-3.0.tar.gz (92MiB)... "; system("wget -nv -c https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.0.tar.gz -O $linuxgz"); print "done\n"; } @@ -138,7 +138,7 @@ sub benchmark { system("echo 3 > /proc/sys/vm/drop_caches"); stopwatch_start("rsync"); - system("rsync -an $dir /tmp"); + system("rsync -an $dir $dir/empty-rsync-target"); stopwatch_stop(\@results); system("echo 3 > /proc/sys/vm/drop_caches"); @@ -188,7 +188,15 @@ sub tabulate { sub main { if ( $#ARGV < 0 ) { - print "Usage: test/benchmark.pl MOUNTPOINT [MOUNTPOINT] [...]\n"; + print "Usage: test/benchmark.pl DIR1 [DIR2] [...]\n"; + print "\n"; + print "Arguments:\n"; + print " DIRn ... Working directory. This is where the encrypted files\n"; + print " are stored. Specifying multiple directories will run\n"; + print " the benchmark in each.\n"; + print "\n"; + print "For details about the testcases see PERFORMANCE.md.\n"; + exit(1); }