/
genstat.pl
executable file
·305 lines (275 loc) · 8.2 KB
/
genstat.pl
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/usr/bin/perl -w
#
# Stupid 'how much work is going on' type calculations for the Linux kernel
# source tree.
#
# Copyright (C) 2007-2008 Greg Kroah-Hartman <greg@kroah.com>
# Copyright (C) 2007-2008 Novell Inc.
#
# Released under the GPL version 2 only.
#
# How to use:
# - go into the git tree for the kernel and run the script, passing the two
# git ids that you wish to calculate between as command line arguments.
# - be amazed at the huge rate of change that happens...
#
# Note, some file names might show up as "unknown" because of some wierd git
# thing, if so, please let me know.
#
# How rate of change is calculated:
# - we look at every changeset between the requested tags
# - for every changeset, we tell git to not show us renames or file moves
# - we look at the diffstat for the individual files within the changeset and
# calculate things as:
# file_lines_added = diffstat lines added
# file_lines_delete = diffstat lines added
# if (file_lines_added = file_lines_deleted)
# overall_lines_modified += file_lines_added
# if (file_lines_added > file_lines_deleted)
# overall_lines_added += file_lines_added - file_lines_deleted
# overall_lines_modified += file_lines_deleted
# if (file_lines_added < file_lines_deleted)
# overall_lines_deleted += file_lines_deleted - file_lines_added
# overall_lines_modified += file_lines_added
# Yeah, it's not the cleanest formula, but it is the best that I can come
# up with after trying a lot of different ones. If anyone knows a better
# one, please let me know.
#
#
#
my $start = "";
my $end = "";
my @core_files = ("init", "block", "ipc", "kernel", "lib", "mm", "virt");
my @fs_files = ("fs");
my @driver_files = ("crypto", "drivers", "sound", "security");
my @net_files = ("net");
my @arch_files = ("arch");
my @misc_files = ("Documentation", "scripts", "samples", "usr", "MAINTAINERS", "CREDITS", "README", ".gitignore", "Kbuild", "Makefile", "REPORTING-BUGS", ".mailmap", "COPYING", "tools", "Kconfig");
my @firmware_files = ("firmware");
my $overall_add = 0;
my $overall_del = 0;
my $overall_mod = 0;
my $core_add = 0;
my $core_del = 0;
my $core_mod = 0;
my $fs_add = 0;
my $fs_del = 0;
my $fs_mod = 0;
my $driver_add = 0;
my $driver_del = 0;
my $driver_mod = 0;
my $net_add = 0;
my $net_del = 0;
my $net_mod = 0;
my $arch_add = 0;
my $arch_del = 0;
my $arch_mod = 0;
my $misc_add = 0;
my $misc_del = 0;
my $misc_mod = 0;
my $firmware_add = 0;
my $firmware_del = 0;
my $firmware_mod = 0;
sub unknown($$$$$)
{
my ($filename, $commit, $add, $del, $mod) = @_;
print "unknown filename='$filename' commit=$commit add=$add del=$del mod=$mod\n";
}
sub include_category($$$$$);
sub include_category($$$$$)
{
my ($filename, $commit, $add, $del, $mod) = @_;
if (($filename eq "linux") ||
($filename eq "keys") ||
($filename eq "trace") ||
($filename eq "Kbuild")) {
$core_add += $add;
$core_del += $del;
$core_mod += $mod;
} elsif (($filename eq "acpi") ||
($filename eq "crypto") ||
($filename eq "drm") ||
($filename eq "media") ||
($filename eq "mtd") ||
($filename eq "pcmcia") ||
($filename eq "target") ||
($filename eq "rdma") ||
($filename eq "rxrpc") ||
($filename eq "scsi") ||
($filename eq "sound") ||
($filename eq "video")) {
$driver_add += $add;
$driver_del += $del;
$driver_mod += $mod;
} elsif (($filename eq "net")) {
$net_add += $add;
$net_del += $del;
$net_mod += $mod;
} elsif (($filename eq "xen") ||
($filename eq "math-emu")) {
$arch_add += $add;
$arch_del += $del;
$arch_mod += $mod;
} else {
# see if this is arch
my @a = split(/-/,$filename);
if ($a[0] eq "asm") {
$arch_add += $add;
$arch_del += $del;
$arch_mod += $mod;
} else {
# see if the first char is the '{'
if (substr($filename, 0, 1) eq "\{") {
# it is, so strip it off (hack, hack, hack...)
my $l = length($filename);
$filename = substr($filename, 1, $l-1);
include_category($filename, $commit, $add, $del, $mod);
} else {
unknown($filename, $commit, $add, $del, $mod);
}
}
}
}
sub filename_category($$$$$)
{
my ($filename, $commit, $add, $del, $mod) = @_;
my @f = split(/\//,$filename);
my $basename = $f[0];
if ($basename eq "include") {
include_category($f[1], $commit, $add, $del, $mod);
} elsif (grep { /$basename/ } @core_files) {
$core_add += $add;
$core_del += $del;
$core_mod += $mod;
} elsif (grep { /$basename/ } @fs_files) {
$fs_add += $add;
$fs_del += $del;
$fs_mod += $mod;
} elsif (grep { /$basename/ } @driver_files) {
$driver_add += $add;
$driver_del += $del;
$driver_mod += $mod;
} elsif (grep { /$basename/ } @net_files) {
$net_add += $add;
$net_del += $del;
$net_mod += $mod;
} elsif (grep { /$basename/ } @arch_files) {
$arch_add += $add;
$arch_del += $del;
$arch_mod += $mod;
} elsif (grep { /$basename/ } @misc_files) {
$misc_add += $add;
$misc_del += $del;
$misc_mod += $mod;
} elsif (grep { /$basename/ } @firmware_files) {
$firmware_add += $add;
$firmware_del += $del;
$firmware_mod += $mod;
} else {
unknown($filename, $commit, $add, $del, $mod);
}
}
sub print_data($$$$)
{
my ($basename, $add, $del, $mod) = @_;
my $percent_add = $overall_add ? $add/$overall_add*100 : 0;
my $percent_del = $overall_del ? $del/$overall_del*100 : 0;
my $percent_mod = $overall_mod ? $mod/$overall_mod*100 : 0;
print "\n$basename:\n";
printf "\tadded = %8d\t%6.2f", $add, $percent_add;
print "%\n";
printf "\tdeleted = %8d\t%6.2f", $del, $percent_del;
print "%\n";
printf "\tmodified = %8d\t%6.2f", $mod, $percent_mod;
print "%\n";
}
sub error_out
{
print "ERROR, must provide 2 git ids to calculate between\n";
die;
}
$start = shift;
$end = shift;
if (($start eq "") || ($end eq "")) {
error_out;
}
print "Figuring stats for $start to $end\n";
open GIT, "git rev-list --no-merges $start..$end | " || die "cant run git";
my $commit;
my $file_add;
my $file_del;
my $filename;
my $num_commits = 0;
while (<GIT>) {
$num_commits++;
chomp;
my @arr = split;
$commit = $arr[0];
# print "commit = $commit\n";
system("git show --pretty=oneline --numstat $commit > genstat.$commit");
open DIFF, "git show --pretty=oneline --numstat $commit |";
my $temp = <DIFF>;
while (<DIFF>) {
my $mod = 0;
my $del = 0;
my $add = 0;
chomp;
my @file_arr = split;
$file_add = $file_arr[0];
$file_del = $file_arr[1];
$filename = $file_arr[2];
# if this is a binary file, there will not be any add or del
# numbers, only "-" in these fields
if (($file_add eq "-") || ($file_del eq "-")) {
next;
}
# if this is a renamed file, we will have a "{" in it
if ($filename =~ m/\{/) {
# if there is a clean move, we don't care about it.
# This makes things easier for some of the bigger i386 to x86
# merged files
if (($file_add == 0) && ($file_del == 0)) {
# print "$filename no add or del, moving on...\n";
next;
}
# see if the first char is the '{'
if (substr($filename, 0, 1) eq "\{") {
# it is, so strip it off (hack, hack, hack...)
my $l = length($filename);
$filename = substr($filename, 1, $l-1);
}
}
# compute the number of modified lines for this file
if ($file_add == $file_del) {
# print "equal\n";
$mod = $file_add;
} elsif ($file_add < $file_del) {
# print "add less than del\n";
$mod = $file_add;
$del = $file_del - $file_add;
} else {
# print "add greater than del\n";
$mod = $file_del;
$add = $file_add - $file_del;
}
$overall_add += $add;
$overall_del += $del;
$overall_mod += $mod;
# print ("mod = $mod add = $add del = $del\n");
# print "$filename\n";
filename_category($filename, $commit, $add, $del, $mod);
}
close DIFF;
}
print "number of commits = $num_commits\n";
print "added = $overall_add\n";
print "deleted = $overall_del\n";
print "modified = $overall_mod\n";
print_data("core", $core_add, $core_del, $core_mod);
print_data("drivers", $driver_add, $driver_del, $driver_mod);
print_data("arch", $arch_add, $arch_del, $arch_mod);
print_data("net", $net_add, $net_del, $net_mod);
print_data("filesystems", $fs_add, $fs_del, $fs_mod);
print_data("misc", $misc_add, $misc_del, $misc_mod);
print_data("firmware", $firmware_add, $firmware_del, $firmware_mod);
exit;