Ross Zwisler | c81950e | 2019-09-18 15:36:40 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | # |
| 3 | # Copyright 2019 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | # |
| 7 | # Maintainer: Ross Zwisler <[email protected]> |
| 8 | # |
| 9 | # feedback-unpack: Unpack a zipped feedback report into individual log files |
| 10 | # for easy viewing. |
| 11 | # |
| 12 | # Usage: feedback-unpack <${feedback_report}.zip> |
| 13 | # |
| 14 | # This will create a ${feedback_report} directory and fill it with the log |
| 15 | # files found in the zipped feedback report. |
| 16 | |
| 17 | use strict; |
| 18 | use warnings; |
| 19 | use IO::Uncompress::Unzip qw(unzip $UnzipError); |
| 20 | |
| 21 | my $zip_file = $ARGV[0]; |
| 22 | |
| 23 | die "'$zip_file' is not a file\n" if ( ! -f $zip_file ); |
| 24 | |
| 25 | my $output_dir = $zip_file; |
| 26 | $output_dir =~ s/.zip$//; |
| 27 | |
| 28 | die "$output_dir already exists\n" if -e $output_dir; |
| 29 | mkdir $output_dir; |
| 30 | |
| 31 | my $z = new IO::Uncompress::Unzip $zip_file or die "unzip failed: $UnzipError\n"; |
| 32 | |
| 33 | while (my $line = $z->getline()) { |
| 34 | if ($line =~ /^(Profile\[.*\] )?(.*)=<multiline>$/) { |
| 35 | my $new_log = "$output_dir/$2"; |
| 36 | open (my $fh, ">", $new_log) or die "Cannot open $new_log: $!"; |
| 37 | while (my $line = $z->getline()) { |
| 38 | next if ($line =~ /---------- START ----------/); |
| 39 | last if ($line =~ /---------- END ----------/); |
| 40 | print $fh $line; |
| 41 | } |
| 42 | close ($fh) or warn "Couldn't close $new_log: $!"; |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | $z->close() or die "close failed: $UnzipError\n"; |