2 # Report generation for plot-sgpdd
3 # ================================
4 # The plot-sgpdd script is used to generate csv file and
5 # instructions files for gnuplot from the output of sgpdd-survey.pl script.
7 # The 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 # $ plot-sgpdd <log_filename>
14 # [Note: 1. This script may need modifications whenever there will be
15 # modifications in output format of sgpdd-survey.pl script.
16 # 2. Gnuplot version 4.0 or above is required.]
20 print "Usage: $0 <log_filename> [--rt=<read title>] [--wt=<write title>]\n";
21 print " The $0 parses and plots graph for output of sgpdd-survey.pl using gnuplot,\n";
22 print " it generates <log_filename>-<Rsize><rd/wr>.dat and <log_filename>-<Rsize>-<rd/wr>.scr files\n";
23 print " those will be used for graphing the results\n";
24 print "e.g. # perl $0 sgpdd-log \"8 devices, chunk = 256\"\n";
25 print " # gnuplot <log_filename>-<Rsize>.scr\n";
29 # check whether gnuplot exists?
30 system ("which gnuplot > /dev/null") == 0 or die "gnuplot does not exist, please install it and try again.\n";
32 #Subroutine to write .scr file that further used by gnuplot to plot the graph.
33 sub write_scr_file() {
35 print "generating plot $file-$rsz-$op.png\n";
36 open ( SCRFILE, "> $file-$rsz-$op.scr" ) or die "Can't open scr file for writing";
44 if ($opt_rdtitle || $opt_wrtitle) {
46 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz, $opt_rdtitle\"\n";
49 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz, $opt_wrtitle\"\n";
52 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz\"\n";
54 print SCRFILE "set xlabel \"Threads\"\n";
55 print SCRFILE "set ylabel \"Speeds(MB/s)\"\n";
56 print SCRFILE "set logscale x\n";
60 # generate instructions for gnuplot, with adjusting X-axes ranges
61 for ($j = 1; $j <= $thread ; $j = $j + $j) {
66 printf SCRFILE "$plot \"$file-$rsz-$op.dat\" using 1:$i axes x%dy1 title \"write$j\" with line\n", $xrange;
69 printf SCRFILE "$plot \"$file-$rsz-$op.dat\" using 1:$i axes x%dy1 title \"read$j\" with line\n", $xrange;
74 #print SCRFILE "set terminal png transparent\n";
75 print SCRFILE "set output \"$file-$rsz-$op.png\"\n";
76 print SCRFILE "replot\n";
78 # invoke gnuplot to display graph.
79 system ("gnuplot $file-$rsz-$op.scr") == 0 or die "ERROR: while ploting graph";
80 system ("rm $file-$rsz-$op.scr");
83 #Subroutine to write .dat file that further used by gnuplot to plot the graph.
84 sub write_dat_file() {
86 print "writing data $file-$rsz-$op.dat\n";
87 # Open .csv/.dat file for writing required columns from log file.
88 open ( DATAFILE, "> $file-$rsz-$op.dat" ) or die "Can't open csv file for writing";
89 printf DATAFILE "%-6s", "0";
90 for ($j = 1; $j <= $thread ; $j = $j + $j) {
91 printf DATAFILE "%-8s", "$op$j";
93 for ( $i = 1; $i <= $region; $i = $i + $i ) {
94 printf DATAFILE "\n%-6s", $i;
95 for ($j = 1; $j <= $thread ; $j = $j + $j) {
96 if (($op eq "rd" && $rdwr) || ($op eq "wr" && $wrrd) || ($readop) || ($writeop)) {
98 printf DATAFILE "%-8s", $out{$i}{$j};
100 printf DATAFILE "%-8s", "-";
103 if (($j <= 1 && $out{$i}{$j - 1})) {
104 printf DATAFILE "%-8s", $out{$i}{$j - 1};
105 }elsif ($out{$i}{$j + 1} && $j > 1) {
106 printf DATAFILE "%-8s", $out{$i}{$j + 1};
108 printf DATAFILE "%-8s", "-";
129 # Command line parameter parsing
131 GetOptions ('help' => \$opt_help, 'rt=s' => \$opt_rdtitle, 'wt=s' => \$opt_wrtitle) or usage();
135 open ( PFILE, "$file") or die "Can't open results";
136 LABEL: while ( <PFILE> ) {
138 @line = split( /\s+/ );
140 print "invalid file format\n";
149 if ($line[8] eq "ENOMEM") {
153 if (!$rsz && $line[3]) {
156 if ($rsz != $line[3]) {
158 &write_dat_file("rd");
159 &write_scr_file("rd");
162 &write_dat_file("wr");
163 &write_scr_file("wr");
165 if ($wrrd || $rdwr) {
166 &write_dat_file("rd");
167 &write_scr_file("rd");
168 &write_dat_file("wr");
169 &write_scr_file("wr");
175 #print "rg$line[5] th$line[7] w$line[9] r$line[$rindex]\n";
178 if ($line[10] eq "failed") {
181 if ($line[8] eq "write" && $line[17] eq "read") {
184 if ($line[8] eq "read" && $line[17] eq "write") {
188 if ($line[8] eq "write" && $line[9]) {
191 if ($line[8] eq "read" && $line[9]) {
196 if ($wrrd || $rdwr) {
197 $out{$line[7]}{$line[5]} = $line[9];
198 if ($line[$rindex+1]) {
199 if (!($line[$rindex+1] eq "failed")) {
203 LABEL2: if ($line[5] <= 1 ) {
204 $out{$line[7]}{$line[5] - 1} = $line[$rindex];
206 $out{$line[7]}{$line[5] + 1} = $line[$rindex];
211 $out{$line[7]}{$line[5]} = $line[9];
214 $out{$line[7]}{$line[5]} = $line[9];
216 if ( $region < $line[7] ) {
219 if ( $thread < $line[5] ) {
225 if ($count > 1 && $rsz) {
227 &write_dat_file("rd");
228 &write_scr_file("rd");
231 &write_dat_file("wr");
232 &write_scr_file("wr");
234 if ($wrrd || $rdwr) {
235 &write_dat_file("rd");
236 &write_scr_file("rd");
237 &write_dat_file("wr");
238 &write_scr_file("wr");
241 print "Invalid log file format\n";