Skip to content

Instantly share code, notes, and snippets.

@postwait
Created July 20, 2018 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save postwait/e79ba94589dea94a71e06bcc3ebbaa3e to your computer and use it in GitHub Desktop.
Save postwait/e79ba94589dea94a71e06bcc3ebbaa3e to your computer and use it in GitHub Desktop.
#!/bin/bash
SECONDS=5
bail() {
echo "Error: $@"
exit 1
}
DIR=`mktemp -d`
cd $DIR || bail "temp directory failure"
DARGS=()
for disk in `ls /dev/sd*[^0-9]` ; do
DARGS+=('-d')
DARGS+=($disk)
done
shopt -s nullglob
maybe_comma() {
local V=`eval "echo "'$'"$1"`
if [[ $V -ne 0 ]]; then
echo -n ","
fi
eval "$1=1"
}
while true; do
blktrace -w $SECONDS -o auto ${DARGS[@]} 2>&1 > /dev/null
btt -i auto.blktrace.0 --q2c-latencies=lat --q2d-latencies=lat --d2c-latencies=lat 2>&1 > /dev/null
COMMA=0
echo -n "{"
for file in lat_*_q2c.dat; do
maybe_comma COMMA
DEV=`echo $file | sed -e 's/^lat_//' -e 's/_q2c.dat//' -e s'/[,:]/./g'`
echo -n "\"io_latency|ST[dev:$DEV]\":{\"_type\":\"n\",\"_value\":["
LISTC=0
for lat in `cat $file | awk '{ print $2; }'` ; do
maybe_comma LISTC
echo -n "$lat"
done
echo -n "]"
done
for file in lat_*_q2d.dat; do
maybe_comma COMMA
DEV=`echo $file | sed -e 's/^lat_//' -e 's/_q2d.dat//' -e s'/[,:]/./g'`
echo -n "\"io_latency_q2d|ST[dev:$DEV]\":{\"_type\":\"n\",\"_value\":["
LISTC=0
for lat in `cat $file | awk '{ print $2; }'` ; do
maybe_comma LISTC
echo -n "$lat"
done
echo -n "]"
done
for file in lat_*_d2c.dat; do
maybe_comma COMMA
DEV=`echo $file | sed -e 's/^lat_//' -e 's/_q2d.dat//' -e s'/[,:]/./g'`
echo -n "\"io_latency_d2c|ST[dev:$DEV]\":{\"_type\":\"n\",\"_value\":["
LISTC=0
for lat in `cat $file | awk '{ print $2; }'` ; do
maybe_comma LISTC
echo -n "$lat"
done
echo -n "]"
done
echo "}"
echo
rm -f *dat *.0
done
cd /
rm -rf $DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment