Whamcloud - gitweb
274ab31a9a4b376f1b6164682eb3af431815f174
[fs/lustre-release.git] / lustre-iokit / sgpdd-survey / plot-sgpdd.pl
1 #!/usr/bin/perl -w
2 # Report generation for plot-sgpdd.pl
3 # ===================================
4 #        The plot-sgpdd.pl script is used to generate csv file and
5 # instructions files for gnuplot from the output of sgpdd-survey.pl script.
6 #
7 #        The plot-sgpdd.pl 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.
10 #
11 # Syntax:
12 # $ plot-sgpdd.pl <log_filename>
13 # [Note: 1. This script may need modifications whenever there will be
14 #           modifications in output format of sgpdd-survey.pl script.
15 #        2. Gnuplot version 4.0 or above is required.]
16
17 # arg 0 is filename
18 sub usages_msg() {
19         print "Usage: $0 <log_filename> \n";
20         print "       The $0 parses and plots graph for output of sgpdd-survey.pl using gnuplot,\n";
21         print "       it generates .dat and .scr files for results graphing\n";
22         print "e.g.> perl $0 sgpdd-log \n";
23         exit 1;
24 }
25
26 my @GraphTitle;
27 if ( !$ARGV[0] ) {
28         usages_msg();
29 }
30 $file = $ARGV[0];
31 $region = 0;
32 $thread = 0;
33 $count = 0;
34 open ( PFILE, "$file") or die "Can't open results";
35 LABEL: while ( <PFILE> ) {
36         chomp;
37         @line = split( /\s+/ );
38         if ($count == 0) {
39                 @GraphTitle = @line;
40                 $count++;
41                 next LABEL;
42         }
43         $rindex = 18;
44         if ($line[9]) {
45             if ($line[10] eq "failed") {
46                 $rindex = 12;
47             } else {
48                 $out{$line[7]}{$line[5]} = $line[9];    
49             }
50         }
51         #print "rg$line[5] th$line[7] w$line[9] r$line[$rindex]\n";
52         if ($line[$rindex]) {
53             if (!($line[$rindex+1] eq "failed")) {
54                 if ($line[5] <= 1 ) {
55                         $out{$line[7]}{$line[5] - 1} = $line[$rindex];
56                 } else {
57                         $out{$line[7]}{$line[5] + 1} = $line[$rindex];
58                 }
59             }
60         }
61         if ( $region < $line[7] ) {
62                 $region = $line[7];
63         }
64         if ( $thread < $line[5] ) {
65                 $thread = $line[5];
66         }
67         $count++;
68 }
69 close PFILE;
70
71 print "@GraphTitle\n";
72 # Open .csv file for writting required columns from log file.
73 open ( DATAFILE, "> $file.dat" ) or die "Can't open csv file for writting";
74 printf DATAFILE "%-6s", "0";
75 for ($j = 1; $j <= $thread ; $j = $j + $j) {
76         printf DATAFILE "%-8s%-8s", "wr$j", "rd$j";
77 }
78 for ( $i = 1; $i <= $region; $i = $i + $i ) {
79         printf DATAFILE "\n%-6s", $i;
80         for ($j = 1; $j <= $thread ; $j = $j + $j) {
81                 if ( $out{$i}{$j} ) {
82                         printf DATAFILE "%-8s", $out{$i}{$j};
83                     } else {
84                         printf DATAFILE "%-8s", "-";
85                     }
86                 if ( $j <= 1 && $out{$i}{$j - 1}) {
87                     printf DATAFILE "%-8s", $out{$i}{$j - 1};
88                 } elsif ($out{$i}{$j + 1}) {
89                     printf DATAFILE "%-8s", $out{$i}{$j + 1};
90                 } else {
91                     printf DATAFILE "%-8s", "-";
92                 }
93         }
94 }
95 close DATAFILE;
96 open ( SCRFILE, "> $file.scr" ) or die "Can't open scr file for writting";
97 print SCRFILE "set title \"@GraphTitle\"\n";
98 print SCRFILE "set xlabel \"Threads\"\n";
99 print SCRFILE "set ylabel \"Speeds(MB/s)\"\n";
100 my $plot = "plot";
101 $i = 2;
102 $xrange = 1;
103 # generate instructions for gnuplot, with adjusting X-axes ranges
104 for ($j = 1; $j <= $thread ; $j = $j + $j) {
105         if ($j > 15 ) {
106                 $xrange = 2;
107         }
108         printf SCRFILE "$plot \"$file.dat\" using 1:$i axes x%dy1 title \"write$j\" with line\n", $xrange;
109         $plot = "replot";
110         $i++;
111         printf SCRFILE "$plot \"$file.dat\" using 1:$i axes x%dy1 title \"read$j\" with line\n", $xrange;
112         $i++;
113 }
114 print SCRFILE "pause -1\n";
115 close SCRFILE;
116 system ("gnuplot $file.scr") == 0 or die "ERROR: while ploting graph.\nMake sure that gnuplot is working properly";