#!/usr/bin/perl -w use strict; my (%lines_by_pkg, %synch_lines_by_pkg); while () { chomp; my $file = $_; open JAVA, $file or die "$file: $!"; local($/); undef $/; my $text = ; close JAVA; $text =~ s!/\*([^*]|\*[^/])*\*/!!g; $text =~ s!//[^\n]*\n!\n!g; $text =~ s!\n([ \t]*\n)+!\n!g; $text =~ s!^\s+|\s+$!!g; #print "---%<--- $file\n$text\n---%<---\n"; print "$file: "; if ($text =~ m!^\s*package ([a-zA-Z0-9_.]+);!) { my $pkg = $1; #print "(package: $pkg)\n"; my @lines = split '\n', $text; my $linecount = 0; my $synch = 0; my @synchlines; for my $line (@lines) { if ($line =~ /\bpackage|import\b/) { next; } $linecount++; # skipping: notify (ErrorManager) if ($line =~ /\b(Mutex|RequestProcessor|Task|Thread|Timer)\b|\b(cancel|enterReadAccess|enterWriteAccess|exitReadAccess|exitWriteAccess|interrupt|interrupted|invokeAndWait|invokeLater|isInterrupted|join|notifyAll|post|postReadRequest|postRequest|postWriteRequest|prepare|readAccess|runAtomic|runAtomicAction|runAtomicAsUser|schedule|sleep|start|stop|synchronized|taskFinished|wait|waitFinished|writeAccess|yield) ?\(/) { $synch++; push @synchlines, $line; } } print "$synch/$linecount\n"; for my $line (@synchlines) {print "$line\n"} $lines_by_pkg{$pkg} += $linecount; $synch_lines_by_pkg{$pkg} += $synch; } else { print "(no package)\n"; } } my %portion_by_pkg; print "\n\nSummary:\n\n"; for my $pkg (sort keys %lines_by_pkg) { print "package $pkg: $synch_lines_by_pkg{$pkg}/$lines_by_pkg{$pkg}\n"; $portion_by_pkg{$pkg} = int($synch_lines_by_pkg{$pkg} / $lines_by_pkg{$pkg} * 10000) / 100; } print "\n\nUsers of threading:\n\n"; for my $pkg (sort {$synch_lines_by_pkg{$b} <=> $synch_lines_by_pkg{$a}} keys %lines_by_pkg) { print "package $pkg: $synch_lines_by_pkg{$pkg}\n"; } print "\n\nProportional users of threading:\n\n"; for my $pkg (sort {$portion_by_pkg{$b} <=> $portion_by_pkg{$a}} keys %lines_by_pkg) { print "package $pkg: $portion_by_pkg{$pkg}%\n"; }