1
# This program is copyright 2011 Percona Inc.
2
# Feedback and improvements are welcome.
4
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
5
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
6
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
8
# This program is free software; you can redistribute it and/or modify it under
9
# the terms of the GNU General Public License as published by the Free Software
10
# Foundation, version 2; OR the Perl Artistic License. On UNIX and similar
11
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
14
# You should have received a copy of the GNU General Public License along with
15
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16
# Place, Suite 330, Boston, MA 02111-1307 USA.
17
# ###########################################################################
18
# report_formatting package
19
# ###########################################################################
21
# Package: report_formatting
22
# Common report formatting functions for the summary tools.
27
export POSIXLY_CORRECT
31
if (fuzzy_var <= 10 ) {
35
while ( rounded == 0 ) {
36
if ( fuzzy_var <= 50 * factor ) {
37
fuzzy_var = sprintf("%.0f", fuzzy_var / (5 * factor)) * 5 * factor;
40
else if ( fuzzy_var <= 100 * factor) {
41
fuzzy_var = sprintf("%.0f", fuzzy_var / (10 * factor)) * 10 * factor;
44
else if ( fuzzy_var <= 250 * factor) {
45
fuzzy_var = sprintf("%.0f", fuzzy_var / (25 * factor)) * 25 * factor;
51
# Does fuzzy rounding: rounds to nearest interval, but the interval gets larger
52
# as the number gets larger. This is to make things easier to diff.
54
awk -v fuzzy_var="$1" "BEGIN { ${fuzzy_formula} print fuzzy_var;}"
57
# Fuzzy computes the percent that $1 is of $2
59
local pct="$(awk -v one="$1" -v two="$2" 'BEGIN{ if (two > 0) { printf "%d", one/two*100; } else {print 0} }')";
60
echo "$(fuzz "${pct}")%"
63
# Prints a section header. All spaces in the string passed in are replaced
64
# with #'s and all underscores with spaces.
67
awk -v var="${str} _" 'BEGIN {
68
line = sprintf("# %-60s", var);
71
gsub(/[_ \t]/, "#", x);
72
printf("%s%s\n", substr(line, 1, i-1), x);
78
# We use $NAME_VAL_LEN here because the two summary tools, as well as
79
# the tests, use diffent widths.
80
printf "%+*s | %s\n" "${NAME_VAL_LEN}" "$1" "$2"
84
# Shorten a value in bytes to another representation.
89
local div="${3:-1024}"
91
echo "$num" | awk -v prec="$prec" -v div="$div" '
96
unit = val >= 1099511627776 ? "T" : val >= 1073741824 ? "G" : val >= 1048576 ? "M" : val >= 1024 ? "k" : "";
98
while ( int(val) && !(val % 1024) ) {
102
while ( val > 1000 ) {
106
printf "%.*f%s", prec, val, unit;
112
sed -e '{H; $!d;}' -e 'x' -e 's/\n[[:space:]]*\([[:digit:]]*\)[[:space:]]*/, \1x/g' -e 's/[[:space:]][[:space:]]*/ /g' -e 's/, //' "${1}"
115
# ###########################################################################
116
# End report_formatting package
117
# ###########################################################################