+
+#Subroutine to write .scr file that further used by gnuplot to plot the graph.
+sub write_scr_file() {
+ my $op = $_[0];
+ print "generating plot $file-$rsz-$op.png\n";
+ open ( SCRFILE, "> $file-$rsz-$op.scr" ) or die "Can't open scr file for writing";
+ if ($op eq "rd") {
+ $rwlabel = "Read";
+ }
+ if ($op eq "wr") {
+ $rwlabel = "Write";
+ }
+
+ if ($opt_rdtitle || $opt_wrtitle) {
+ if ($op eq "rd") {
+ print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz KBytes, $opt_rdtitle\"\n";
+ }
+ if ($op eq "wr") {
+ print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz KBytes, $opt_wrtitle\"\n";
+ }
+ } else {
+ print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz KBytes\"\n";
+ }
+ print SCRFILE "set xlabel \"Threads\"\n";
+ print SCRFILE "set ylabel \"Speeds(MB/s)\"\n";
+ print SCRFILE "set logscale x\n";
+ print SCRFILE "set grid\n";
+ print SCRFILE "set terminal png\n";
+ print SCRFILE "set output \"/dev/null\"\n";
+ if ($opt_y != 0) {
+ print SCRFILE "set yrange [ 0:$opt_y ]\n";
+ } else {
+ print SCRFILE "set yrange [ 0: ]\n";
+ }
+
+ my $plot = "plot";
+ $i = 2;
+ my @numrgs = split " ", $regions;
+ $xrange = 1;
+ # generate instructions for gnuplot, with adjusting X-axes ranges
+
+ foreach my $j (sort numerically split " ", $threads) {
+ if ($op eq "wr") {
+ $using = ( $i < $#numrgs ) ? $i : $#numrgs;
+ printf SCRFILE "$plot \"$file-$rsz-$op.dat\" using 1:$using axes x%dy1 title \"write-obj$j\" with line\n", $xrange;
+ }
+ if ($op eq "rd") {
+ $using = ( $i < $#numrgs ) ? $i : $#numrgs;
+ printf SCRFILE "$plot \"$file-$rsz-$op.dat\" using 1:$using axes x%dy1 title \"read-obj$j\" with line\n", $xrange;
+ }
+ $i++;
+ $plot = "replot";
+ }
+ print SCRFILE "set output \"$file-$rsz-$op.png\"\n";
+ print SCRFILE "replot\n";
+ close SCRFILE;
+ # invoke gnuplot to display graph.
+ system ("gnuplot $file-$rsz-$op.scr") == 0 or die "ERROR: while ploting graph";
+ system ("rm $file-$rsz-$op.scr");
+}
+
+sub check_data_file () {
+ my $file=shift;
+ my @values;
+ my @tmp;
+
+ open ( FILE, "< $file" ) or die "Can't open $file for reading";
+ while ( <FILE> ) {
+ @tmp = split;
+ push @values, [ @tmp ];
+ }
+ close FILE;
+
+ for ( $j = 0; $j <= $#tmp; $j++) {
+ my $sum=0;
+ for ($i = 2; $i <= $#values ; $i ++) {
+ $values [$i][$j] =~ "-" or $sum = $sum + $values [$i][$j];
+ }
+ die "File: $file : $j column contains no data.\n" unless $sum != 0;
+ }
+}
+
+sub numerically { $a <=> $b; }
+
+#Subroutine to write .dat file that further used by gnuplot to plot the graph.
+sub write_dat_file() {
+ my $op = $_[0];
+ print "writing data $file-$rsz-$op.dat\n";
+ # Open .csv/.dat file for writing required columns from log file.
+ my $datafile = "$file-$rsz-$op.dat";
+ open ( DATAFILE, "> $datafile" ) or die "Can't open csv $datafile for writing";
+ printf DATAFILE "%-6s", "0";
+
+ foreach my $j (sort numerically split " ", $regions) {
+ printf DATAFILE "%-8s", "$op$j";
+ }
+
+ # threads, line [7], strings
+ foreach my $i (sort numerically split " ", $threads) {
+ printf DATAFILE "\n%-6s", $i;
+
+ # regions, line [5], column
+ foreach my $j (sort numerically split " ", $regions) {
+ if (($op eq "rd" && $rdwr) || ($op eq "wr" && $wrrd) || ($readop) || ($writeop)) {
+ if ( $out{$i}{$j} ) {
+ printf DATAFILE "%-8s", $out{$i}{$j};
+ } else {
+ printf DATAFILE "%-8s", "-";
+ }
+ } else {
+ if (($j <= 1 && $out{$i}{$j - 1})) {
+ printf DATAFILE "%-8s", $out{$i}{$j - 1};
+ }elsif ($out{$i}{$j + 1} && $j > 1) {
+ printf DATAFILE "%-8s", $out{$i}{$j + 1};
+ } else {
+ printf DATAFILE "%-8s", "-";
+ }
+ }
+ }
+ }
+ close DATAFILE;
+ &check_data_file ( $datafile );
+}
+