From: Mauro Carvalho Chehab <mauro.chehab@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 07/12] code_cov_parse_info: add support for compressed files
Date: Tue, 17 Jan 2023 15:06:02 +0100 [thread overview]
Message-ID: <20230117140607.2759816-8-mauro.chehab@linux.intel.com> (raw)
In-Reply-To: <20230117140607.2759816-1-mauro.chehab@linux.intel.com>
From: Mauro Carvalho Chehab <mchehab@kernel.org>
Code coverage files are big. Add support for read/write gzipped
files, in order to save I/O, and, depending on the disk, speeding
up the tool.
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
---
scripts/code_cov_parse_info | 56 ++++++++++++++++++++++++++-----------
1 file changed, 40 insertions(+), 16 deletions(-)
mode change 100644 => 100755 scripts/code_cov_parse_info
diff --git a/scripts/code_cov_parse_info b/scripts/code_cov_parse_info
old mode 100644
new mode 100755
index 80a9f1c25540..d38ee9ee6a69
--- a/scripts/code_cov_parse_info
+++ b/scripts/code_cov_parse_info
@@ -6,6 +6,8 @@ use Getopt::Long;
BEGIN { $Pod::Usage::Formatter = 'Pod::Text::Termcap'; }
use Pod::Usage;
use Pod::Man;
+use IO::File;
+use IO::Zlib;
my $prefix = qr ".*?(linux)\w*/";
@@ -340,8 +342,14 @@ sub read_json($)
}
# Read JSON data
- open IN, $file or die "can't open $file";
- while (<IN>) {
+ my $fh;
+ if ($file =~ m/\.gz$/) {
+ $fh = IO::Zlib->new($file, "rb") or die "can't open $file";
+ } else {
+ $fh = IO::File->new($file) or die "can't open $file";
+ }
+ print "reading $file...\n" if ($verbose);
+ while (<$fh>) {
my $json = eval {
Cpanel::JSON::XS::decode_json($_)
};
@@ -361,7 +369,7 @@ sub read_json($)
die "Unknown JSON format on file $file\n";
}
}
- close IN;
+ $fh->close() or die "Failed to close file $file";
}
sub read_info($)
@@ -376,11 +384,16 @@ sub read_info($)
# First step: parse data
- print "reading $file...\n" if ($verbose);
- open IN, $file or die "can't open $file";
# For details on .info file format, see "man geninfo"
# http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php
- while (<IN>) {
+ my $fh;
+ if ($file =~ m/\.gz$/) {
+ $fh = IO::Zlib->new($file, "rb") or die "can't open $file";
+ } else {
+ $fh = IO::File->new($file) or die "can't open $file";
+ }
+ print "reading $file...\n" if ($verbose);
+ while (<$fh>) {
# TN:<test name>
if (m/^TN:(.*)/) {
if ($1 ne $cur_test) {
@@ -571,7 +584,7 @@ sub read_info($)
printf("Warning: invalid line: $_");
}
- close IN or die;
+ $fh->close() or die "Failed to close file $file";
}
sub sort_where($$)
@@ -601,9 +614,15 @@ sub write_json_file($)
Cpanel::JSON::XS::encode_json(\%record)
};
- open OUT, ">$fname" or die "Can't open $fname";
- print OUT $data or die "Failed to write to $fname";
- close OUT or die "Failed to close to $fname";
+ if ($fname =~ m/\.gz$/) {
+ my $fh = IO::Zlib->new($fname, "wb") or die "can't open $fname";
+ print $fh $data or die "Failed to write to $fname";
+ $fh->close or die "Failed to write to $fname";
+ } else {
+ open OUT, ">$fname" or die "Can't open $fname";
+ print OUT $data or die "Failed to write to $fname";
+ close OUT or die "Failed to close to $fname";
+ }
}
sub write_info_file($)
@@ -650,12 +669,17 @@ sub write_info_file($)
$data .= "BRDA:$ln,0,$i,$taken\n";
}
}
-
$data .= "end_of_record\n";
}
- open OUT, ">$fname" or die "Can't open $fname";
- print OUT $data or die "Failed to write to $fname";
- close OUT or die "Failed to close to $fname";
+ if ($fname =~ m/\.gz$/) {
+ my $fh = IO::Zlib->new($fname, "wb") or die "can't open $fname";
+ print $fh $data or die "Failed to write to $fname";
+ $fh->close or die "Failed to write to $fname";
+ } else {
+ open OUT, ">$fname" or die "Can't open $fname";
+ print OUT $data or die "Failed to write to $fname";
+ close OUT or die "Failed to close to $fname";
+ }
}
sub print_code_coverage($$$)
@@ -1346,7 +1370,7 @@ if ($ignore_unused) {
}
foreach my $f (@ARGV) {
- if ($f =~ /.json$/) {
+ if ($f =~ /\.json(\.gz)?$/) {
read_json($f);
} else {
read_info($f);
@@ -1425,7 +1449,7 @@ if ($show_files) {
}
if ($output_file) {
- if ($output_file =~ /.json$/) {
+ if ($output_file =~ /.json(.gz)?$/) {
write_json_file($output_file);
} else {
write_info_file($output_file);
--
2.39.0
next prev parent reply other threads:[~2023-01-17 14:06 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-17 14:05 [igt-dev] [PATCH i-g-t 00/12] Improve code coverage tool Mauro Carvalho Chehab
2023-01-17 14:05 ` [igt-dev] [PATCH i-g-t 01/12] code_cov_parse_info: silent some messages by default Mauro Carvalho Chehab
2023-01-17 14:05 ` [igt-dev] [PATCH i-g-t 02/12] code_cov_parse_info: do some renames to make it more coherent Mauro Carvalho Chehab
2023-01-17 14:05 ` [igt-dev] [PATCH i-g-t 03/12] code_cov_parse_info: use numberic sort for line numbers Mauro Carvalho Chehab
2023-01-17 14:05 ` [igt-dev] [PATCH i-g-t 04/12] code_cov_parse_info: better handle include regexes Mauro Carvalho Chehab
2023-01-17 14:06 ` [igt-dev] [PATCH i-g-t 05/12] code_cov_parse_info: add a tool to analyze branch coverage Mauro Carvalho Chehab
2023-01-17 14:06 ` [igt-dev] [PATCH i-g-t 06/12] code_cov_parse_info: add support for parsing JSON files Mauro Carvalho Chehab
2023-01-25 14:18 ` Kamil Konieczny
2023-01-17 14:06 ` Mauro Carvalho Chehab [this message]
2023-01-17 14:06 ` [igt-dev] [PATCH i-g-t 08/12] code_cov_parse_info: allow specifying the source directory Mauro Carvalho Chehab
2023-01-17 14:06 ` [igt-dev] [PATCH i-g-t 09/12] code_cov_parse_info: better handle branch filtering Mauro Carvalho Chehab
2023-01-17 14:06 ` [igt-dev] [PATCH i-g-t 10/12] code_cov_parse_info: filter out branches from headers by default Mauro Carvalho Chehab
2023-01-17 14:06 ` [igt-dev] [PATCH i-g-t 11/12] code_cov_parse_info: add support for filtering branches Mauro Carvalho Chehab
2023-01-17 14:06 ` [igt-dev] [PATCH i-g-t 12/12] code_cov_parse_info: add support for filtering Xe driver data Mauro Carvalho Chehab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230117140607.2759816-8-mauro.chehab@linux.intel.com \
--to=mauro.chehab@linux.intel.com \
--cc=igt-dev@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox