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 {