blob: 4116074b80ec1da933aff8889dd1f8f127149603 [file] [log] [blame]
Ross Zwislerc81950e2019-09-18 15:36:401#!/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
17use strict;
18use warnings;
19use IO::Uncompress::Unzip qw(unzip $UnzipError);
20
21my $zip_file = $ARGV[0];
22
23die "'$zip_file' is not a file\n" if ( ! -f $zip_file );
24
25my $output_dir = $zip_file;
26$output_dir =~ s/.zip$//;
27
28die "$output_dir already exists\n" if -e $output_dir;
29mkdir $output_dir;
30
31my $z = new IO::Uncompress::Unzip $zip_file or die "unzip failed: $UnzipError\n";
32
33while (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";