Debian Codegraph @

mysql-test/suite/plugins/t/normalize_query_id.pl

raw
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 my $filename = $ARGV[0] or die "Usage: $0 <logfile>\n";
6
7 # Read all lines into memory
8 open(my $fh, '<', $filename) or die "Cannot open file '$filename': $!";
9 my @lines = <$fh>;
10 close($fh);
11
12 # Process lines and normalize query IDs
13 my $first_id;
14 foreach my $line (@lines) {
15 if ($line =~ /,(\d+),QUERY/) {
16 $first_id = $1 unless defined $first_id;
17 my $normalized = $1 - $first_id;
18 $line =~ s/,$1,QUERY/,$normalized,QUERY/;
19 }
20 }
21
22 # Write back to the same file
23 open($fh, '>', $filename) or die "Cannot write to file '$filename': $!";
24 print $fh @lines;
25 close($fh);