Partially Moified QueryReportFormatter, split event_report and query_report into two different subs; one that gets the values to print, and one that formats things

This commit is contained in:
Brian Fraser fraserb@gmail.com
2013-01-14 12:52:23 -03:00
parent e5d17af0fe
commit 5e5763f82a
5 changed files with 312 additions and 436 deletions

View File

@@ -43,7 +43,6 @@ my $o = new OptionParser(description=>'qrf');
my $ex = new ExplainAnalyzer(QueryRewriter => $qr, QueryParser => $qp);
$o->get_specs("$trunk/bin/pt-query-digest");
my $qrf = new QueryReportFormatter(
OptionParser => $o,
QueryRewriter => $qr,
@@ -885,6 +884,13 @@ ok(
# Test show_all.
@ARGV = qw(--show-all host);
$o->get_opts();
$qrf = new QueryReportFormatter(
OptionParser => $o,
QueryRewriter => $qr,
QueryParser => $qp,
Quoter => $q,
ExplainAnalyzer => $ex,
);
$result = $qrf->event_report(
ea => $ea,
select => [ qw(Query_time host) ],
@@ -971,7 +977,13 @@ $ea->calculate_statistical_metrics(apdex_t=>1);
# Reset opts in case anything above left something set.
@ARGV = qw();
$o->get_opts();
$qrf = new QueryReportFormatter(
OptionParser => $o,
QueryRewriter => $qr,
QueryParser => $qp,
Quoter => $q,
ExplainAnalyzer => $ex,
);
# Normally, the report subs will make their own ReportFormatter but
# that package isn't visible to QueryReportFormatter right now so we
# make ReportFormatters and pass them in. Since ReporFormatters can't
@@ -980,7 +992,7 @@ $o->get_opts();
# profile subreport. And the line width is 82 because that's the new
# default to accommodate the EXPLAIN sparkline (issue 1141).
my $report = new ReportFormatter(line_width=>82);
$qrf->set_report_formatter(report=>'profile', formatter=>$report);
$qrf->{formatter} = $report;
ok(
no_diff(
sub { $qrf->print_reports(
@@ -997,8 +1009,6 @@ ok(
"print_reports(header, query_report, profile)"
);
$report = new ReportFormatter(line_width=>82);
$qrf->set_report_formatter(report=>'profile', formatter=>$report);
ok(
no_diff(
sub { $qrf->print_reports(
@@ -1051,11 +1061,6 @@ foreach my $event ( @$events ) {
$ea->aggregate($event);
}
$ea->calculate_statistical_metrics();
$report = new ReportFormatter(
line_width => 82,
extend_right => 1,
);
$qrf->set_report_formatter(report=>'prepared', formatter=>$report);
ok(
no_diff(
sub {
@@ -1094,11 +1099,6 @@ foreach my $event ( @$events ) {
$ea->aggregate($event);
}
$ea->calculate_statistical_metrics();
$report = new ReportFormatter(
line_width => 82,
extend_right => 1,
);
$qrf->set_report_formatter(report=>'profile', formatter=>$report);
ok(
no_diff(
sub {
@@ -1130,7 +1130,13 @@ SKIP: {
@ARGV = qw(--explain F=/tmp/12345/my.sandbox.cnf);
$o->get_opts();
$qrf = new QueryReportFormatter(
OptionParser => $o,
QueryRewriter => $qr,
QueryParser => $qp,
Quoter => $q,
ExplainAnalyzer => $ex,
);
my $qrf = new QueryReportFormatter(
OptionParser => $o,
QueryRewriter => $qr,
@@ -1151,56 +1157,6 @@ SKIP: {
"explain_report()"
);
my $arg = "select t1.i from t as t1 join t as t2 where t1.i < t2.i and t1.v is not null order by t1.i";
my $fingerprint = $qr->fingerprint($arg);
$events = [
{
Query_time => '0.000286',
arg => $arg,
fingerprint => $fingerprint,
bytes => length $arg,
cmd => 'Query',
db => 'qrf',
pos_in_log => 0,
ts => '091208 09:23:49.637394',
},
];
$ea = new EventAggregator(
groupby => 'fingerprint',
worst => 'Query_time',
);
foreach my $event ( @$events ) {
$ea->aggregate($event);
}
$ea->calculate_statistical_metrics();
$dbh->do("USE mysql");
$report = new ReportFormatter(
line_width => 82,
extend_right => 1,
);
$qrf->set_report_formatter(report=>'profile', formatter=>$report);
$dbh->do("USE mysql"); # same reason as above ^; force use db from event
ok(
no_diff(
sub {
$qrf->print_reports(
reports => ['profile', 'query_report'],
ea => $ea,
worst => [ [$fingerprint, 'top', 1], ],
other => [ [$fingerprint, 'misc', 2], ],
orderby => 'Query_time',
groupby => 'fingerprint',
);
},
( $sandbox_version eq '5.6' ? "t/lib/samples/QueryReportFormatter/report032.txt"
: $sandbox_version ge '5.1' ? "t/lib/samples/QueryReportFormatter/report027.txt"
: "t/lib/samples/QueryReportFormatter/report029.txt"),
),
"EXPLAIN sparkline (issue 1141)"
);
$sb->wipe_clean($dbh);
$dbh->disconnect();
}
@@ -1251,7 +1207,6 @@ foreach my $event ( @$events ) {
$ea->calculate_statistical_metrics();
@ARGV = qw();
$o->get_opts();
$report = new ReportFormatter(line_width=>82);
$qrf = new QueryReportFormatter(
OptionParser => $o,
QueryRewriter => $qr,
@@ -1259,7 +1214,6 @@ $qrf = new QueryReportFormatter(
Quoter => $q,
ExplainAnalyzer => $ex,
);
$qrf->set_report_formatter(report=>'profile', formatter=>$report);
my $output = output(
sub { $qrf->print_reports(
reports => [qw(rusage date files header query_report profile)],
@@ -1323,11 +1277,6 @@ foreach my $event ( @$events ) {
$ea->aggregate($event);
}
$ea->calculate_statistical_metrics();
$report = new ReportFormatter(
line_width => 82,
extend_right => 1,
);
$qrf->set_report_formatter(report=>'profile', formatter=>$report);
ok(
no_diff(
sub {
@@ -1376,11 +1325,6 @@ foreach my $event ( @$events ) {
$ea->aggregate($event);
}
$ea->calculate_statistical_metrics();
$report = new ReportFormatter(
line_width => 82,
extend_right => 1,
);
$qrf->set_report_formatter(report=>'prepared', formatter=>$report);
ok(
no_diff(
sub {

View File

@@ -1,58 +0,0 @@
# Profile
# Rank Query ID Response time Calls R/Call Apdx V/M EXPLAIN Item
# ==== ================== ============= ===== ====== ==== ===== ======= =========
# 1 0x46F81B022F1AD76B 0.0003 100.0% 1 0.0003 NS 0.00 TF>aI SELECT t
# MISC 0xMISC 0.0003 100.0% 1 0.0003 NS 0.0 MISC <1 ITEMS>
# Query 1: 0 QPS, 0x concurrency, ID 0x46F81B022F1AD76B at byte 0 ________
# Scores: Apdex = NS [0.0]*, V/M = 0.00
# EXPLAIN sparkline: TF>aI
# Query_time sparkline: | ^ |
# Time range: all events occurred at 2009-12-08 09:23:49.637394
# Attribute pct total min max avg 95% stddev median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count 100 1
# Exec time 100 286us 286us 286us 286us 286us 0 286us
# Query size 100 90 90 90 90 90 0 90
# String:
# cmd Query
# Databases qrf
# Query_time distribution
# 1us
# 10us
# 100us ################################################################
# 1ms
# 10ms
# 100ms
# 1s
# 10s+
# Tables
# SHOW TABLE STATUS FROM `qrf` LIKE 't'\G
# SHOW CREATE TABLE `qrf`.`t`\G
# EXPLAIN /*!50100 PARTITIONS*/
select t1.i from t as t1 join t as t2 where t1.i < t2.i and t1.v is not null order by t1.i\G
# *************************** 1. row ***************************
# id: 1
# select_type: SIMPLE
# table: t1
# partitions: NULL
# type: ALL
# possible_keys: PRIMARY
# key: NULL
# key_len: NULL
# ref: NULL
# rows: 4
# Extra: Using where; Using temporary; Using filesort
# *************************** 2. row ***************************
# id: 1
# select_type: SIMPLE
# table: t2
# partitions: NULL
# type: index
# possible_keys: PRIMARY
# key: PRIMARY
# key_len: 4
# ref: NULL
# rows: 4
# Extra: Using where; Using index; Using join buffer

View File

@@ -1,56 +0,0 @@
# Profile
# Rank Query ID Response time Calls R/Call Apdx V/M EXPLAIN Item
# ==== ================== ============= ===== ====== ==== ===== ======= =========
# 1 0x46F81B022F1AD76B 0.0003 100.0% 1 0.0003 NS 0.00 TF>aI SELECT t
# MISC 0xMISC 0.0003 100.0% 1 0.0003 NS 0.0 MISC <1 ITEMS>
# Query 1: 0 QPS, 0x concurrency, ID 0x46F81B022F1AD76B at byte 0 ________
# Scores: Apdex = NS [0.0]*, V/M = 0.00
# EXPLAIN sparkline: TF>aI
# Query_time sparkline: | ^ |
# Time range: all events occurred at 2009-12-08 09:23:49.637394
# Attribute pct total min max avg 95% stddev median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count 100 1
# Exec time 100 286us 286us 286us 286us 286us 0 286us
# Query size 100 90 90 90 90 90 0 90
# String:
# cmd Query
# Databases qrf
# Query_time distribution
# 1us
# 10us
# 100us ################################################################
# 1ms
# 10ms
# 100ms
# 1s
# 10s+
# Tables
# SHOW TABLE STATUS FROM `qrf` LIKE 't'\G
# SHOW CREATE TABLE `qrf`.`t`\G
# EXPLAIN /*!50100 PARTITIONS*/
select t1.i from t as t1 join t as t2 where t1.i < t2.i and t1.v is not null order by t1.i\G
# *************************** 1. row ***************************
# id: 1
# select_type: SIMPLE
# table: t1
# type: ALL
# possible_keys: PRIMARY
# key: NULL
# key_len: NULL
# ref: NULL
# rows: 4
# Extra: Using where; Using temporary; Using filesort
# *************************** 2. row ***************************
# id: 1
# select_type: SIMPLE
# table: t2
# type: index
# possible_keys: PRIMARY
# key: PRIMARY
# key_len: 4
# ref: NULL
# rows: 4
# Extra: Using where; Using index

View File

@@ -1,56 +0,0 @@
# Profile
# Rank Query ID Response time Calls R/Call V/M Item
# ==== ================== ============= ===== ====== ===== =========
# 1 0x46F81B022F1AD76B 0.0003 100.0% 1 0.0003 0.00 SELECT t
# MISC 0xMISC 0.0003 100.0% 1 0.0003 0.0 <1 ITEMS>
# Query 1: 0 QPS, 0x concurrency, ID 0x46F81B022F1AD76B at byte 0 ________
# Scores: V/M = 0.00
# Time range: all events occurred at 2009-12-08 09:23:49.637394
# Attribute pct total min max avg 95% stddev median
# ============ === ======= ======= ======= ======= ======= ======= =======
# Count 100 1
# Exec time 100 286us 286us 286us 286us 286us 0 286us
# Query size 100 90 90 90 90 90 0 90
# String:
# cmd Query
# Databases qrf
# Query_time distribution
# 1us
# 10us
# 100us ################################################################
# 1ms
# 10ms
# 100ms
# 1s
# 10s+
# Tables
# SHOW TABLE STATUS FROM `qrf` LIKE 't'\G
# SHOW CREATE TABLE `qrf`.`t`\G
# EXPLAIN /*!50100 PARTITIONS*/
select t1.i from t as t1 join t as t2 where t1.i < t2.i and t1.v is not null order by t1.i\G
# *************************** 1. row ***************************
# id: 1
# select_type: SIMPLE
# table: t1
# partitions: NULL
# type: index
# possible_keys: PRIMARY
# key: PRIMARY
# key_len: 4
# ref: NULL
# rows: 4
# Extra: Using where
# *************************** 2. row ***************************
# id: 1
# select_type: SIMPLE
# table: t2
# partitions: NULL
# type: ALL
# possible_keys: PRIMARY
# key: NULL
# key_len: NULL
# ref: NULL
# rows: 4
# Extra: Range checked for each record (index map: 0x1)