Code comment why MiB, GiB, etc. are used in shorten() and update that func in pt-summary and pt-mysql-summary.

This commit is contained in:
Daniel Nichter
2012-05-07 16:38:30 -06:00
parent fdfd305dc5
commit cc80f278d5
4 changed files with 46 additions and 46 deletions

View File

@@ -576,22 +576,19 @@ shorten() {
local div="${3:-1024}" local div="${3:-1024}"
echo "$num" | awk -v prec="$prec" -v div="$div" ' echo "$num" | awk -v prec="$prec" -v div="$div" '
{ {
size = 4; num = $1;
val = $1; unit = num >= 1125899906842624 ? "P" \
: num >= 1099511627776 ? "T" \
unit = val >= 1099511627776 ? "T" : val >= 1073741824 ? "G" : val >= 1048576 ? "M" : val >= 1024 ? "k" : ""; : num >= 1073741824 ? "G" \
: num >= 1048576 ? "M" \
while ( int(val) && !(val % 1024) ) { : num >= 1024 ? "k" \
val /= 1024; : "";
while ( num >= div ) {
num /= div;
}
printf "%.*f%s", prec, num, unit;
} }
while ( val > 1000 ) {
val /= div;
}
printf "%.*f%s", prec, val, unit;
}
' '
} }

View File

@@ -713,22 +713,19 @@ shorten() {
local div="${3:-1024}" local div="${3:-1024}"
echo "$num" | awk -v prec="$prec" -v div="$div" ' echo "$num" | awk -v prec="$prec" -v div="$div" '
{ {
num = $1; num = $1;
unit = num >= 1125899906842624 ? "P" \
unit = num >= 1125899906842624 ? "P" \ : num >= 1099511627776 ? "T" \
: num >= 1099511627776 ? "T" \ : num >= 1073741824 ? "G" \
: num >= 1073741824 ? "G" \ : num >= 1048576 ? "M" \
: num >= 1048576 ? "M" \ : num >= 1024 ? "k" \
: num >= 1024 ? "k" \ : "";
: ""; while ( num >= div ) {
num /= div;
while ( num >= div ) { }
num /= div; printf "%.*f%s", prec, num, unit;
} }
printf "%.*f%s", prec, num, unit;
}
' '
} }

View File

@@ -87,23 +87,29 @@ shorten() {
local prec="${2:-2}" local prec="${2:-2}"
local div="${3:-1024}" local div="${3:-1024}"
# By default Mebibytes (MiB), Gigibytes (GiB), etc. are used because
# that's what MySQL uses. This may create odd output for values like
# 1500M * 2 (bug 937793) because the base unit is MiB but the code
# see 1,572,864,000 * 2 = 3,145,728,000 which is > 1 GiB so it uses
# GiB as the unit, resulting in 2.9G instead of 3.0G that the user
# might expect to see. There's no easy way to determine that
# 3,145,728,000 was actually a multiple of MiB and not some weird GiB
# value to begin with like 3.145G. The Perl lib Transformers::shorten()
# uses MiB, GiB, etc. too.
echo "$num" | awk -v prec="$prec" -v div="$div" ' echo "$num" | awk -v prec="$prec" -v div="$div" '
{ {
num = $1; num = $1;
unit = num >= 1125899906842624 ? "P" \
unit = num >= 1125899906842624 ? "P" \ : num >= 1099511627776 ? "T" \
: num >= 1099511627776 ? "T" \ : num >= 1073741824 ? "G" \
: num >= 1073741824 ? "G" \ : num >= 1048576 ? "M" \
: num >= 1048576 ? "M" \ : num >= 1024 ? "k" \
: num >= 1024 ? "k" \ : "";
: ""; while ( num >= div ) {
num /= div;
while ( num >= div ) { }
num /= div; printf "%.*f%s", prec, num, unit;
} }
printf "%.*f%s", prec, num, unit;
}
' '
} }

View File

@@ -78,7 +78,7 @@ is \
is \ is \
"$(section "A_B_C")" \ "$(section "A_B_C")" \
"# A#B#C#######################################################" \ "# A#B#C#######################################################" \
"replace everything after and including first underscore with #s" "replace extra underscores with #s"
# name_val # name_val