mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 13:11:32 +00:00
Simplify and fix report_formatting::shorten(), and add Petabyte unit (in case it's needed). Update affected test samples. Add T_DIR to util/test-bash-functions.
This commit is contained in:
@@ -714,20 +714,20 @@ shorten() {
|
||||
|
||||
echo "$num" | awk -v prec="$prec" -v div="$div" '
|
||||
{
|
||||
size = 4;
|
||||
val = $1;
|
||||
num = $1;
|
||||
|
||||
unit = val >= 1099511627776 ? "T" : val >= 1073741824 ? "G" : val >= 1048576 ? "M" : val >= 1024 ? "k" : "";
|
||||
unit = num >= 1125899906842624 ? "P" \
|
||||
: num >= 1099511627776 ? "T" \
|
||||
: num >= 1073741824 ? "G" \
|
||||
: num >= 1048576 ? "M" \
|
||||
: num >= 1024 ? "k" \
|
||||
: "";
|
||||
|
||||
while ( int(val) && !(val % 1024) ) {
|
||||
val /= 1024;
|
||||
while ( num >= div ) {
|
||||
num /= div;
|
||||
}
|
||||
|
||||
while ( val > 1000 ) {
|
||||
val /= div;
|
||||
}
|
||||
|
||||
printf "%.*f%s", prec, val, unit;
|
||||
printf "%.*f%s", prec, num, unit;
|
||||
}
|
||||
'
|
||||
}
|
||||
|
@@ -82,7 +82,6 @@ name_val () {
|
||||
|
||||
# Sub: shorten
|
||||
# Shorten a value in bytes to another representation.
|
||||
#
|
||||
shorten() {
|
||||
local num="$1"
|
||||
local prec="${2:-2}"
|
||||
@@ -90,20 +89,20 @@ shorten() {
|
||||
|
||||
echo "$num" | awk -v prec="$prec" -v div="$div" '
|
||||
{
|
||||
size = 4;
|
||||
val = $1;
|
||||
num = $1;
|
||||
|
||||
unit = val >= 1099511627776 ? "T" : val >= 1073741824 ? "G" : val >= 1048576 ? "M" : val >= 1024 ? "k" : "";
|
||||
unit = num >= 1125899906842624 ? "P" \
|
||||
: num >= 1099511627776 ? "T" \
|
||||
: num >= 1073741824 ? "G" \
|
||||
: num >= 1048576 ? "M" \
|
||||
: num >= 1024 ? "k" \
|
||||
: "";
|
||||
|
||||
while ( int(val) && !(val % 1024) ) {
|
||||
val /= 1024;
|
||||
while ( num >= div ) {
|
||||
num /= div;
|
||||
}
|
||||
|
||||
while ( val > 1000 ) {
|
||||
val /= div;
|
||||
}
|
||||
|
||||
printf "%.*f%s", prec, val, unit;
|
||||
printf "%.*f%s", prec, num, unit;
|
||||
}
|
||||
'
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
plan 19
|
||||
plan 20
|
||||
|
||||
. "$LIB_DIR/report_formatting.sh"
|
||||
|
||||
@@ -12,12 +12,12 @@ is \
|
||||
is \
|
||||
"$(shorten 3145728000 1)" \
|
||||
"2.9G" \
|
||||
"10485760, 1 precision, default divisor => 2.9G"
|
||||
"3145728000, 1 precision, default divisor => 2.9G"
|
||||
|
||||
is \
|
||||
"$(shorten 3145728000 1 1000)" \
|
||||
"3.0G" \
|
||||
"Opt-in to the 2.1 behavior works"
|
||||
"3.1G" \
|
||||
"3145728000, 1 precision, divisor 1000 => 3.1G"
|
||||
|
||||
is \
|
||||
"$(shorten 0 0)" \
|
||||
@@ -31,8 +31,8 @@ is \
|
||||
|
||||
is \
|
||||
"$(shorten 1572864000 1 1000)" \
|
||||
"1.5G" \
|
||||
"1572864000, 1 precision, divisor 1000 => 1.5G"
|
||||
"1.6G" \
|
||||
"1572864000, 1 precision, divisor 1000 => 1.6G"
|
||||
|
||||
is \
|
||||
"$(shorten 364 0)" \
|
||||
@@ -59,6 +59,10 @@ is \
|
||||
"6.5T" \
|
||||
"6492100000006, 1 precision, divisor 1000 => 6.5T"
|
||||
|
||||
is "$(shorten 1059586048 1)" \
|
||||
"1010.5M" \
|
||||
"1059586048 => 1010.5M (bug 993436)"
|
||||
|
||||
# section
|
||||
|
||||
is \
|
||||
@@ -74,7 +78,7 @@ is \
|
||||
is \
|
||||
"$(section "A_B_C")" \
|
||||
"# A#B#C#######################################################" \
|
||||
"..but it does replace everything after and including the first underscore with #s"
|
||||
"replace everything after and including first underscore with #s"
|
||||
|
||||
# name_val
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
plan 48
|
||||
plan 49
|
||||
|
||||
. "$LIB_DIR/alt_cmds.sh"
|
||||
. "$LIB_DIR/log_warn_die.sh"
|
||||
@@ -827,6 +827,18 @@ EOF
|
||||
parse_free_minus_b "$TMPDIR/in" > "$TMPDIR/got"
|
||||
no_diff "$TMPDIR/got" "$TMPDIR/expected" "parse_free_minus_b"
|
||||
|
||||
# Bug 993436: Memory: Total reports M when it should say G
|
||||
cat <<EOF > "$TMPDIR/expected"
|
||||
Total | 1010.5M
|
||||
Free | 784.4M
|
||||
Used | physical = 226.1M, swap allocated = 2.0G, swap used = 0.0, virtual = 226.1M
|
||||
Buffers | 48.8M
|
||||
Caches | 122.2M
|
||||
Dirty | 152 kB
|
||||
EOF
|
||||
parse_free_minus_b "$T_DIR/pt-summary/samples/Linux/002/memory" > "$TMPDIR/got"
|
||||
no_diff "$TMPDIR/got" "$TMPDIR/expected" "parse_free_minus_b (bug 993436)"
|
||||
|
||||
# parse_filesystems
|
||||
|
||||
cat <<EOF > $TMPDIR/expected
|
||||
|
@@ -14,7 +14,7 @@ Architecture | CPU = 32-bit, OS = 32-bit
|
||||
Models | 1xQEMU Virtual CPU version 0.14.1
|
||||
Caches | 1x4096 KB
|
||||
# Memory #####################################################
|
||||
Total | 1.0M
|
||||
Total | 1010.5M
|
||||
Free | 784.4M
|
||||
Used | physical = 226.1M, swap allocated = 2.0G, swap used = 0.0, virtual = 226.1M
|
||||
Buffers | 48.8M
|
||||
|
@@ -14,7 +14,7 @@ Architecture | CPU = 32-bit, OS = 32-bit
|
||||
Models | 1xQEMU Virtual CPU version 0.14.1
|
||||
Caches | 1x4096 KB
|
||||
# Memory #####################################################
|
||||
Total | 1.0M
|
||||
Total | 1010.5M
|
||||
Free | 784.7M
|
||||
Used | physical = 225.8M, swap allocated = 2.0G, swap used = 0.0, virtual = 225.8M
|
||||
Buffers | 48.8M
|
||||
|
@@ -32,6 +32,7 @@ cd "$cwd"
|
||||
|
||||
BIN_DIR="$BRANCH/bin";
|
||||
LIB_DIR="$BRANCH/lib/bash";
|
||||
T_DIR="$BRANCH/t";
|
||||
T_LIB_DIR="$BRANCH/t/lib";
|
||||
SANDBOX_VERSION="$($BRANCH/sandbox/test-env version)"
|
||||
|
||||
|
Reference in New Issue
Block a user