Rework fio_generate_plots script
[fio.git] / fio_generate_plots
index 611f49fc0eec2e812a4df79c181d595820986286..f65a326c87f52e6647a90988ade23ea092850da0 100755 (executable)
-#! /bin/sh
-
-# Use gnuplot to generate plots from fio run with -l and/or -w
-
-if [ "$1"x = "x" ]; then
-       echo Need title as arg
+#!/bin/sh
+#
+# This script is an almost total rewrite by Louwrentius 
+# of the original fio_generate_plots script provided as part of the FIO storage
+# benchmark utiliy. I only retained how GNUplot is used to generate graphs, as
+# that is something I know nothing about.
+#
+# The script uses the files generated by FIO to create nice graphs in the
+# SVG format. This output format is supported by most modern browsers and
+# allows resolution independant graphs to be generated.
+#
+# This script supports GNUPLOT 4.4 and higher.
+# 
+# Version 1.0 @ 20121231
+#
+# 
+#
+
+if [ -z "$1" ]; then
+       echo "Usage: fio_generate_plots subtitle [xres yres]"
        exit 1
 fi
 
 GNUPLOT=$(which gnuplot)
-if [ ! -x $GNUPLOT ]; then
+if [ ! -x $GNUPLOT ]
+then
        echo You need gnuplot installed to generate graphs
        exit 1
 fi
 
-TITLE=$1
-
-PLOT_LINE=""
-for i in *bw.log; do
-       if [ ! -r $i ]; then
-               continue
-       fi
-       PT=$(echo $i | sed s/_bw.log//g)
-       if [ "$PLOT_LINE"x != "x" ]; then
-               PLOT_LINE=$PLOT_LINE", "
-       fi
-
-       PLOT_LINE=$PLOT_LINE"'$i' title '$PT' with lines"
-done
+TITLE="$1"
 
-if [ "$PLOT_LINE"x != "x" ]; then
-       echo Making bw logs
-       echo "set title 'Bandwidth - $TITLE'; set xlabel 'time (msec)'; set ylabel 'KB/sec'; set terminal png; set output '$TITLE-bw.png'; plot " $PLOT_LINE | $GNUPLOT -
+# set resolution
+if [ ! -z "$2" ] && [ ! -z "$3" ]
+then
+       XRES="$2"
+       YRES="$3"
+else
+       XRES=1280
+       YRES=768
 fi
 
-PLOT_LINE=""
-for i in *slat.log; do
-       if [ ! -r $i ]; then
-               continue
-       fi
-       PT=$(echo $i | sed s/_slat.log//g)
-       if [ "$PLOT_LINE"x != "x" ]; then
-               PLOT_LINE=$PLOT_LINE", "
-       fi
-
-       PLOT_LINE=$PLOT_LINE"'$i' title '$PT' with lines"
-done
-
-if [ "$PLOT_LINE"x != "x" ]; then
-       echo Making slat logs $PLOT_LINE
-       echo "set title 'Submission latency - $TITLE'; set xlabel 'time (msec)'; set ylabel 'latency (msec)'; set terminal png; set output '$TITLE-slat.png'; plot " $PLOT_LINE | $GNUPLOT -
+if [ -z "$SAMPLE_DURATION" ]
+then
+    SAMPLE_DURATION="*"
 fi
 
-PLOT_LINE=""
-for i in *clat.log; do
-       if [ ! -r $i ]; then
-               continue
-       fi
-       PT=$(echo $i | sed s/_clat.log//g)
-       if [ "$PLOT_LINE"x != "x" ]; then
-               PLOT_LINE=$PLOT_LINE", "
-       fi
-
-       PLOT_LINE=$PLOT_LINE"'$i' title '$PT' with lines"
-done
-
-if [ "$PLOT_LINE"x != "x" ]; then
-       echo Making clat logs $PLOT_LINE
-       echo "set title 'Completion latency - $TITLE'; set xlabel 'time (msec)'; set ylabel 'latency (msec)'; set terminal png; set output '$TITLE-clat.png'; plot " $PLOT_LINE | $GNUPLOT -
-fi
+DEFAULT_GRID_LINE_TYPE=3
+DEFAULT_LINE_WIDTH=2
+DEFAULT_LINE_COLORS="
+set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb\"#ffffff\" behind 
+set style line 1 lc rgb \"#E41A1C\" lw $DEFAULT_LINE_WIDTH lt 1;
+set style line 2 lc rgb \"#377EB8\" lw $DEFAULT_LINE_WIDTH lt 1;
+set style line 3 lc rgb \"#4DAF4A\" lw $DEFAULT_LINE_WIDTH lt 1;
+set style line 4 lc rgb \"#984EA3\" lw $DEFAULT_LINE_WIDTH lt 1;
+set style line 5 lc rgb \"#FF7F00\" lw $DEFAULT_LINE_WIDTH lt 1;
+set style line 6 lc rgb \"#DADA33\" lw $DEFAULT_LINE_WIDTH lt 1;
+set style line 7 lc rgb \"#A65628\" lw $DEFAULT_LINE_WIDTH lt 1;
+set style line 20 lc rgb \"#000000\" lt $DEFAULT_GRID_LINE_TYPE lw $DEFAULT_LINE_WIDTH;
+"
+
+DEFAULT_TERMINAL="set terminal svg enhanced dashed size $XRES,$YRES dynamic"
+DEFAULT_TITLE_FONT="\"Helvetica,28\""
+DEFAULT_AXIS_FONT="\"Helvetica,14\""
+DEFAULT_AXIS_LABEL_FONT="\"Helvetica,16\""
+DEFAULT_XLABEL="set xlabel \"Time (sec)\" font $DEFAULT_AXIS_LABEL_FONT"
+DEFAULT_XTIC="set xtics font $DEFAULT_AXIS_FONT"
+DEFAULT_YTIC="set ytics font $DEFAULT_AXIS_FONT"
+DEFAULT_MXTIC="set mxtics 0"
+DEFAULT_MYTIC="set mytics 2"
+DEFAULT_XRANGE="set xrange [0:$SAMPLE_DURATION]"
+DEFAULT_YRANGE="set yrange [0:*]"
+DEFAULT_GRID="set grid ls 20"
+DEFAULT_KEY="set key outside bottom center ; set key box enhanced spacing 2.0 samplen 3 horizontal width 4 height 1.2 "
+DEFAULT_SOURCE="set label 30 \"Data source: http://example.com\" font $DEFAULT_AXIS_FONT tc rgb \"#00000f\" at screen 0.976,0.175 right"
+DEFAULT_OPTS="$DEFAULT_LINE_COLORS ; $DEFAULT_GRID_LINE ; $DEFAULT_GRID ; $DEFAULT_GRID_MINOR ; $DEFAULT_XLABEL ; $DEFAULT_XRANGE ; $DEFAULT_YRANGE ; $DEFAULT_XTIC ;  $DEFAULT_YTIC ; $DEFAULT_MXTIC ; $DEFAULT_MYTIC ; $DEFAULT_KEY ; $DEFAULT_TERMINAL ; $DEFAULT_SOURCE"
+
+plot () {
+    
+    if [ -z "$TITLE" ]
+    then       
+        PLOT_TITLE=" set title \"$1\" font $DEFAULT_TITLE_FONT"
+    else
+        PLOT_TITLE=" set title \"$TITLE\\\n\\\n{/*0.6 "$1"}\" font $DEFAULT_TITLE_FONT"
+    fi
+    FILETYPE="$2"
+    YAXIS="set ylabel \"$3\" font $DEFAULT_AXIS_LABEL_FONT"
+    SCALE=$4
+
+    echo "Title: $PLOT_TITLE"
+    echo "File type: $FILETYPE"
+    echo "yaxis: $YAXIS"
+
+    i=0
+    
+    for x in *_"$FILETYPE".log
+    do
+        i=$((i+1))
+        PT=$(echo $x | sed s/_"$FILETYPE".log//g)
+        if [ ! -z "$PLOT_LINE" ]
+        then
+            PLOT_LINE=$PLOT_LINE", "
+        fi
+
+        DEPTH=$(echo $PT | cut -d "-" -f 4)
+           PLOT_LINE=$PLOT_LINE"'$x' using (\$1/1000):(\$2/$SCALE) title \"Queue depth $DEPTH\" with lines ls $i" 
+        
+    done
+
+    OUTPUT="set output \"$TITLE-$FILETYPE.svg\" "
+
+    echo " $PLOT_TITLE ; $YAXIS ; $DEFAULT_OPTS ; show style lines ; $OUTPUT ; plot "  $PLOT_LINE  | $GNUPLOT -
+    unset PLOT_LINE
+}
+
+#
+# plot <sub title> <file name tag> <y axis label> <y axis scale>
+#
+
+plot "I/O Latency" lat "Time (msec)" 1000
+plot "I/O Operations Per Second" iops "IOPS" 1
+plot "I/O Submission Latency" slat "Time (μsec)" 1
+plot "I/O Completion Latency" clat "Time (msec)" 1000
+plot "I/O Bandwidth" bw "Throughput (KB/s)" 1
+
 
-PLOT_LINE=""
-for i in *_lat.log; do
-       if [ ! -r $i ]; then
-               continue
-       fi
-       PT=$(echo $i | sed s/_lat.log//g)
-       if [ "$PLOT_LINE"x != "x" ]; then
-               PLOT_LINE=$PLOT_LINE", "
-       fi
-
-       PLOT_LINE=$PLOT_LINE"'$i' title '$PT' with lines"
-done
-
-if [ "$PLOT_LINE"x != "x" ]; then
-       echo Making lat logs $PLOT_LINE
-       echo "set title 'Latency - $TITLE'; set xlabel 'time (msec)'; set ylabel 'latency (msec)'; set terminal png; set output '$TITLE-lat.png'; plot " $PLOT_LINE | $GNUPLOT -
-fi