2 # SPDX-License-Identifier: GPL-2.0-only
4 # Sergey Senozhatsky, 2015
5 # sergey.senozhatsky.work@gmail.com
9 # This program is intended to plot a `slabinfo -X' stats, collected,
10 # for example, using the following command:
11 # while [ 1 ]; do slabinfo -X >> stats; sleep 1; done
13 # Use `slabinfo-gnuplot.sh stats' to pre-process collected records
14 # and generate graphs (totals, slabs sorted by size, slabs sorted
17 # Graphs can be [individually] regenerate with different ranges and
18 # size (-r %d,%d and -s %d,%d options).
20 # To visually compare N `totals' graphs, do
21 # slabinfo-gnuplot.sh -t FILE1-totals FILE2-totals ... FILEN-totals
33 echo "Usage: [-s W,H] [-r MIN,MAX] [-t|-l] FILE1 [FILE2 ..]"
34 echo "FILEs must contain 'slabinfo -X' samples"
35 echo "-t - plot totals for FILE(s)"
36 echo "-l - plot slabs stats for FILE(s)"
37 echo "-s %d,%d - set image width and height"
38 echo "-r %d,%d - use data samples from a given range"
43 if [ ! -f "$1" ]; then
44 echo "File '$1' does not exist"
53 local range
="every ::$xmin"
55 local xtic_rotate
="norotate"
59 check_file_exist
"$file"
61 out_file
=`basename "$file"`
62 if [ $xmax -ne 0 ]; then
67 wc_lines
=`cat "$file" | wc -l`
68 if [ $?
-ne 0 ] ||
[ "$wc_lines" -eq 0 ] ; then
72 if [ "$wc_lines" -lt "$lines" ]; then
76 if [ $
((width
/ lines
)) -gt $min_slab_name_size ]; then
82 #!/usr/bin/env gnuplot
84 set terminal png enhanced size $width,$height large
85 set output '$out_file.png'
89 set style histogram columnstacked title textcolor lt -1
90 set style fill solid 0.15
91 set xtics rotate $xtic_rotate
92 set key left above Left title reverse
94 plot "$file" $range u 2$xtic title 'SIZE' with boxes,\
95 '' $range u 3 title 'LOSS' with boxes
106 local range
="every ::$xmin"
109 if [ $xmax -ne 0 ]; then
110 range
="$range::$xmax"
113 for i
in "${t_files[@]}"; do
114 check_file_exist
"$i"
116 file="$file"`basename "$i"`
117 gnuplot_cmd
="$gnuplot_cmd '$i' $range using 1 title\
118 '$i Memory usage' with lines,"
119 gnuplot_cmd
="$gnuplot_cmd '' $range using 2 title \
120 '$i Loss' with lines,"
124 #!/usr/bin/env gnuplot
126 set terminal png enhanced size $width,$height large
128 set output '$file.png'
131 set key left above Left title reverse
136 if [ $?
-eq 0 ]; then
147 check_file_exist
"$in"
149 # use only 'TOP' slab (biggest memory usage or loss)
151 out
=`basename "$in"`"-slabs-by-loss"
152 `cat "$in" | grep -A "$lines" 'Slabs sorted by loss' |\
153 egrep -iv '\-\-|Name|Slabs'\
154 | awk '{print $1" "$4+$2*$3" "$4}' > "$out"`
155 if [ $?
-eq 0 ]; then
156 do_slabs_plotting
"$out"
160 out
=`basename "$in"`"-slabs-by-size"
161 `cat "$in" | grep -A "$lines" 'Slabs sorted by size' |\
162 egrep -iv '\-\-|Name|Slabs'\
163 | awk '{print $1" "$4" "$4-$2*$3}' > "$out"`
164 if [ $?
-eq 0 ]; then
165 do_slabs_plotting
"$out"
168 out
=`basename "$in"`"-totals"
169 `cat "$in" | grep "Memory used" |\
170 awk '{print $3" "$7}' > "$out"`
171 if [ $?
-eq 0 ]; then
181 while getopts "tlr::s::h" opt
; do
190 array
=(${OPTARG//,/ })
195 array
=(${OPTARG//,/ })
204 echo "Invalid option: -$OPTARG" >&2
208 echo "-$OPTARG requires an argument." >&2
242 parse_args
"${@:$argstart}"
244 if [ ${#files[@]} -eq 0 ] && [ ${#t_files[@]} -eq 0 ]; then
251 for i
in "${files[@]}"; do
259 for i
in "${files[@]}"; do
260 do_slabs_plotting
"$i"
264 echo "Unknown mode $mode" >&2