forked from Percona-QA/percona-qa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_general_log.pl
executable file
·74 lines (67 loc) · 2.3 KB
/
parse_general_log.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl
# Created by Roel Van de Paar, Percona LLC
use strict 'vars';
use Getopt::Std;
our ($opt_i,$opt_o);
getopt('io');
if (($opt_i eq '')||($opt_o eq '')){
print "Usage: [perl] ./parse_general_log.pl -i infile -o outfile\n";
print "Where infile is a standard myqld general query log\n";
print "General mysqld logs can be generated with these options to MTR (or RQG):\n";
print " --mysqld=--log-output=FILE --mysqld=--general_log --mysqld=--general_log_file=out.sql\n\n";
print "WARNING: by default this script eliminates a number of statements which may cause replay issues (KILL, RELEASE)\n";
print "This may lead to non-reproducibility for certain bugs. Check the script's source for specifics\n";
exit 1;
}
open IFILE, "<", $opt_i or die $!;
open OFILE, ">", $opt_o or die $!;
print OFILE "DROP DATABASE transforms;CREATE DATABASE transforms;DROP DATABASE test;CREATE DATABASE test;USE test;\n";
my $past_header=0;
my $first_stmt=0;
while (<IFILE>) {
chomp ($_);
my $out="";
# Are we past the intro header?
if (($_=~/^[0-9\t]/)&&($past_header==0)){
$past_header=1;
}
if ($past_header==1){
# Multi-line statements are covered first
if ($_=~/^[^0-9\t]/){
$out = substr $_,0,9999999;
if ((!($out=~/^kill [0-9]/i))&&(!($out=~/commit[^n.]*release/i))){
print OFILE "\n$out";
}
}elsif (($_=~/[0-9] Query\t/)||($_=~/[0-9] Prepare\t/)||($_=~/[0-9] Execute\t/)){
if ($_=~/^[0-9]/){
# Fix line format for lines that have timestamps
s/.*[0-9] Query\t/\t\t 0 Query\t/;
s/.*[0-9] Prepare\t/\t\t 0 Prepare\t/;
s/.*[0-9] Execute\t/\t\t 0 Execute\t/;
}
s/\t/ /g;
$out = substr $_,35,9999999;
# Drop KILL and COMMIT RELEASE statements (KILL QUERY and COMMIT NO RELEASE are not affected)
if ((!($out=~/^kill [0-9]/i))&&(!($out=~/commit[^n.]*release/i))){
if ($first_stmt==1){
print OFILE ";\n$out";
}else{
print OFILE "$out";
$first_stmt=1;
}
}
}elsif ($_=~/[0-9] Init DB\t/){
$out = substr $_,16,999;
if ($first_stmt==1){
print OFILE ";\nUSE $out";
}else{
print OFILE "USE $out";
$first_stmt=1;
}
}
}
}
# Fixup last line
print OFILE ";\n";
close IFILE;
close OFILE;