Whamcloud - gitweb
LU-9514 test: sanity 51f add to ALWAYS_EXCEPT
[fs/lustre-release.git] / lustre-iokit / sgpdd-survey / iokit-plot-sgpdd
1 #!/usr/bin/perl -w
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.
6 #
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.
10 #
11 # Syntax:
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.]
17
18 sub usage()
19 {
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";
28         exit 1;
29 }
30
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";
33
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";
38
39 my @GraphTitle;
40
41 #Subroutine to write .scr file that further used by gnuplot to plot the graph.
42 sub write_scr_file() {
43         my $op = $_[0];
44         my $rwlabel = $_[1];
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";
47
48         if ($opt_rdtitle || $opt_wrtitle) {
49                 if ($op eq "rd") {
50                         print SCRFILE "set title \"@GraphTitle\\n$rwlabel, " .
51                                       "Rsize = $rsz, $lun LUNs, $opt_rdtitle\"\n";
52                 }
53                 if ($op eq "wr") {
54                         print SCRFILE "set title \"@GraphTitle\\n$rwlabel, " .
55                                       "Rsize = $rsz, $lun LUNs, $opt_wrtitle\"\n";
56                 }
57         } else {
58                 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, " .
59                               "Rsize = $rsz, $lun LUNs\"\n";
60         }
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";
68         if ($opt_y != 0) {
69                 print SCRFILE "set yrange [ 0:$opt_y ]\n";
70         } else {
71                 print SCRFILE "set yrange [ 0: ]\n";
72         }
73
74         my $plot = "plot";
75         $i = 2;
76         $xrange = 1;
77         # generate instructions for gnuplot, with adjusting X-axes ranges
78         for ($j = $first_crg; $j <= $crg ; $j = $j + $j) {
79                 $tmp=$j/$lun;
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;
84                 $i++;
85                 $plot = "replot";
86         }
87         print SCRFILE "set output \"$file-$rsz-$op.png\"\n";
88         print SCRFILE "replot\n";
89         close SCRFILE;
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");
93 }
94
95
96 #Subroutine to write .dat file that further used by gnuplot to plot the graph.
97 sub write_dat_file() {
98         my $op = $_[0];
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) {
105                 $tmp = $j/$lun;
106                 printf DATAFILE "%-10s", "$tmp-crg";
107         }
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) {
111                         if ($op eq "rd") {
112                                 if ( $ard{$i}{$j} ) {
113                                         printf DATAFILE "%-10s", $ard{$i}{$j};
114                                 } else {
115                                         printf DATAFILE "%-10s", "-";
116                                 }
117                         } elsif ($op eq "wr" ) {
118                                 if ( $awr{$i}{$j} ) {
119                                         printf DATAFILE "%-10s", $awr{$i}{$j};
120                                 } else {
121                                         printf DATAFILE "%-10s", "-";
122                                 }
123                         }
124                 }
125         }
126         close DATAFILE;
127 }
128
129 #Subroutine to call .scr and .dat file write routines.
130 sub write_files() {
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");
138                 }
139         }
140 }
141
142 if ( !$ARGV[0] ) {
143         usage();
144 }
145 $crg = 0;
146 $thread = 0;
147 $first_crg = 1;
148 $first_thread = 1;
149 $count = 0;
150 $rsz = 0;
151 $opt_rdtitle = "";
152 $opt_wrtitle = "";
153 $opt_y = 0;
154 $cnt = 0;
155 @operations = ();
156 # Command line parameter parsing
157 use Getopt::Long;
158 GetOptions ('help' => \$opt_help, 'rt=s' => \$opt_rdtitle, 'wt=s' => \$opt_wrtitle, 'y=i' => \$opt_y) or usage();
159 if ($opt_help) {
160         usage();
161 }
162 $file = $ARGV[0];
163
164 open ( PFILE, "$file") or die "Can't open $file";
165 LABEL: while ( <PFILE> ) {
166         chomp;
167         # replace error strings to ensure same ordering of line fields
168         s/failed/failed . . . . ./g;
169         @line = split( /\s+/ );
170         if ($count == 0) {
171                 @GraphTitle = @line[0 .. 6];
172                 $count++;
173                 next LABEL;
174         }
175         # output format
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]
177         $linelen = @line;
178         if ($linelen < 11) {
179                 print "invalid file format at line $count\n";
180                 exit 1;
181         }
182         if ($line[10]) {
183                 if ($line[10] eq "ENOMEM") {
184                         next LABEL;
185                 }
186         }
187         if (!$rsz || $rsz ne $line[5]) {
188                 &write_files() unless !$rsz;
189                 $cnt = 0;
190                 $lun = $line[1];
191                 $rsz = $line[5];
192                 $first_crg = $line[7];
193                 $first_thread = $line[9];
194                 for ($i = 10; $i <= $linelen; $i = $i + 5) {
195                         if ($line[$i]) {
196                                 $operations[$cnt] = $line[$i];
197                                 $cnt++;
198                         }
199                 }
200         }
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];
206                 }
207         }
208         if ( $crg < $line[7] ) {
209                 $crg = $line[7];
210         }
211         if ( $thread < $line[9] ) {
212                 $thread = $line[9];
213         }
214         $count++;
215 }
216 close PFILE;
217 if ($count > 1 && $rsz) {
218         &write_files()
219 } else {
220         print "Invalid log file format\n";
221 }