summaryrefslogtreecommitdiff
path: root/memanalyze.pl
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2001-04-24 21:47:01 +0000
committerDaniel Stenberg <daniel@haxx.se>2001-04-24 21:47:01 +0000
commit90cce2ae3a51c1fc1c69bbcc23dd82cce84a492a (patch)
tree540d7277d9179b30bf1ab11b3f260e8c5460d2a8 /memanalyze.pl
parent775dc07eb52738c4081240ceff2fd2a76049ca23 (diff)
downloadgnurl-90cce2ae3a51c1fc1c69bbcc23dd82cce84a492a.tar.gz
gnurl-90cce2ae3a51c1fc1c69bbcc23dd82cce84a492a.tar.bz2
gnurl-90cce2ae3a51c1fc1c69bbcc23dd82cce84a492a.zip
added some verbose summary output stuff
Diffstat (limited to 'memanalyze.pl')
-rwxr-xr-xmemanalyze.pl55
1 files changed, 49 insertions, 6 deletions
diff --git a/memanalyze.pl b/memanalyze.pl
index faca19c04..a9dce2044 100755
--- a/memanalyze.pl
+++ b/memanalyze.pl
@@ -12,12 +12,21 @@ do {
}
} while (shift @ARGV);
+my $maxmem;
+
+sub newtotal {
+ my ($newtot)=@_;
+ # count a max here
+
+ if($newtot > $maxmem) {
+ $maxmem= $newtot;
+ }
+}
+
while(<STDIN>) {
chomp $_;
$line = $_;
- if($verbose) {
- print "IN: $line\n";
- }
+
if($line =~ /^MEM ([^:]*):(\d*) (.*)/) {
# generic match for the filename+linenumber
$source = $1;
@@ -34,17 +43,39 @@ while(<STDIN>) {
print "FREE ERROR: Previously freed at: ".$getmem{$addr}."\n";
}
else {
+ if(0 && $verbose) {
+ print "malloc at ".$getmem{$addr}." is freed again at $source:$linenum\n";
+ }
+
$totalmem -= $sizeataddr{$addr};
+
+ newtotal($totalmem);
+ $frees++;
+
$sizeataddr{$addr}=-1; # set -1 to mark as freed
$getmem{$addr}="$source:$linenum";
+
}
}
elsif($function =~ /malloc\((\d*)\) = 0x([0-9a-f]*)/) {
$size = $1;
$addr = $2;
+
+ if($sizeataddr{$addr}>0) {
+ # this means weeeeeirdo
+ print "Fucked up debug compile, rebuild curl now\n";
+ }
+
$sizeataddr{$addr}=$size;
$totalmem += $size;
+ if(0 && $verbose) {
+ print "malloc($size) at $source:$linenum\n";
+ }
+
+ newtotal($totalmem);
+ $mallocs++;
+
$getmem{$addr}="$source:$linenum";
}
elsif($function =~ /realloc\(0x([0-9a-f]*), (\d*)\) = 0x([0-9a-f]*)/) {
@@ -58,6 +89,9 @@ while(<STDIN>) {
$totalmem += $newsize;
$sizeataddr{$newaddr}=$newsize;
+ newtotal($totalmem);
+ $reallocs++;
+
$getmem{$oldaddr}="";
$getmem{$newaddr}="$source:$linenum";
}
@@ -71,6 +105,9 @@ while(<STDIN>) {
$sizeataddr{$addr}=$size;
$totalmem += $size;
+
+ newtotal($totalmem);
+ $strdups++;
}
else {
print "Not recognized input line: $function\n";
@@ -134,9 +171,6 @@ while(<STDIN>) {
else {
print "Not recognized prefix line: $line\n";
}
- if($verbose) {
- print "TOTAL: $totalmem\n";
- }
}
if($totalmem) {
@@ -168,3 +202,12 @@ if($fopens) {
}
}
}
+
+if($verbose) {
+ print "Mallocs: $mallocs\n",
+ "Reallocs: $reallocs\n",
+ "Strdups: $strdups\n",
+ "Frees: $frees\n";
+
+ print "Maximum allocated: $maxmem\n";
+}