Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mono-stats « status - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 64a2947df09a37939fb8809458298008112ed8a5 (plain)
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
#!/usr/bin/perl -w

use strict;
use XML::Parser;
#use Data::Dumper;

# command line arguments: shell globs for the files containing the info
# for the ms assemblyes and mono's
my $msglob = shift || 'ms*.xml';
my $monoglob = shift || 'mono*.xml';
# maintainers file
my $mfile = 'maintainers.xml';
my $curfile;

# positions in array refs
use constant MNAME => 0;
use constant MASSEMBLY => 1;
use constant MCLASS => 2;

use constant MAINTAINER => 0;
use constant PERCENT => 1;
use constant HASH => 2;
# we store all the data in some global hash tables
# $email => [$name, \%assembly, \%class]
my %maintainer;

# $name => [$maintainer, $percent, \%classes];
my %assembly;

# $name => [$maintainer, $percent, \%methods]
my %class;

# my parsing state machine
my @status;
# current maintainer, class and assembly pointers
my ($curm, $curc, $cura);
my $mono = 0;
my $namespace = '';
my %status_action = (
	MAINTAINERS => sub {
		my ($elem, %attrs) = @_;
		malformed ($mfile, $elem, 'maintainers', \@status);
		push @status, 'DUDE';
	},
	DUDE => sub {
		my ($elem, %attrs) = @_;
		malformed ($mfile, $elem, 'person', \@status);
		foreach(qw(email name)) {die "$_ not included in person\n" unless defined $attrs{$_}}
		$curm = $maintainer{$attrs{email}} = [$attrs{name}, {}, {}];
		push @status, 'DUDE_CONTENT';
	},
	DUDE_CONTENT => sub {
		my ($elem, %attrs) = @_;
		malformed ($mfile, $elem, 'class|assembly', \@status);
		if ($elem eq 'class') {
			$curm->[MCLASS]->{$attrs{name}} = '';
		} elsif ($elem eq 'assembly') {
			$curm->[MASSEMBLY]->{$attrs{name}} = '';
		}
		push @status, 'DUDE_CONTENT';
	},
	ASSEMBLY => sub {
		my ($elem, %attrs) = @_;
		malformed ($curfile, $elem, 'assembly', \@status);
		$namespace = '';
		$cura = $assembly{$attrs{name}} = ['', 0, {}];
		push @status, 'NAMESPACE';
	},
	NAMESPACE => sub {
		my ($elem, %attrs) = @_;
		malformed ($curfile, $elem, 'namespace', \@status);
		$namespace = $attrs{name};
		push @status, 'CLASS';
	},
	CLASS => sub {
		my ($elem, %attrs) = @_;
		malformed ($curfile, $elem, 'class|valueType|interface', \@status);
		if ($elem eq 'class') {
			my $name = $namespace ? $namespace.".".$attrs{name} : $attrs{name};
			if ($mono) {
				warn "mono implements non exisistent class $name\n" 
					if (!exists $class{$name});
				$curc = $class{$name};
			} else {
				$curc = $class{$name} = ['', 0, {}];
			}
			$cura->[HASH]->{$name} = $mono;
			push @status, 'METHOD';
		} else {
			push @status, 'METHOD';
		}
	},
	METHOD => sub {
		my ($elem, %attrs) = @_;
		malformed ($curfile, $elem, 'method|field|valueType', \@status);
		if ($elem eq 'method') {
			my $name = $attrs{signature};
			if ($mono) {
				warn "mono implements non exisistent method $name\n" 
					if (!exists $curc->[HASH]->{$name});
			}
			$curc->[HASH]->{$name} = $mono;
			push @status, 'METHOD';
		} else {
			push @status, 'METHOD';
		}
	},
);


my $parser = new XML::Parser (Handlers => {Start => \&handle_tag, End => \&end_tag});

# parse the maintainers info
if ($mfile) {
	@status = 'MAINTAINERS';
	$parser->parsefile($mfile);
	#print Dumper(\%maintainer);
}

foreach (glob($msglob)) {
	$curfile = $_;
	@status = 'ASSEMBLY';
	$mono = 0;
	$parser->parsefile($_);
}

foreach (glob($monoglob)) {
	$curfile = $_;
	@status = 'ASSEMBLY';
	$mono = 1;
	$parser->parsefile($_);
}

create_stats();
create_html();
#print Dumper(\%assembly);
#print Dumper(\%class);
exit(0);

sub malformed {
	my ($file, $elem, $match, $data) = @_;
	unless ($elem =~ /^$match$/) {
		$data = Dumper($data) if defined $data;
		die "file $file malformed ($elem instead of $match) $data\n"
	}
}

sub handle_tag {
	my $parser = shift @_;
	my $status = $status[-1];
	die "status $status unknown" unless exists $status_action{$status};
	$status_action{$status}->(@_);
}

sub end_tag {
	my $last = pop @status;
	# print STDERR "done with $last\n";
}

