5749424 [rkeene@sledge /home/rkeene/projects/scripts]$ cat -n profile_subs.plx
   1: #! /usr/bin/perl
   2: 
   3: sub test_proc1 {
   4: 	my $arg = shift;
   5:         print "heh: " . test_proc2($arg,"jim") . "\n";
   6: 	sleep 1;
   7: }
   8: 
   9: sub test_proc2 {
  10: 	my $bob = shift;
  11: 	my $joe = shift;
  12: 	print "whee: " . $bob . " " . $joe . "\n";
  13: 	sleep 1;
  14: 	return "joe";
  15: }
  16: 
  17: for my $f ( grep { defined &{$_} } keys %{__PACKAGE__ . "::"} ) {
  18: 	*{$f."_real"} = \&{$f}; *{$f} = sub {
  19: 		my $start = time;
  20: 		my $ret = &{$f."_real"};
  21: 		$elaptime=time-$start;
  22: 		$count{$f}++;
  23: 		$ttime{$f}+=$elaptime;
  24: 		printf("%s:[%i]: %i seconds (total=%i seconds)\n", $f, $count{$f}, $elaptime, $ttime{$f});
  25: 		return $ret;
  26: 	}
  27: }
  28: 
  29: test_proc1("sally");
  30: test_proc2("bobby", "wally");
5749425 [rkeene@sledge /home/rkeene/projects/scripts]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2004-03-20 23:48:00