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 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 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() {
44 print "generating plot $file-$rsz-$op.png\n";
45 open ( SCRFILE, "> $file-$rsz-$op.scr" ) or die "Can't open scr file for writing";
53 if ($opt_rdtitle || $opt_wrtitle) {
55 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz KBytes, $opt_rdtitle\"\n";
58 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz KBytes, $opt_wrtitle\"\n";
61 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz KBytes\"\n";
63 print SCRFILE "set xlabel \"Threads\"\n";
64 print SCRFILE "set ylabel \"Speeds(MB/s)\"\n";
65 print SCRFILE "set logscale x\n";
66 print SCRFILE "set grid\n";
67 print SCRFILE "set terminal png\n";
68 print SCRFILE "set output \"/dev/null\"\n";
70 print SCRFILE "set yrange [ 0:$opt_y ]\n";
72 print SCRFILE "set yrange [ 0: ]\n";
77 my @numrgs = split " ", $regions;
79 # generate instructions for gnuplot, with adjusting X-axes ranges
81 foreach my $j (sort numerically split " ", $threads) {
83 $using = ( $i < $#numrgs ) ? $i : $#numrgs;
84 printf SCRFILE "$plot \"$file-$rsz-$op.dat\" using 1:$using axes x%dy1 title \"write-obj$j\" with line\n", $xrange;
87 $using = ( $i < $#numrgs ) ? $i : $#numrgs;
88 printf SCRFILE "$plot \"$file-$rsz-$op.dat\" using 1:$using axes x%dy1 title \"read-obj$j\" with line\n", $xrange;
93 print SCRFILE "set output \"$file-$rsz-$op.png\"\n";
94 print SCRFILE "replot\n";
96 # invoke gnuplot to display graph.
97 system ("gnuplot $file-$rsz-$op.scr") == 0 or die "ERROR: while ploting graph";
98 system ("rm $file-$rsz-$op.scr");
101 sub check_data_file () {
106 open ( FILE, "< $file" ) or die "Can't open $file for reading";
109 push @values, [ @tmp ];
113 for ( $j = 0; $j <= $#tmp; $j++) {
115 for ($i = 2; $i <= $#values ; $i ++) {
116 $values [$i][$j] =~ "-" or $sum = $sum + $values [$i][$j];
118 die "File: $file : $j column contains no data.\n" unless $sum != 0;
122 sub numerically { $a <=> $b; }
124 #Subroutine to write .dat file that further used by gnuplot to plot the graph.
125 sub write_dat_file() {
127 print "writing data $file-$rsz-$op.dat\n";
128 # Open .csv/.dat file for writing required columns from log file.
129 my $datafile = "$file-$rsz-$op.dat";
130 open ( DATAFILE, "> $datafile" ) or die "Can't open csv $datafile for writing";
131 printf DATAFILE "%-6s", "0";
133 foreach my $j (sort numerically split " ", $regions) {
134 printf DATAFILE "%-8s", "$op$j";
137 # threads, line [7], strings
138 foreach my $i (sort numerically split " ", $threads) {
139 printf DATAFILE "\n%-6s", $i;
141 # regions, line [5], column
142 foreach my $j (sort numerically split " ", $regions) {
143 if (($op eq "rd" && $rdwr) || ($op eq "wr" && $wrrd) || ($readop) || ($writeop)) {
144 if ( $out{$i}{$j} ) {
145 printf DATAFILE "%-8s", $out{$i}{$j};
147 printf DATAFILE "%-8s", "-";
150 if (($j <= 1 && $out{$i}{$j - 1})) {
151 printf DATAFILE "%-8s", $out{$i}{$j - 1};
152 }elsif ($out{$i}{$j + 1} && $j > 1) {
153 printf DATAFILE "%-8s", $out{$i}{$j + 1};
155 printf DATAFILE "%-8s", "-";
161 &check_data_file ( $datafile );
178 # Command line parameter parsing
180 GetOptions ('help' => \$opt_help, 'rt=s' => \$opt_rdtitle, 'wt=s' => \$opt_wrtitle, 'y=i' => \$opt_y) or usage();
186 open ( PFILE, "$file") or die "Can't open $file";
187 LABEL: while ( <PFILE> ) {
189 @line = split( /\s+/ );
190 if ($line[27] && $count != 0) {
191 print "invalid file format\n";
200 if ($line[8] eq "ENOMEM") {
204 if (!$rsz && $line[3]) {
207 if ($rsz != $line[3]) {
209 &write_dat_file("rd");
210 &write_scr_file("rd");
213 &write_dat_file("wr");
214 &write_scr_file("wr");
216 if ($wrrd || $rdwr) {
217 &write_dat_file("rd");
218 &write_scr_file("rd");
219 &write_dat_file("wr");
220 &write_scr_file("wr");
226 #print "rg$line[5] th$line[7] w$line[9] r$line[$rindex]\n";
229 if ($line[10] eq "failed") {
232 if ($line[8] eq "write" && $line[17] eq "read") {
235 if ($line[8] eq "read" && $line[17] eq "write") {
239 if ($line[8] eq "write" && $line[9]) {
242 if ($line[8] eq "read" && $line[9]) {
247 if ($wrrd || $rdwr) {
248 $out{$line[7]}{$line[5]} = $line[9];
249 if ($line[$rindex+1]) {
250 if (!($line[$rindex+1] eq "failed")) {
254 LABEL2: if ($line[5] <= 1 ) {
255 $out{$line[7]}{$line[5] - 1} = $line[$rindex];
257 $out{$line[7]}{$line[5] + 1} = $line[$rindex];
262 $out{$line[7]}{$line[5]} = $line[9];
265 $out{$line[7]}{$line[5]} = $line[9];
267 $regions .= " $line[5]" unless $regions =~ $line[5];
268 $threads .= " $line[7]" unless $threads =~ $line[7];
272 if ($count > 1 && $rsz) {
274 &write_dat_file("rd");
275 &write_scr_file("rd");
278 &write_dat_file("wr");
279 &write_scr_file("wr");
281 if ($wrrd || $rdwr) {
282 &write_dat_file("rd");
283 &write_scr_file("rd");
284 &write_dat_file("wr");
285 &write_scr_file("wr");
288 print "Invalid log file format\n";