]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
Added a latency capture tool
authorStephen Bates <sbates@raithlin.com>
Tue, 10 Feb 2015 16:54:03 +0000 (09:54 -0700)
committerStephen Bates <sbates@raithlin.com>
Tue, 10 Feb 2015 16:54:03 +0000 (09:54 -0700)
Added a simple shell script that calls nvme read or nme write a number
of times and captures latency information for post-processing. Later
we will run this over random LBAs on the drive and probably move to a
tools sub-folder.

latency [new file with mode: 0755]

diff --git a/latency b/latency
new file mode 100755 (executable)
index 0000000..17835de
--- /dev/null
+++ b/latency
@@ -0,0 +1,96 @@
+#!/bin/bash
+#
+# Copyright 2015 PMC-Sierra, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you
+# may not use this file except in compliance with the License. You may
+# obtain a copy of the License at
+# http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+# applicable law or agreed to in writing, software distributed under the
+# License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+# CONDITIONS OF ANY KIND, either express or implied. See the License for
+# the specific language governing permissions and limitations under the
+# License.
+#
+#
+#   Author: Stephen Bates <stephen.bates@pmcs.com>
+#
+#   Description:
+#     A shell script that calls the NVMe CLI multiple times to gather
+#     latency data. Consider this a poor man's iometer or fio for QD=1
+#     analysis. Of course this is below the file-system and block
+#     layer so is a best case measurement.
+#
+
+DEVICE=
+WRITE=false
+COUNT=10
+DATA_SIZE=4096
+METADATA_SIZE=64
+
+RAND_BASE=temp.rand
+RAND_WFILE=${RAND_BASE}.write
+RAND_RFILE=${RAND_BASE}.read
+OUTPUT=latency.dat
+
+green=$(tput bold)$(tput setaf 2)
+red=$(tput bold)$(tput setaf 1)
+rst=$(tput sgr0)
+
+while getopts ":d:n:w" opt; do
+  case $opt in
+    d)
+      DEVICE=${OPTARG}
+      ;;
+    n)
+      COUNT=${OPTARG}
+      ;;
+    w)
+      echo "WARNING: Write mode enabled, this might trash your drive!"
+      WRITE=true
+      ;;
+    \?)
+      echo "Invalid option: -$OPTARG" >&2
+      exit 1
+      ;;
+    :)
+      echo "Option -$OPTARG requires an argument." >&2
+      exit 1
+      ;;
+  esac
+done
+
+if [ -z "$DEVICE" ]; then
+     echo "regress: You must specify a NVMe device using -d"
+     exit 1
+fi
+
+function run_test {
+    $* | grep -i latency >> ${OUTPUT} 2>&1
+    if (( $? )); then
+        echo ${red}"FAILED!"${rst}
+        echo "Failed running command: "
+        echo  "   $*"
+        exit 1
+    fi
+}
+
+rm ${OUTPUT} > /dev/null || exit -1
+make clean   > /dev/null || exit -1
+make install > /dev/null || exit -1
+
+for i in `seq 1 ${COUNT}`;
+do
+    if $WRITE ; then
+        run_test dd if=/dev/urandom of=${RAND_WFILE} bs=${DATA_SIZE} count=1
+        run_test nvme write ${DEVICE} --start-block=0 --block-count=0 \
+            --metadata-size=${METADATA_SIZE} --data-size=${DATA_SIZE} \
+            --data ${RAND_WFILE} --latency
+        rm ${RAND_WFILE} > /dev/null
+    else
+        run_test nvme read ${DEVICE} --start-block=0 --block-count=0 \
+            --metadata-size=${METADATA_SIZE} --data-size=${DATA_SIZE} \
+            --data ${RAND_RFILE} --latency
+        rm ${RAND_RFILE} > /dev/null
+    fi
+done