Add code to automatically uncompress .gz and .bz2 files that are given as arguments.
authordbaron@dbaron.org
Wed, 20 Jun 2007 14:59:33 -0700
changeset 2618 7d9faff1e81c5da6b09474e2de2e0ff1b21360e4
parent 2617 7b348148692878a7a53f8a3a378ed758d7b10721
child 2619 706b1f7437e5549ee10ab8a86fdd2c283ef72a85
push idunknown
push userunknown
push dateunknown
milestone1.9a6pre
Add code to automatically uncompress .gz and .bz2 files that are given as arguments.
tools/trace-malloc/diffbloatdump.pl
--- a/tools/trace-malloc/diffbloatdump.pl
+++ b/tools/trace-malloc/diffbloatdump.pl
@@ -122,17 +122,25 @@ sub add_file($$) {
             $node = $node->{children}->{$stack[$i]};
             ++$i;
         }
         $node->{count} += $factor;
     }
 
     my ($infile, $factor) = @_;
 
-    open (INFILE, "<$infile") || die "Can't open input \"$infile\"";
+    if ($infile =~ /\.bz2$/) {
+        # XXX This doesn't propagate errors from bzip2.
+        open (INFILE, "bzip2 -cd '$infile' |") || die "Can't open input \"$infile\"";
+    } elsif ($infile =~ /\.gz$/) {
+        # XXX This doesn't propagate errors from gzip.
+        open (INFILE, "gzip -cd '$infile' |") || die "Can't open input \"$infile\"";
+    } else {
+        open (INFILE, "<$infile") || die "Can't open input \"$infile\"";
+    }
     while ( ! eof(INFILE) ) {
         # read the type and address
         my $line = <INFILE>;
         unless ($line =~ /.*\((\d*)\)[\r|\n]/) {
             die "badly formed allocation header in $infile";
         }
         my $size;
         if ($::opt_allocation_count) {