Skip to content

Commit 7431cc0

Browse files
committed
bitesize: work with different versions of awk and bash
This patch tries to fix following bitesize issues, 1. Error flooding messages when array index value is negative. 2. the smax in gawk was treated as string, that cause bug when perf return zero IO count. Signed-off-by: Yong Yang <[email protected]>
1 parent 85414b0 commit 7431cc0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

disk/bitesize

+7-3
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ sectors=(${buckets[*]})
8585
((max_i = ${#buckets[*]} - 1))
8686
while (( i <= max_i )); do
8787
(( sectors[$i] = ${sectors[$i]} * 1024 / $secsz ))
88-
if (( i && ${sectors[$i]} <= ${sectors[$i - 1]} )); then
89-
die "ERROR: bucket list must increase in size."
88+
# avoid negative array index errors for old version bash
89+
if (( i > 0 ));then
90+
if (( ${sectors[$i]} <= ${sectors[$i - 1]} )); then
91+
die "ERROR: bucket list must increase in size."
92+
fi
9093
fi
9194
(( i++ ))
9295
done
@@ -136,7 +139,8 @@ echo
136139
echo "$stat" | awk -v tpoint=$tpoint -v max_i=$max_i -v most=$most '
137140
function star(sval, smax, swidth) {
138141
stars = ""
139-
if (smax == 0) return ""
142+
# using int could avoid error on gawk
143+
if (int(smax) == 0) return ""
140144
for (si = 0; si < (swidth * sval / smax); si++) {
141145
stars = stars "#"
142146
}

0 commit comments

Comments
 (0)