From c6068aa2852a46a43f2709dfcd1722ec67461854 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Tue, 5 Mar 2013 09:59:33 -0700 Subject: [PATCH] Clean up docs. Clean up t/pt-query-digest/since_until.t. review.t needs to be fixed and cleaned up (i.e. use pt_query_digest::main() instead of shelling out, split off --history tests into history.t, etc.). --- bin/pt-query-digest | 449 ++++++++++++++++---------------- t/pt-query-digest/since_until.t | 90 ++++++- 2 files changed, 302 insertions(+), 237 deletions(-) diff --git a/bin/pt-query-digest b/bin/pt-query-digest index 039ce55a..cd5f53db 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -12504,7 +12504,7 @@ sub main { my $db_tbl = $q->quote(@db_tbl); my $create_review_sql = $o->read_para_after( - __FILE__, qr/\bMAGIC_create_review\b/); + __FILE__, qr/\bMAGIC_create_review_table\b/); $create_review_sql =~ s/\bquery_review\b/$db_tbl/; create_review_tables( @@ -12548,9 +12548,9 @@ sub main { my $hdb_tbl = $q->quote(@hdb_tbl); my $create_history_sql = $o->read_para_after( - __FILE__, qr/\bMAGIC_create_review_history\b/); + __FILE__, qr/\bMAGIC_create_history_table\b/); $create_history_sql =~ s/\bquery_history\b/$hdb_tbl/; - + create_review_tables( type => 'history', dbh => $qh_dbh, @@ -12561,7 +12561,7 @@ sub main { ); my $tbl = $tp->parse($tp->get_create_table($qh_dbh, @hdb_tbl)); - my $pat = $o->read_para_after(__FILE__, qr/\bMAGIC_history_cols\b/); + my $pat = $o->read_para_after(__FILE__, qr/\bMAGIC_history_columns\b/); $pat =~ s/\s+//g; $pat = qr/^(.*?)_($pat)$/; @@ -13769,10 +13769,12 @@ sub handle_special_defaults { my ($o, $opt) = @_; my $dsn = $o->get($opt); return unless $dsn; - - my $default_table = $o->read_para_after( - __FILE__, qr/MAGIC_${opt}_table/); - $default_table =~ s/.+\s(\S+)$/$1/; + + my $para = $o->read_para_after( + __FILE__, qr/MAGIC_default_${opt}_table/); + my ($default_table) = $para =~ m/default table is C<[^>]+>/; + die "Error parsing special default for --$opt" + unless $default_table; my ($D, $t) = Quoter->split_unquote($default_table); $dsn->{D} ||= $D; $dsn->{t} ||= $t; @@ -14087,7 +14089,7 @@ pt-query-digest - Analyze MySQL queries from logs, processlist, and tcpdump. Usage: pt-query-digest [OPTIONS] [FILES] [DSN] -pt-query-digest analyzes queries from MySQL slow, general, and binary log +pt-query-digest analyzes MySQL queries from slow, general, and binary log files. It can also analyze queries from C and MySQL protocol data from tcpdump. By default, queries are grouped by fingerprint and reported in descending order of query time (i.e. the slowest queries @@ -14140,25 +14142,34 @@ See also L<"BUGS"> for more information on filing bugs and getting help. =head1 DESCRIPTION -C is a framework for doing things with events from a query -source such as the slow query log or PROCESSLIST. By default it acts as a very -sophisticated log analysis tool. You can group and sort queries in many -different ways simultaneously and find the most expensive queries, or create a -timeline of queries in the log, for example. It can also do a "query review," -which means to save a sample of each type of query into a MySQL table so you can -easily see whether you've reviewed and analyzed a query before. The benefit of -this is that you can keep track of changes to your server's queries and avoid -repeated work. You can also save other information with the queries, such as -comments, issue numbers in your ticketing system, and so on. +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, as well as 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 +can be created by using options like L<"--group-by">, L<"--filter">, and +L<"--embedded-attributes">. + +Query analysis is a best-practice that should be done frequently. To +make this easier, pt-query-digest has two features: query review +(L<"--review">) and query history (L<"--history">). When the L<"--review"> +option is used, all unique queries are saved to a database. When the +tool is ran again with L<"--review">, queries marked as reviewed in +the database are not printed in the report. This highlights new queries +that need to be reviewed. When the L<"--history"> option is used, +query metrics (query time, lock time, etc.) for each unique query are +saved to database. Each time the tool is ran with L<"--history">, the +more historical data is saved which can be used to trend and analyze +query performance over time. =head1 ATTRIBUTES -pt-query-digest works on events, which are a collection of key/value pairs +pt-query-digest works on events, which are a collection of key-value pairs called attributes. You'll recognize most of the attributes right away: -Query_time, Lock_time, and so on. You can just look at a slow log and see them. -However, there are some that don't exist in the slow log, and slow logs -may actually include different kinds of attributes (for example, you may have a -server with the Percona patches). +C, C, and so on. You can just look at a slow log +and see them. However, there are some that don't exist in the slow log, +and slow logs may actually include different kinds of attributes (for example, +you may have a server with the Percona patches). See L<"ATTRIBUTES REFERENCE"> near the end of this documentation for a list of common and L<"--type"> specific attributes. A familiarity with these @@ -14176,7 +14187,7 @@ The C<&& 1> trick is needed to create a valid one-line syntax that is always true, even if the assignment happens to evaluate false. The new attribute will automatically appears in the output: - # Row ratio 1.00 0.00 1 0.50 1 0.71 0.50 + # Row ratio 1.00 0.00 1 0.50 1 0.71 0.50 Attributes created this way can be specified for L<"--order-by"> or any option that requires an attribute. @@ -14186,11 +14197,11 @@ option that requires an attribute. The default L<"--output"> is a query analysis report. The L<"--[no]report"> option controls whether or not this report is printed. Sometimes you may want to parse all the queries but suppress the report, for example when using -L<"--review">. +L<"--review"> or L<"--history">. There is one paragraph for each class of query analyzed. A "class" of queries all have the same value for the L<"--group-by"> attribute which is -"fingerprint" by default. (See L<"ATTRIBUTES">.) A fingerprint is an +C by default. (See L<"ATTRIBUTES">.) A fingerprint is an abstracted version of the query text with literals removed, whitespace collapsed, and so forth. The report is formatted so it's easy to paste into emails without wrapping, and all non-query lines begin with a comment, so you @@ -14245,17 +14256,17 @@ select the reviewed query's details from the database with a query like C