| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use File::Find; |
| 4 | use IO::File; |
| 5 | |
| 6 | use strict; |
| 7 | use vars qw($Pat @Locks $DupOnly); |
| 8 | |
| 9 | # This pattern matches the function names we are looking for |
| 10 | $Pat = qr/(?:NB)?Obtain(?:Write|Shared|)Lock|UpgradeSToWLock/; |
| 11 | |
| 12 | if (@ARGV[0] eq '-d') { |
| 13 | $DupOnly = 1; |
| 14 | shift @ARGV; |
| 15 | } |
| 16 | |
| 17 | find( |
| 18 | sub { |
| 19 | return unless -f $_; |
| 20 | |
| 21 | my $path = $File::Find::name; |
| 22 | my $F = new IO::File($_, O_RDONLY) or die "$path: $!\n"; |
| 23 | while (<$F>) { |
| 24 | next unless /\b(?:$Pat)\(.*,\s*(\d+)\)/o; |
| 25 | $Locks[$1] ||= []; |
| 26 | push(@{$Locks[$1]}, sprintf("%s:%d", $path, $.)); |
| 27 | } |
| 28 | $F->close; |
| 29 | }, @ARGV); |
| 30 | |
| 31 | foreach my $id (0 .. @Locks) { |
| 32 | next unless defined $Locks[$id]; |
| 33 | next if $DupOnly && @{$Locks[$id]} < 2; |
| 34 | printf("%5d %s", $id, join(" ", map("$_\n", @{$Locks[$id]}))) |
| 35 | } |