summaryrefslogtreecommitdiffstats
path: root/bm/bm_history.pl
diff options
context:
space:
mode:
Diffstat (limited to 'bm/bm_history.pl')
-rw-r--r--bm/bm_history.pl152
1 files changed, 0 insertions, 152 deletions
diff --git a/bm/bm_history.pl b/bm/bm_history.pl
deleted file mode 100644
index 5f2ea4a..0000000
--- a/bm/bm_history.pl
+++ /dev/null
@@ -1,152 +0,0 @@
-#!/usr/bin/perl
-use strict;
-use warnings;
-use File::Spec;
-use File::Path qw(remove_tree);
-use File::Find;
-use Cwd qw(getcwd abs_path);
-
-my ($files, $depth, $total_commits) = @ARGV;
-if (!defined $files || !defined $depth || !defined $total_commits) {
- die "Usage: perl bm_history.pl <file_count> <depth> <total_commits>\n";
-}
-
-my $base_dir = getcwd();
-my $urn_bin = abs_path(File::Spec->catfile("..", "urn"));
-my $seed_bin = abs_path("seed.pl");
-my $bm_repo = "bm_repo";
-
-my $sample_rate = int($total_commits / 5) || 1;
-my %results;
-
-my $rebase_count = 0;
-my %last_base_hashes;
-
-sub get_size {
- my $dir = shift;
- return "0 KB" unless -d $dir;
- my $size = `du -sk $dir 2>/dev/null`;
- $size =~ /^(\d+)/;
- return ($1 || 0) . " KB";
-}
-
-sub count_inodes {
- my $dir = shift;
- return 0 unless -d $dir;
- my $count = `find $dir 2>/dev/null | wc -l`;
- $count =~ s/\s+//g;
- return $count || 0;
-}
-
-sub track_rebases {
- return unless -f ".urn/index";
- open(my $fh, '<', ".urn/index") or return;
- while (<$fh>) {
- chomp;
- my @cols = split(/\t/);
- next unless @cols >= 6;
- my ($b_hash, $path) = ($cols[2], $cols[5]);
- if (exists $last_base_hashes{$path} && $last_base_hashes{$path} ne $b_hash) {
- $rebase_count++;
- }
- $last_base_hashes{$path} = $b_hash;
- }
- close($fh);
-}
-
-sub run_history_benchmark {
- my ($tool_name) = @_;
- print ">>> Starting History Benchmark: $tool_name\n";
-
- remove_tree($bm_repo) if -d $bm_repo;
- system("perl $seed_bin $files $depth > /dev/null 2>&1");
-
- chdir($bm_repo) or die $!;
-
- my $init_cmd = ($tool_name eq "URN") ? "perl $urn_bin init" : "git init";
- my $add_cmd = ($tool_name eq "URN") ? "perl $urn_bin add ." : "git add .";
-
- system("$init_cmd > /dev/null 2>&1");
- system("$add_cmd > /dev/null 2>&1");
- system(($tool_name eq "URN" ? "perl $urn_bin" : "git") . " commit -m 'initial' > /dev/null 2>&1");
-
- track_rebases() if $tool_name eq "URN";
-
- my @file_list;
- find(sub { push @file_list, $File::Find::name if -f $_ && $File::Find::name !~ /\.(git|urn)/ }, ".");
-
- for my $i (1 .. $total_commits) {
- my $to_modify = int($files * 0.02) || 1;
- for (1 .. $to_modify) {
- my $target = $file_list[rand @file_list];
- if (open(my $fh, '>>', $target)) {
- print $fh "Churn $i\n";
- close($fh);
- }
- }
-
- my $cmd = ($tool_name eq "URN")
- ? "perl $urn_bin add . && perl $urn_bin commit -m 'c$i'"
- : "git add . && git commit -m 'c$i'";
-
- if ($i % $sample_rate == 0 || $i == $total_commits) {
- # Capture hardware metrics via /usr/bin/time -l
- my $stats = `/usr/bin/time -l sh -c "$cmd" 2>&1 > /dev/null`;
-
- my ($real, $rss, $maj, $min) = (0, 0, 0, 0);
- if ($stats =~ /(\d+\.\d+)\s+real/) { $real = $1; }
- if ($stats =~ /(\d+)\s+maximum resident set size/) { $rss = sprintf("%.2f MB", $1 / 1024 / 1024); }
- if ($stats =~ /(\d+)\s+page reclaims/) { $min = $1; }
- if ($stats =~ /(\d+)\s+page faults/) { $maj = $1; }
-
- if ($tool_name eq "URN") { track_rebases(); }
-
- my $meta = ($tool_name eq "URN") ? ".urn" : ".git";
- $results{$i}{$tool_name} = {
- real => $real . "s",
- rss => $rss,
- faults => "Maj:$maj / Min:$min",
- inodes => count_inodes($meta),
- size => get_size($meta),
- };
- print " [Commit $i] $tool_name sampled.\n";
- } else {
- system("$cmd > /dev/null 2>&1");
- if ($tool_name eq "URN") { track_rebases(); }
- }
- }
- chdir($base_dir);
- remove_tree($bm_repo);
-}
-
-$rebase_count = 0;
-%last_base_hashes = ();
-run_history_benchmark("URN");
-run_history_benchmark("GIT");
-
-my $out_file = "BM_HISTORY_${files}_${total_commits}.txt";
-open(my $res, '>', $out_file) or die $!;
-print $res "=============================================================\n";
-print $res " HISTORY BENCHMARK: $files files ($total_commits commits)\n";
-print $res "=============================================================\n\n";
-
-foreach my $i (sort { $a <=> $b } keys %results) {
- my $u = $results{$i}{"URN"};
- my $g = $results{$i}{"GIT"};
- print $res "SNAPSHOT: Commit #$i\n";
- print $res "-------------------------------------------------------------\n";
- printf $res "%-15s | %-20s | %-20s\n", "METRIC", "URN", "GIT";
- print $res "----------------+----------------------+---------------------\n";
- printf $res "%-15s | %20s | %20s\n", "Time", $u->{real}, $g->{real};
- printf $res "%-15s | %20s | %20s\n", "Max RSS", $u->{rss}, $g->{rss};
- printf $res "%-15s | %20s | %20s\n", "Page faults", $u->{faults}, $g->{faults};
- printf $res "%-15s | %20s | %20s\n", "Inodes", $u->{inodes}, $g->{inodes};
- printf $res "%-15s | %20s | %20s\n", "Repo size", $u->{size}, $g->{size};
- print $res "-------------------------------------------------------------\n\n";
-}
-print $res "TOTAL URN REBASES: $rebase_count\n";
-close($res);
-
-my $pager = $ENV{PAGER} || 'less';
-exec $pager, $out_file;
-