From 5edb7366f38b949a245905417cd003f57fea23e4 Mon Sep 17 00:00:00 2001 From: Frank Cizmich Date: Wed, 5 Nov 2014 12:41:15 -0200 Subject: [PATCH] Improved test. Changed test file location. Added doc example. --- bin/pt-query-digest | 28 ++++++++++++--------------- t/lib/samples/binlogs/raw_binlog.log | Bin 0 -> 2551 bytes t/pt-query-digest/binlog_analyses.t | 17 +++++++++++----- 3 files changed, 24 insertions(+), 21 deletions(-) create mode 100644 t/lib/samples/binlogs/raw_binlog.log diff --git a/bin/pt-query-digest b/bin/pt-query-digest index 8be749d4..12bf8097 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -13185,7 +13185,7 @@ sub main { if ( $filename && $o->get('type')->[0] eq 'binlog') { if (is_raw_binlog($filename)) { warn "Binlog file $filename must first be converted to text format using mysqlbinlog"; - exit 1; + return 1; } } push @read_files, { name => ($filename || "STDIN"), size => $filesize }; @@ -14730,21 +14730,11 @@ sub sanitize_event { } # make an effort to check if file is a raw binlog -# ( i.e was not converted to text using mysqlbinlog ) +# (i.e. was not converted to text using mysqlbinlog) sub is_raw_binlog { my $filename = shift; - - my $output; - eval { - $output = `file $filename`; - }; - - # if we can't determine file type, let's assume it's ok - if ($EVAL_ERROR || !$output) { - return 0; - } - - return $output =~ /MySQL\s*replication/i; + + return -B $filename; } sub _d { @@ -14823,7 +14813,7 @@ server. Before using this tool, please: pt-query-digest is a sophisticated but easy to use tool for analyzing MySQL queries. It can analyze queries from MySQL slow, general, and binary -logs. ( Binary logs must first be converted to text, see L<"--type"> ). +logs. (Binary logs must first be converted to text, see L<"--type">). It can also use C and MySQL protocol data from tcpdump. By default, the tool reports which queries are the slowest, and therefore the most important to optimize. More complex and custom-tailored reports @@ -16160,7 +16150,13 @@ The type of input to parse. The permitted types are =item binlog -Parse a binary log file that has been converted to text using mysqlbinlog. +Parse a binary log file that has first been converted to text using mysqlbinlog. + +For example: + + mysqlbinlog mysql-bin.000441 > mysql-bin.000441.txt + + pt-query-digest --type binlog mysql-bin.000441.txt =item genlog diff --git a/t/lib/samples/binlogs/raw_binlog.log b/t/lib/samples/binlogs/raw_binlog.log new file mode 100644 index 0000000000000000000000000000000000000000..58bd214d4908dd1b33225c78f7239b7a359e967c GIT binary patch literal 2551 zcmcJQJxIe)5XY}=v=J1g4u!g;AXLGIv|1>*h$tcjr*6f;(jcWJg(fMuSU>9A&Bc#` zlbfr17x%6XYFBp`5$~Sikw6fdzCL&%kaDiTZCE6&w&gvkZ{ESiXbIq?3HCX3^!O0(`|NeKhafK z#v?5WAn|ubb+)D>rd5%Wki<4iH!axS-P=Flj6-aiWzC~7s)ngIEv0H$4aI2G^b@6Z zRJV0gS;?$rR|&pA%q83@25&MKfLphF4NC#sIfL9^1iKTQyAK)MblmUU?x}Dfcg`U9 z4l-b*XZL^Z1n2HO2Dkj&hXUNUA`^5kF}Urx-@9|~VJX1Oa0cc6E!dslJoh-hg8(hZ z{mt!O!cqWt&LH<^h8Op)5}dma82r@FJw7$QyM+vq^X_r)GI-l@e|P6T2x9z zE%5v9ac?vDrQ`nLp7(w*cg~=BS7yYz6P(ZcCWCkU+}l_Rkh{nIb&~F141VRf{{l># Bcmx0d literal 0 HcmV?d00001 diff --git a/t/pt-query-digest/binlog_analyses.t b/t/pt-query-digest/binlog_analyses.t index a0fde6d9..f8f76016 100644 --- a/t/pt-query-digest/binlog_analyses.t +++ b/t/pt-query-digest/binlog_analyses.t @@ -52,11 +52,18 @@ ok( # Issue 1377888: refuse to parse raw binary log # ############################################################################# -my $output = `$trunk/bin/pt-query-digest --type binlog '$trunk/t/pt-query-digest/samples/raw_binlog.log' 2>&1`; -ok( - $output =~ /mysqlbinlog/i , - 'Refuses to parse raw binlog file.' - ); +my $output = output( + sub { pt_query_digest::main(@args, "$trunk/t/lib/samples/binlogs/raw_binlog.log") }, + stderr => 1 +); + +like( + $output, + qr/mysqlbinlog/i, + 'Refuses to parse raw binlog file' +); + + # #############################################################################