Debian Codegraph @

gnuplotExample/make_percentile_plot

raw
1 #!/bin/sh
2 #
3 # * Written by Gil Tene of Azul Systems, and released to the public domain,
4 # * as explained at http://creativecommons.org/publicdomain/zero/1.0/
5 #
6 # This script uses gnuplot to plot the percentile distribution in the
7 # input files provided. run with "-h" option for an expected usage description.
8 #
9 # The script assumes the input files contain ".hgrm" formatted output such
10 # as the one provided by HdrHistogram. The 4th column in the input files is
11 # expected to be the value of 1/(1-percentile) (for a given percentile),
12 # and the 1st column in the input files is expected to be the value at the
13 # given percentile.
14 #
15
16 reading_SLA_NAME=0
17 reading_OUTPUT_NAME=0
18 helpFlagFound=0
19 SLA_NAME=
20 FILES=
21 OUTPUT_FILENAME=
22 reading_maxvalue=0
23 maxvalue=
24
25 for var in $@; do
26 if [ $reading_SLA_NAME -eq 1 ]; then
27 SLA_NAME=$var
28 reading_SLA_NAME=0
29 elif [ $reading_OUTPUT_NAME -eq 1 ]; then
30 OUTPUT_FILENAME=$var
31 reading_OUTPUT_NAME=0
32 elif [ $reading_maxvalue -eq 1 ]; then
33 maxvalue="set yrange [0:$var]"
34 reading_maxvalue=0
35 elif [ $var = "-h" ]; then
36 helpFlagFound=1
37 elif [ $var = "-o" ]; then
38 reading_OUTPUT_NAME=1
39 elif [ $var = "-s" ]; then
40 reading_SLA_NAME=1
41 elif [ $var = "-m" ]; then
42 reading_maxvalue=1
43 else
44 FILES="$FILES $var"
45 fi
46 done
47
48 message()
49 {
50 echo "$@" >&2
51 }
52
53 if [ $helpFlagFound -eq 1 ]; then
54 message "Usage: make_percentile_plot [-o output_file] [-s sla_file] histogram_file ..."
55 exit 255
56 fi
57
58 echo "1.0 0.0 0%" > ./xlabels.dat
59 echo "10.0 0.0 90%" >> ./xlabels.dat
60 echo "100.0 0.0 99%" >> ./xlabels.dat
61 echo "1000.0 0.0 99.9%" >> ./xlabels.dat
62 echo "10000.0 0.0 99.99%" >> ./xlabels.dat
63 echo "100000.0 0.0 99.999%" >> ./xlabels.dat
64 echo "1000000.0 0.0 99.9999%" >> ./xlabels.dat
65 echo "10000000.0 0.0 99.99999%" >> ./xlabels.dat
66
67 IndividualFilePlotCommands="'./xlabels.dat' with labels center offset 0, 1.5 point"
68 for file in $FILES; do
69 IndividualFilePlotCommands="$IndividualFilePlotCommands, '$file' using 4:1 with lines"
70 done
71
72 if [ $SLA_NAME ]; then
73 IndividualFilePlotCommands="$IndividualFilePlotCommands, '$SLA_NAME' with lines ls 1"
74 message plotting "{ " $FILES " }" with SLA $SLA_NAME
75 else
76 message plotting "{ " $FILES " }"
77 fi
78
79 message command will be:
80 message $IndividualFilePlotCommands
81
82 (
83 echo "#plot commands"
84 echo "set terminal png size 1280,720"
85 if [ $OUTPUT_FILENAME ]; then
86 echo "set output '$OUTPUT_FILENAME'"
87 fi
88 echo "set logscale x"
89 echo "unset xtics"
90 echo "$maxvalue"
91 echo "set key top left"
92 echo "set style line 1 lt 1 lw 3 pt 3 linecolor rgb \"red\""
93 echo "plot $IndividualFilePlotCommands"
94 ) | gnuplot
95