-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.pl
More file actions
117 lines (105 loc) · 3.22 KB
/
plot.pl
File metadata and controls
117 lines (105 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/perl -w
use strict;
use warnings;
my $num_commits = 512;
$#ARGV >= 0 or die "Usage: plot.pl <gcc|llvm-project> [<num-commits, default:$num_commits>]";
my $compiler = $ARGV[0];
if ($#ARGV >= 1) {
$num_commits = int($ARGV[1]);
}
my @commits = reverse(split('\n', `git -C $compiler log --pretty=format:"%H"`));
my $cnum = scalar @commits;
my $skip = $cnum / $num_commits;
open(my $outdata, ">out.data.tmp");
for (my $i = 0; $i < $cnum - 1; $i += $skip) {
process_commit($compiler, $commits[$i]);
}
process_commit($compiler, $commits[$cnum - 1]);
close($outdata);
system("mv out.data.tmp out.$compiler.csv");
sub process_commit {
my $compiler = shift;
my $commit = shift;
print "Checking out $commit\n";
checkout($compiler, $commit);
my $date = get_commit_date($compiler);
my $tot = count_total($compiler);
#print "Number of lines in $compiler: $tot\n";
print $outdata "\t$compiler\t$date\t$tot\n";
};
sub checkout {
my $compiler = shift;
my $commit = shift;
system("git -C $compiler checkout -f $commit");
};
sub count_total {
my $compiler = shift;
if ($compiler eq "llvm-project") {
system("mv llvm-project/llvm/test llvm-project/llvm/docs llvm-project/llvm/examples llvm-project/llvm/unittests llvm-project/llvm/utils llvm-project/llvm/bindings .");
system("mv llvm-project/.git llvm-project.git");
system("find llvm-project/llvm -type f | xargs wc -l | cat > wc.out");
system("mv test docs examples unittests utils bindings llvm-project/llvm");
system("mv llvm-project.git llvm-project/.git");
my $tot = count_total_in_wc_out("wc.out");
system("rm -f wc.out");
return $tot;
} elsif ($compiler eq "gcc") {
system("mv gcc/.git gcc.git");
system("find gcc -type f | xargs wc -l | cat > wc.out");
system("mv gcc.git gcc/.git");
my $tot = count_total_in_wc_out("wc.out");
system("rm -f wc.out");
return $tot;
} else {
die "unrecognized compiler: $compiler\n";
}
};
sub count_total_in_wc_out {
my $wc_out = shift;
open(my $in, "<$wc_out");
my $ret = 0;
while (my $line = <$in>) {
if ($line =~ / (\d*) total/) {
my $t = $1;
$ret += $t;
}
}
close($in);
return $ret;
};
sub get_commit_date {
my $gitrep = shift;
my $date = `cd $gitrep && git show -s --format=%ci && cd ..`;
chomp($date);
return $date;
};
sub identify_need_to_commit {
my $compiler = shift;
my $commitcount_filename = shift;
my $every_nth_commit = shift;
if (not (-e $commitcount_filename)) {
open(my $outfp, ">$commitcount_filename");
print $outfp "LAST COMMITTED: 0\n";
print $outfp "LAST SEEN: 0\n";
close($outfp);
return 1;
}
open(my $infp, "<$commitcount_filename");
my $line1 = <$infp>;
my $line2 = <$infp>;
close($infp);
$line1 =~ /LAST COMMITTED: (\d*)$/ or die;
my $last_committed = int($1);
$line2 =~ /LAST SEEN: (\d*)$/ or die;
my $last_seen = int($1);
my $cur_seen = $last_seen + 1;
my $cur_committed = $last_committed;
if ($cur_seen >= $last_committed + $every_nth_commit) {
$cur_committed = $cur_seen;
}
open(my $outfp, ">$commitcount_filename");
print $outfp "LAST COMMITTED: $cur_committed\n";
print $outfp "LAST SEEN: $cur_seen\n";
close($outfp);
return $cur_committed > $last_committed;
};