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) {
63 printf SCRFILE "$plot \"$file-$rsz-$op.dat\" using 1:$i axes x%dy1 title \"write$j\" with line\n", $xrange;
66 printf SCRFILE "$plot \"$file-$rsz-$op.dat\" using 1:$i axes x%dy1 title \"read$j\" with line\n", $xrange;
71 print SCRFILE "set terminal png transparent\n";
72 print SCRFILE "set output \"$file-$rsz-$op.png\"\n";
73 print SCRFILE "replot\n";
75 # invoke gnuplot to display graph.
76 system ("gnuplot $file-$rsz-$op.scr") == 0 or die "ERROR: while ploting graph";
77 system ("rm $file-$rsz-$op.scr");
80 #Subroutine to write .dat file that further used by gnuplot to plot the graph.
81 sub write_dat_file() {
83 print "writing data $file-$rsz-$op.dat\n";
84 # Open .csv/.dat file for writing required columns from log file.
85 open ( DATAFILE, "> $file-$rsz-$op.dat" ) or die "Can't open csv file for writing";
86 printf DATAFILE "%-6s", "0";
87 for ($j = 1; $j <= $thread ; $j = $j + $j) {
88 printf DATAFILE "%-8s", "$op$j";
90 for ( $i = 1; $i <= $region; $i = $i + $i ) {
91 printf DATAFILE "\n%-6s", $i;
92 for ($j = 1; $j <= $thread ; $j = $j + $j) {
93 if (($op eq "rd" && $rdwr) || ($op eq "wr" && $wrrd) || ($readop) || ($writeop)) {
95 printf DATAFILE "%-8s", $out{$i}{$j};
97 printf DATAFILE "%-8s", "-";
100 if (($j <= 1 && $out{$i}{$j - 1})) {
101 printf DATAFILE "%-8s", $out{$i}{$j - 1};
102 }elsif ($out{$i}{$j + 1} && $j > 1) {
103 printf DATAFILE "%-8s", $out{$i}{$j + 1};
105 printf DATAFILE "%-8s", "-";
126 # Command line parameter parsing
128 GetOptions ('help' => \$opt_help, 'rt=s' => \$opt_rdtitle, 'wt=s' => \$opt_wrtitle) or usage();
132 open ( PFILE, "$file") or die "Can't open results";
133 LABEL: while ( <PFILE> ) {
135 @line = split( /\s+/ );
137 print "invalid file format\n";
146 if ($line[8] eq "ENOMEM") {
150 if (!$rsz && $line[3]) {
153 if ($rsz != $line[3]) {
155 &write_dat_file("rd");
156 &write_scr_file("rd");
159 &write_dat_file("wr");
160 &write_scr_file("wr");
162 if ($wrrd || $rdwr) {
163 &write_dat_file("rd");
164 &write_scr_file("rd");
165 &write_dat_file("wr");
166 &write_scr_file("wr");
172 #print "rg$line[5] th$line[7] w$line[9] r$line[$rindex]\n";
175 if ($line[10] eq "failed") {
178 if ($line[8] eq "write" && $line[17] eq "read") {
181 if ($line[8] eq "read" && $line[17] eq "write") {
185 if ($line[8] eq "write" && $line[9]) {
188 if ($line[8] eq "read" && $line[9]) {
193 if ($wrrd || $rdwr) {
194 $out{$line[7]}{$line[5]} = $line[9];
195 if ($line[$rindex+1]) {
196 if (!($line[$rindex+1] eq "failed")) {
200 LABEL2: if ($line[5] <= 1 ) {
201 $out{$line[7]}{$line[5] - 1} = $line[$rindex];
203 $out{$line[7]}{$line[5] + 1} = $line[$rindex];
208 $out{$line[7]}{$line[5]} = $line[9];
211 $out{$line[7]}{$line[5]} = $line[9];
213 if ( $region < $line[7] ) {
216 if ( $thread < $line[5] ) {
222 if ($count > 1 && $rsz) {
224 &write_dat_file("rd");
225 &write_scr_file("rd");
228 &write_dat_file("wr");
229 &write_scr_file("wr");
231 if ($wrrd || $rdwr) {
232 &write_dat_file("rd");
233 &write_scr_file("rd");
234 &write_dat_file("wr");
235 &write_scr_file("wr");
238 print "Invalid log file format\n";