From 41f440518f61d2b8e89c0621b862fe79c3b309ca Mon Sep 17 00:00:00 2001 From: "Brian Fraser fraserb@gmail.com" <> Date: Thu, 17 Jan 2013 19:40:58 -0300 Subject: [PATCH] Fixed the precisions for numbers in the json output --- bin/pt-query-digest | 6 ++++-- lib/JSONReportFormatter.pm | 9 +++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bin/pt-query-digest b/bin/pt-query-digest index 01bf5e1f..4e779928 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -8049,11 +8049,13 @@ override query_report => sub { elsif ( ($ea->{type_for}->{$attrib} || '') eq 'num' ) { for my $value ( values %{$metrics{$attrib}} ) { next unless $value; - $value = sprintf '%.7f', $value; + $value = sprintf '%.6f', $value; + } + if ( my $pct = $metrics{$attrib}->{pct} ) { + $metrics{$attrib}->{pct} = sprintf('%.2f', $pct); } } } - push @queries, { class => \%class, attributes => \%metrics, diff --git a/lib/JSONReportFormatter.pm b/lib/JSONReportFormatter.pm index e2cc0a31..331e08de 100644 --- a/lib/JSONReportFormatter.pm +++ b/lib/JSONReportFormatter.pm @@ -71,13 +71,18 @@ override query_report => sub { $class{ts_max} = $ts->{max}; } elsif ( ($ea->{type_for}->{$attrib} || '') eq 'num' ) { + # Avoid scientific notation in the metrics by forcing it to use + # six decimal places. for my $value ( values %{$metrics{$attrib}} ) { next unless $value; - $value = sprintf '%.7f', $value; + $value = sprintf '%.6f', $value; + } + # ..except for the percentage, which only needs two + if ( my $pct = $metrics{$attrib}->{pct} ) { + $metrics{$attrib}->{pct} = sprintf('%.2f', $pct); } } } - push @queries, { class => \%class, attributes => \%metrics,