CVS: brutus/elaine find.pl,1.2,1.3

elaine at lunar-linux.org elaine at lunar-linux.org
Fri Aug 22 16:20:13 GMT 2003


Update of /var/cvs/lunar/brutus/elaine
In directory dbguin.lunar-linux.org:/tmp/cvs-serv23990

Modified Files:
	find.pl 
Log Message:
Cleanups: finished removing extraneous loops, unnecessary db calls; 
Moved init code to top.
Only grab Tie::DBI and related libs if -s switch is given
Changed List array into hash to record found depth, keeping only
deepest. For now use "|sort +1 -rn | cut -f1 -d' '" 


Index: find.pl
===================================================================
RCS file: /var/cvs/lunar/brutus/elaine/find.pl,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- find.pl	21 Aug 2003 20:53:33 -0000	1.2
+++ find.pl	22 Aug 2003 16:20:11 -0000	1.3
@@ -2,19 +2,13 @@
 
 #######################################################################################
 # 
-#  v0.2
+#  v0.3
 # Very crude required-dependency finder in perl 
 # Works with Berkely DB file created by 'makedeps.pl' and with mysql or other RDBMS
 # 
 # 
 # Caveats:
-# Full recursive search, no pruning and returns (many) duplicate deps.
-# I think I want to record the deepest-found requirement and order the
-# build deepest-found modules first
 # 
-# Needs some re-write, originally I intended to handle varrying numbers of
-# input modules, and gave that up as too complex, however the structure
-# is still there and needs to be removed.
 # 
 # Needs to be turned into a method, where the class handles dependency
 # data in general and     depend->find is just one metod
@@ -26,63 +20,43 @@
 # -b Berkeley DB
 # -s Sql backend
 # 
-# Todo: optimize-out duplicates while remembering the deepest-found instance
-#       Add optional-depends handling, probably managed in a separate bdb file
-# 
-#       Tie::DBI interface is not zero-code change inside the subroutine, but
-#       can probably be made to be. 
+# Done: optimize-out duplicates while remembering the deepest-found instance
+#       Cleaned up cruft, reordered code, gained an extra 30% speed by removing
+#       unneeded duplicate database call.
 #
-# Notes: Tie::DBI takes a considerable performance hit, e.g. working out depends
-# for Gnome2 on mysql backend takes 8 seconds elapsed vs 0.5 seconds w/ Berkeley
+# Todo: Tie::DBI interface is not zero-code change inside the subroutine, but
+#       can probably be made to be. 
+# 
+#       Add optional depends
 # 
 # 
+# Notes: Tie::DBI takes a considerable performance hit, e.g. working out depends
+# for Gnome2 on mysql backend takes 6 seconds elapsed vs 0.5 seconds w/ Berkeley
+# (amd k7/550) -- which still runs ca. 2x faster than bash : find_depends() on 
+# comparable hardware. Perl will use about 60% of the CPU whild mysql uses 40%
+# on a uni-processor system. There is a slight extra gain on SMP, however latency
+# in the mysql communication protocol limits the total speed.
+# 
 #######################################################################################
 
 
 #use strict;
 use DB_File;
-use DBI;
-use DBD::mysql;
-use Tie::DBI;
 use Getopt::Std;
 
+our($opt_b, $opt_s);
+getopts('bs');
 
-my $level=0;
-my @list;
-sub find {
-
-    $main'level++;
-    my  ($get) = @_;
-    print "Dbg: enter find $get depth= $main'level\n";
-    my $infind; 
-    my $item; 
-    my $found;
-    my $try;
-    
 
-    for $infind ($get) {
-        if ( ($opt_b && $main'database{$infind} || $opt_s && $main'database{$infind}->{value}) ne "") {
-            for $try ($get) {
-                for $item (split " ",  ($opt_s && $main'database{$try}->{value} || $opt_b && $main'database{$try})  ) {
-                    unshift (@main'list, $item);
-                    find ($item);
-                }
-            }
+my $DB_USER='db_user';
+my $DB_PASS='nil';
 
-        $main'level--;
-        return  ($opt_b && $main'database{$try} || $opt_s && $main'database{$found}->{value});
-        }
-        else{
-            $main'level--;
-            return;
-        }          
-    }
+if ($opt_s) {
+    use DBI;
+    use DBD::mysql;
+    use Tie::DBI;
 }
 
-
-our($opt_b, $opt_s);
-getopts('bs');
-
 my %data;
 
 if ( ! ($opt_b || $opt_s) ) {
@@ -93,8 +67,8 @@
     my $db = tie %data,Tie::DBI,{db       => 'mysql:testdb',
                                  table    => 'depends',
                                  key      => 'id',
-                                 user     => 'luser',
-                                 password => '',
+                                 user     => "$DB_USER",
+                                 password => "$DB_PASS",
                                  CLOBBER  => 0};
 }
 
@@ -105,16 +79,48 @@
     open DATAFILE, "+<&=$fd";
 }
 
+%main'database = %data;
+my $tofind=shift;
 
+my $level=0;
+my %list;
+sub find {
 
+    $main'level++;
+    my  ($get) = @_;
+    my $found;
+    my $item;
 
-%main'database = %data;
-my $tofind=shift;
+    if ( ($opt_b && ( $found = $main'database{$get} ) || 
+          $opt_s && ( $found = $main'database{$get}->{value})   )   ne "") {
+
+        for $item (split " ", $found) {
+
+            if ($main'list{$item} <= $main'level) {
+                $main'list{$item} = $main'level;
+            }
+
+            find ($item);
+    }
+
+    $main'level--;
+    return; 
+            
+    }
+    else{
+        $main'level--;
+        return;
+    }
+}
 
 if ($tofind ne "all"){
-    print "finding $tofind\n";
+    warn "finding $tofind\n";
     find ($tofind);
-    print "Module $tofind: found @main'list\n";
+    warn "Module $tofind: found :\n";
+
+    for my $depkey (keys %main'list) {
+        print "$depkey $main'list{$depkey}   \n" 
+    }
 }
 else {
     for my $key (keys %data) {
@@ -124,8 +130,6 @@
     }
 }
     
-
-print "found @main'list\n";
 my $used=times();
-print "User: $used\n";
+warn  "User: $used\n";
 close DATAFILE;




More information about the Lunar-commits mailing list