dbilogstrip.PL

filter: Statementstmt 91.6% 11 / 12 Branchbran 50.0% 2 / 4 Conditioncond 36.3% 4 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub n/a Podpod n/a totaltotal 51.5% 17 / 33 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« dbiproxy.PL ↑ Summary DBI.xs »
1 #!/usr/bin/perl
2 # -*- perl -*-
3 1 ▶my $file = $ARGV[0] || 'dbilogstrip';
Condition50%1/2
$ARGV[0] || 'dbilogstrip'
l!l
10
MC/DC0%0/1
$ARGV[0] || 'dbilogstrip'
$ARGV[0]
Truth table50%1/2
A
A= $ARGV[0]
Aresult
11
00
4  
5 1 my $script = <<'SCRIPT';
6 ~startperl~
7  
8 =head1 NAME
9  
10 dbilogstrip - filter to normalize DBI trace logs for diff'ing
11  
12 =head1 SYNOPSIS
13  
14 Read DBI trace file C<dbitrace.log> and write out a stripped version to C<dbitrace_stripped.log>
15  
16 dbilogstrip dbitrace.log > dbitrace_stripped.log
17  
18 Run C<yourscript.pl> twice, each with different sets of arguments, with
19 DBI_TRACE enabled. Filter the output and trace through C<dbilogstrip> into a
20 separate file for each run. Then compare using diff. (This example assumes
21 you're using a standard shell.)
22  
23 DBI_TRACE=2 perl yourscript.pl ...args1... 2>&1 | dbilogstrip > dbitrace1.log
24 DBI_TRACE=2 perl yourscript.pl ...args2... 2>&1 | dbilogstrip > dbitrace2.log
25 diff -u dbitrace1.log dbitrace2.log
26  
27 =head1 DESCRIPTION
28  
29 Replaces any hex addresses, e.g, C<0x128f72ce> with C<0xN>.
30  
31 Replaces any references to process id or thread id, like C<pid#6254> with C<pidN>.
32  
33 So a DBI trace line like this:
34  
35 -> STORE for DBD::DBM::st (DBI::st=HASH(0x19162a0)~0x191f9c8 'f_params' ARRAY(0x1922018)) thr#1800400
36  
37 will look like this:
38  
39 -> STORE for DBD::DBM::st (DBI::st=HASH(0xN)~0xN 'f_params' ARRAY(0xN)) thrN
40  
41 =cut
42  
43 use strict;
44  
45 while (<>) {
46 # normalize hex addresses: 0xDEADHEAD => 0xN
47 s/ \b 0x [0-9a-f]+ /0xN/gx;
48 # normalize process and thread id number
49 s/ \b (pid|tid|thr) \W? \d+ /${1}N/gx;
50  
51 } continue {
52 print or die "-p destination: $!\n";
53 }
54  
55  
56 SCRIPT
57  
58 1 require Config;
59 1 my $config = {};
60 1 $config->{'startperl'} = $Config::Config{'startperl'};
61  
62 1 $script =~ s/\~(\w+)\~/$config->{$1}/eg;
63 1 ▶if (!(open(FILE, ">$file")) ||
Branch: 1 branch
BranchTrueFalseTotal
unless (open FILE, ">$file" and print FILE $script and close FILE) 0 1 1
Condition33%2/6
open FILE, ">$file" and print FILE $script and close FILE
!ll&&!rl&&r
001
open FILE, ">$file" and print FILE $script
!ll&&!rl&&r
001
MC/DC0%0/3
open FILE, ">$file" and print FILE $script and close FILE
open FILE, ">$file" print FILE $script close FILE
Truth table25%1/4
A and B and C
A= open FILE, ">$file"B= print FILE $scriptC= close FILE
ABCresult
0XX0
10X0
1100
1111
64 !(print FILE $script) ||
65 !(close(FILE))) {
66 0 die "Error while writing $file: $!\n";
67 }
68 1 chmod 0755, $file;
69 1 print "Extracted $file from ",__FILE__," with variable substitutions.\n";
70 # syntax check resulting file, but only for developers
71 1 ▶exit 1 if -d ".svn" and system($^X, '-wc', '-Mblib', $file) != 0;
Branch: 1 branch
BranchTrueFalseTotal
if -d ".svn" and system($^X, "-wc", "-Mblib", $file) != 0 0 1 1
Condition33%1/3
-d ".svn" and system($^X, "-wc", "-Mblib", $file) != 0
!ll&&!rl&&r
100
MC/DC0%0/2
-d ".svn" and system($^X, "-wc", "-Mblib", $file) != 0
-d ".svn" system($^X, "-wc", "-Mblib", $file) != 0
Truth table33%1/3
A and B
A= -d ".svn"B= system($^X, "-wc", "-Mblib", $file) != 0
ABresult
0X0
100
111
72  
« dbiproxy.PL ↑ Summary DBI.xs »