sub assign_maintainer {
	my ($m, $from, $to, $type) = @_;
	foreach (keys %$from) {
		if (!exists $to->{$_}) {
			warn "$m maintains unknown $type $_\n";
			# fixup to avoid warnings
			$to->{$_}->[MAINTAINER] = $m;
			$to->{$_}->[PERCENT] = 0;
			$to->{$_}->[HASH] = {};
		} else {
			warn "$to->{$_}->[MAINTAINER] already maintains $_ (now $m)\n" if $to->{$_}->[MAINTAINER];
			$to->{$_}->[MAINTAINER] = $m;
		}
	}
}

sub completeness {
	my $hash = shift @_;
	my $total = keys %$hash;
	my $done = 0;
	map {$done += $_} values %$hash;
	return 0 unless $total;
	return int($done*100/$total);
}

sub create_stats {
	# set maintainer field in assembly and class hashes
	foreach my $m (sort keys %maintainer) {
		assign_maintainer ($m, $maintainer{$m}->[MASSEMBLY], \%assembly, 'assembly');
		assign_maintainer ($m, $maintainer{$m}->[MCLASS], \%class, 'class');
	}
	# assign completeness percent
	foreach my $ass (values %assembly) {
		$ass->[PERCENT] = completeness ($ass->[HASH]);
	}
	foreach my $class (values %class) {
		$class->[PERCENT] = completeness ($class->[HASH]);
	}
}

sub html_header {
	my ($title) = @_;
return <<"EOF";
<html><head><title>$title</title></head><body bgcolor="#ffffff">
<h1 ALIGN=center>$title</H1>
EOF

}

sub unimplemented ($) {
	my ($c) = @_;
	my $id = $c;
	$id =~ tr/./-/;
	return "<A HREF='per-unimplemented.html#$id'>$c</A>";
}

sub create_html {

	open(F, ">per-assembly.html") || die "Cannot open file: $!";
	print F html_header("Mono - per-assembly stats");
	print F "<TABLE BORDER=1><TR><TH>Assembly<TH>Maintainer<TH>Completion\n";
	foreach my $ass (sort keys %assembly) {
		print F "\t<TR><TD>", join('<TD>', $ass, $assembly{$ass}->[MAINTAINER], $assembly{$ass}->[PERCENT]), "\n";
	}
	print F "</TABLE>\n";
	print F "</body></html>\n";
	close(F);

	# per maintainer info
	open(F, ">per-maintainer.html") || die "Cannot open file: $!";
	print F html_header("Mono - per-maintainer stats");
	print F "<TABLE BORDER=1><TR><TH>Maintainer<TH>Class<TH>Completion\n";
	foreach my $m (sort keys %maintainer) {
		my @classes = sort keys %{$maintainer{$m}->[MCLASS]};
		my $count = @classes;
		foreach my $c (@classes) {
			my $start = $count?"\t<TR><TD ROWSPAN=$count>$m<TD>":"\t<TR><TD>";
			$count = 0;
			print F $start, join('<TD>', $c, $class{$c}->[PERCENT]), "\n";
		}
	}
	my @unmantained = sort grep {!$class{$_}->[MAINTAINER]} keys %class;
	my $count = @unmantained;
	foreach my $c (@unmantained) {
		my $start = $count?"\t<TR><TD ROWSPAN=$count>Unmantained<TD>":"\t<TR><TD>";
		$count = 0;
		print F $start, join('<TD>', $c, $class{$c}->[PERCENT]), "\n";
	}
	print F "</TABLE>\n";
	print F "</body></html>\n";
	close(F);

	# per-completion info
	open(F, ">per-completion.html") || die "Cannot open file: $!";
	print F html_header("Mono - per-completion stats");
	print F "<TABLE BORDER=1><TR><TH>Completion<TH>Class<TH>Maintainer\n";
	foreach my $c (sort {$class{$b}->[PERCENT] <=> $class{$a}->[PERCENT]} keys %class) {
		print F "\t<TR><TD>", join('<TD>', $class{$c}->[PERCENT], unimplemented($c), $class{$c}->[MAINTAINER]), "\n";
	}
	print F "</TABLE>\n";
	print F "</body></html>\n";
	close(F);

	# unimplemented methods
	# FIXME: this can create a very big file, split on assembly name
	# and fix also the unimplemented() sub
	open(F, ">per-unimplemented.html") || die "Cannot open file: $!";
	print F html_header("Mono - unimplemented methods stats");
	print F "<TABLE BORDER=1><TR><TH>Class<TH>Method\n";
	foreach my $c (sort grep {$class{$_}->[PERCENT] != 100} keys %class) {
		my @methods = sort grep {!$class{$c}->[HASH]->{$_}} keys %{$class{$c}->[HASH]};
		my $count = @methods;
		my $aname = '';
		if ($count) {
			my $id = $c;
			$id =~ tr/./-/;
			$aname = "<A NAME='$id'></A>";
		}
		foreach my $m (@methods) {
			my $start = $count?"\t<TR><TD ROWSPAN=$count>$aname$c<TD>":"\t<TR><TD>";
			$count = 0;
			print F $start, join('<TD>', $m), "\n";
		}
	}
	print F "</TABLE>\n";
	print F "</body></html>\n";
	close(F);

}