Skip to content

Commit 0035f83

Browse files
authored
Add divby0 checks, eliminate cat pipe
1 parent cb3496d commit 0035f83

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

fio/fio_run

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ report_info()
260260
obtain_avg()
261261
{
262262
FIELD=${1}
263-
value=`cat fio-results.json | jq '.. | select(type == "object" and has('\"$FIELD\"')).'\"$FIELD\"''`
263+
value=`jq '.. | select(type == "object" and has('\"$FIELD\"')).'\"$FIELD\"'' fio-results.json`
264264
nitems=0
265265
calc="scale=2;("
266266
field_separ=""
@@ -269,9 +269,13 @@ obtain_avg()
269269
let "nitems=$nitems+1"
270270
field_separ="+"
271271
done
272-
# Divide by 3 since the json output includes all three I/O types and we only care about one
273-
calc="${calc})/(${nitems}/3)"
274-
rtval=`echo $calc | bc`
272+
if [ ${nitems} -eq 0]; then
273+
calc=0
274+
else
275+
# Divide by 3 since the json output includes all three I/O types and we only care about one
276+
calc="${calc})/(${nitems}/3)"
277+
fi
278+
rtval=`echo $calc | bc`
275279
echo $rtval
276280
}
277281

@@ -281,7 +285,7 @@ obtain_avg()
281285
obtain_avg_lat()
282286
{
283287
FIELD=${1}
284-
value=`cat fio-results.json | jq '.. | select(type == "object" and has('\"$FIELD\"')).'\"$FIELD\"'.mean'`
288+
value=`jq '.. | select(type == "object" and has('\"$FIELD\"')).'\"$FIELD\"'.mean' fio-results.json`
285289
nitems=0
286290
calc="scale=2;("
287291
field_separ=""
@@ -290,9 +294,13 @@ obtain_avg_lat()
290294
let "nitems=$nitems+1"
291295
field_separ="+"
292296
done
293-
# Divide by 3 since the json output includes all three I/O types and we only care about one
294-
# Divide by 1000 because the json output is nsec but usec is a bit more friendly for now
295-
calc="${calc})/(${nitems}/3)/1000"
297+
if [ ${nitems} -eq 0]; then
298+
calc=0
299+
else
300+
# Divide by 3 since the json output includes all three I/O types and we only care about one
301+
# Divide by 1000 because the json output is nsec but usec is a bit more friendly for now
302+
calc="${calc})/(${nitems}/3)/1000"
303+
fi
296304
rtval=`echo $calc | bc`
297305
echo $rtval
298306
}

0 commit comments

Comments
 (0)