+# check whether gnuplot exists?
+system ("which gnuplot > /dev/null") == 0 or die "gnuplot does not exist, please install it and try again.\n";
+
+#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, $opt_rdtitle\"\n";
+ }
+ if ($op eq "wr") {
+ print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz, $opt_wrtitle\"\n";
+ }
+ } else {
+ print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz\"\n";
+ }
+ print SCRFILE "set xlabel \"Threads\"\n";
+ print SCRFILE "set ylabel \"Speeds(MB/s)\"\n";
+ print SCRFILE "set logscale x\n";
+ my $plot = "plot";
+ $i = 2;
+ $xrange = 1;
+ # generate instructions for gnuplot, with adjusting X-axes ranges
+ for ($j = 1; $j <= $thread ; $j = $j + $j) {
+ if ($j > 15 ) {
+ $xrange = 2;
+ }
+ if ($op eq "wr") {
+ printf SCRFILE "$plot \"$file-$rsz-$op.dat\" using 1:$i axes x%dy1 title \"write$j\" with line\n", $xrange;
+ }
+ if ($op eq "rd") {
+ printf SCRFILE "$plot \"$file-$rsz-$op.dat\" using 1:$i axes x%dy1 title \"read$j\" with line\n", $xrange;
+ }
+ $i++;
+ $plot = "replot";
+ }
+ #print SCRFILE "set terminal png transparent\n";
+ 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");
+}
+
+#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.
+ open ( DATAFILE, "> $file-$rsz-$op.dat" ) or die "Can't open csv file for writing";
+ printf DATAFILE "%-6s", "0";
+ for ($j = 1; $j <= $thread ; $j = $j + $j) {
+ printf DATAFILE "%-8s", "$op$j";
+ }
+ for ( $i = 1; $i <= $region; $i = $i + $i ) {
+ printf DATAFILE "\n%-6s", $i;
+ for ($j = 1; $j <= $thread ; $j = $j + $j) {
+ 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;
+}