Subject: Shared lib reference counts
To: None <current-users@sun-lamp.cs.berkeley.edu>
From: Martin Husemann <martin@euterpe.owl.de>
List: current-users
Date: 04/25/1994 06:49:17
I have written a little perl script to find out, which of the shared
libs I can remove and what binaries still need to be rebuild in userland.
Thought you might find it helpfull too...
Martin
#!/usr/bin/perl
# hey emacs, this is a -*-perl-*- script!
# A little script to build a reference listing for dynamic libraries.
# This should help you to get rid of unused ones and find the binaries
# you need to update before removing old lib revisions.
# Martin Husemann, martin@euterpe.owl.de, 25-Apr-1994
# Synopsis:
# libref [-a]
#
# Description:
# Lists usage count for all known shared libraries
#
# Options:
# -a gives a complete reference table
$doRef = $ARGV[0] eq "-a"; # yes, it may use getopt...
# First ask ldconfig for a list of all shared libs and initialize the
# reference and statistics table
open(LIBS, "ldconfig -r |") || die("could not run ldconfig: $!\n");
while(<LIBS>) {
chop;
next if (/ld.so.hints:$/);
s/^.*=> (\S+)\s.*$/\1/o;
$reference{$_} = "";
$count{$_} = 0;
}
close(LIBS);
# now lookup every dynamically linked executable on the whole disk
open(FILES, "find / -type f -print |") || die("could not run find: $!\n");
while (<FILES>) {
chop;
if ( -x ) {
$whatis=`file $_`;
if ($whatis =~ /dynamically linked/) {
$prog="$_";
open(LIBS, "ldd $prog |") || die("could not run ldd: $!\n");
@libs = <LIBS>;
close(LIBS);
shift(@libs);
foreach (@libs) {
chop;
s/^.*=> (\S+)\s.*$/\1/o;
$count{$_}++;
$reference{$_} .= " $prog" if ($doRef);
}
}
}
}
close(FILES);
# sort statistics
sub ByUsage {
$count{$a} <=> $count{$b};
}
@sorted = sort ByUsage keys(%count);
# and finaly report statistics...
print "Shared library usage counts\n\n" if ($doRef);
foreach (@sorted) {
printf "%8d %s\n", $count{$_}, $_;
}
# and the cross reference
if ($doRef) {
print "\n\nShared library cross reference\n\n";
foreach $lib (sort(keys(%reference))) {
print "$lib:$reference{$lib}\n";
}
}
exit 0;
------------------------------------------------------------------------------