2 # Report generation for iokit-plot-sgpdd
3 # ======================================
4 # The iokit-plot-sgpdd script is used to generate csv file and
5 # instructions files for gnuplot from the output of sgpdd-survey script.
7 # iokit-plot-sgpdd also creates .scr file that contains instructions
8 # for gnuplot to plot the graph. After generating .dat and .scr files this
9 # script invokes gnuplot to display graph.
12 # $ sgpdd-survey > log_filename
13 # $ iokit-plot-sgpdd <log_filename>
14 # [Note: 1. This script may need modifications whenever there will be
15 # modifications in output format of sgpdd-survey script.
16 # 2. Gnuplot version 4.0 or above is required.]
20 print STDERR "Usage: $0 [options] <log_filename>\n";
21 print STDERR " $0 parses and plots graphs from the output of sgpdd-survey\n";
22 print STDERR " It generates text data files (.dat) and graphs (.png) using gnuplot.\n";
23 print STDERR "options:\n";
24 print STDERR " --rt: Subtitle for read graphs\n";
25 print STDERR " --wt: Subtitle for write graphs\n";
26 print STDERR " --y: Y-axis scale\n";
27 print STDERR "e.g. # $0 --rt=\"no prefetch\" --wt=\"WB disabled\" --y=500 sgpdd.summary\n";
31 # check whether gnuplot exists?
32 system ("which gnuplot > /dev/null") == 0 or die "gnuplot does not exist, please install it and try again.\n";
34 # check whether gnuplot supports png
35 $pngsupport = "ldd `which gnuplot` | grep -q libpng";
36 system ("$pngsupport") == 0 or die "gnuplot installed does not support PNG.
37 Please install gnuplot to support PNG and try again.\n";
41 #Subroutine to write .scr file that further used by gnuplot to plot the graph.
42 sub write_scr_file() {
45 print "generating plot $file-$rsz-$op.png\n";
46 open ( SCRFILE, "> $file-$rsz-$op.scr" ) or die "Can't open scr file for writing";
48 if ($opt_rdtitle || $opt_wrtitle) {
50 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, " .
51 "Rsize = $rsz, $lun LUNs, $opt_rdtitle\"\n";
54 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, " .
55 "Rsize = $rsz, $lun LUNs, $opt_wrtitle\"\n";
58 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, " .
59 "Rsize = $rsz, $lun LUNs\"\n";
61 print SCRFILE "set xlabel \"Threads/LUN\"\n";
62 print SCRFILE "set ylabel \"Throughput (MiB/s)\"\n";
63 print SCRFILE "set logscale x\n";
64 print SCRFILE "set grid\n";
65 print SCRFILE "set key right bottom\n";
66 print SCRFILE "set terminal png\n";
67 print SCRFILE "set output \"/dev/null\"\n";
69 print SCRFILE "set yrange [ 0:$opt_y ]\n";
71 print SCRFILE "set yrange [ 0: ]\n";
77 # generate instructions for gnuplot, with adjusting X-axes ranges
78 for ($j = $first_crg; $j <= $crg ; $j = $j + $j) {
80 printf SCRFILE "$plot \"$file-$rsz-$op.dat\" " .
81 "using 1:$i:xticlabels(1) axes x%dy1 " .
82 "title \"$tmp crg/LUN\" " .
83 "with linespoints lw 2\n", $xrange;
87 print SCRFILE "set output \"$file-$rsz-$op.png\"\n";
88 print SCRFILE "replot\n";
90 # invoke gnuplot to display graph.
91 system ("gnuplot $file-$rsz-$op.scr") == 0 or die "ERROR: while ploting graph";
92 system ("rm $file-$rsz-$op.scr");
96 #Subroutine to write .dat file that further used by gnuplot to plot the graph.
97 sub write_dat_file() {
99 print "writing data $file-$rsz-$op.dat\n";
100 # Open .csv/.dat file for writing required columns from log file.
101 my $datafile = "$file-$rsz-$op.dat";
102 open ( DATAFILE, "> $datafile" ) or die "Can't open csv $datafile for writing";
103 printf DATAFILE "%-6s", "thrd";
104 for ($j = $first_crg; $j <= $crg ; $j = $j + $j) {
106 printf DATAFILE "%-10s", "$tmp-crg";
108 for ( $i = $first_thread; $i <= $thread; $i = $i + $i ) {
109 printf DATAFILE "\n%-6s", $i/$lun;
110 for ($j = $first_crg; $j <= $crg ; $j = $j + $j) {
112 if ( $ard{$i}{$j} ) {
113 printf DATAFILE "%-10s", $ard{$i}{$j};
115 printf DATAFILE "%-10s", "-";
117 } elsif ($op eq "wr" ) {
118 if ( $awr{$i}{$j} ) {
119 printf DATAFILE "%-10s", $awr{$i}{$j};
121 printf DATAFILE "%-10s", "-";
129 #Subroutine to call .scr and .dat file write routines.
131 for ($cnt = 0; $cnt < @operations; $cnt = $cnt + 1) {
132 if($operations[$cnt] eq "read") {
133 &write_dat_file("rd");
134 &write_scr_file("rd", "read");
135 } elsif ($operations[$cnt] eq "write") {
136 &write_dat_file("wr");
137 &write_scr_file("wr", "write");
156 # Command line parameter parsing
158 GetOptions ('help' => \$opt_help, 'rt=s' => \$opt_rdtitle, 'wt=s' => \$opt_wrtitle, 'y=i' => \$opt_y) or usage();
164 open ( PFILE, "$file") or die "Can't open $file";
165 LABEL: while ( <PFILE> ) {
167 # replace error strings to ensure same ordering of line fields
168 s/failed/failed . . . . ./g;
169 @line = split( /\s+/ );
171 @GraphTitle = @line[0 .. 6];
176 # dev 1 sz 1048576K rsz 1024K crg 1 thr 8 write 604.55 [ 606.43, 606.43] read 754.02 [ 756.95, 756.95]
179 print "invalid file format at line $count\n";
183 if ($line[10] eq "ENOMEM") {
187 if (!$rsz || $rsz ne $line[5]) {
188 &write_files() unless !$rsz;
192 $first_crg = $line[7];
193 $first_thread = $line[9];
194 for ($i = 10; $i <= $linelen; $i = $i + 5) {
196 $operations[$cnt] = $line[$i];
201 for ($i = 0; $i < @operations; $i++) {
202 if ($operations[$i] eq "read") {
203 $ard{$line[9]}{$line[7]} = $line[$i * 5 + 11];
204 } elsif ($operations[$i] eq "write") {
205 $awr{$line[9]}{$line[7]} = $line[$i * 5 + 11];
208 if ( $crg < $line[7] ) {
211 if ( $thread < $line[9] ) {
217 if ($count > 1 && $rsz) {
220 print "Invalid log file format\n";