2 # Report generation for llstat
3 # ===============================
4 # The plot-llstat script is used to generate csv file and
5 # instructions files for gnuplot from the output of llstat script.
6 # Since llstat is generic in nature, plot-llstat is also generic
10 # operations = { open, close, read_bytes, write_bytes, connect, create, .. etc.}
11 # parameters = { Rate, Total}
13 # plot-llstat script creates dat(csv) file using number of operations
14 # specified by the user. Number of operations equals to number of columns in csv
15 # file. And values in those columns are equals to the corresponding value of
16 # the "$param_inx" parameter from the output file.
17 # The plot-llstat also creates .scr file that contains instructions
18 # for gnuplot to plot the graph. After generating .dat and .scr files this
19 # script invokes gnuplot to display graph.
22 # 1. This script is generic in nature, works with any operations names.
23 # 2. User have option to setect operations of their choice for graph generation.
24 # 3. This script automatically selects different y axes according to the ranges
25 # of values of the parameter.
26 # 4. One can change parameter to be consider for graphing
27 # by changing value of $param_inx.
30 # $ plot-llstat <results_filename> [parameter index (default=2, i.e. Rate)]
31 # [Note: 1. The output filt given to this script must have been generated
32 # with -g option to the llstat script.
33 # 2. This script may need modifications whenever there will be
34 # modifications in output format of llstat script.]
38 print "$0 parses and graphs the output of llstat using gnuplot,\n";
39 print "and generates .dat files for use in spreadsheets.\n";
40 print "Usage: $0 <results_filename> [parameter_index]\n";
41 print " where parameter_index is one of:\n";
42 print " 1 - Count per interval\n";
43 print " 2 - Rate (count per second) (default)\n";
44 print " 3 - Total count\n";
45 print "ex: # llstat -i2 -g -c lustre-OST0000 > log\n";
46 print " # $0 log 3\n";
50 my $count = 0; # count for number of rows in csv(.dat) file.
51 my $jumpcolumn = -1; # Columns to be skiped to get op. name and the "$param_inx" param.
52 my @columns; # Array for Operations names.
53 my $columnvalues = ""; # Values of the "$param_inx" parameter for all operations.
54 my @line; # To store recently read line from log file
55 my $param_inx = 2; # Index of the parameter are you interested in graphing.
56 # Default is 2 for Rate.
63 $param_inx = $ARGV[1];
68 # Open log file for reading
69 open ( PFILE, "$file") or die "Can't open results log file";
72 LABLE:while ( $count <= $#alllines ) {
73 $line = $alllines[$count];
76 @line = split(/\s+/,$line); # splits line into tokens
77 # This comparison may be changed if there will be changes log file.
78 if( $line[0] eq "Timestamp" ) {
79 # decide operations position in the logfile depends on num of
80 # parameters(Rate, Total, etc.) present in this line.
82 $count = $count + 2; # skip the "---------" line from result file.
85 if ($line[1] eq "STATS" && $line[2] eq "on") {
87 @GraphTitle = split( /:/, $GraphTitle );
91 if ($jumpcolumn < 0) {
92 print "Invalid logfile format\n";
95 $lastline = $alllines[-1];
96 @lastline = split(/\s+/,$lastline);
99 while ($i < $#lastline) {
100 # display operations names for user selection.
101 print "$lastline[$i] ";
102 $allcolumns = "$allcolumns$lastline[$i] ";
103 # capture the "$param_inx" parameter in $columnvalues,
104 # used to define axes ranges depends on values.
105 $columnvalues = "$columnvalues$lastline[$i + $param_inx] ";
106 $i = $i + $jumpcolumn;
108 print "\nSelect columns(press return to select all): ";
110 # consider all operations if user hit return.
111 if ( $columns eq "\n" ) {
112 $columns = $allcolumns;
115 @columns = split (/\s+/, $columns);
116 # Open .csv file for writting required columns from log file.
117 open ( DATAFILE, "> $file.dat" ) or die "Can't open csv file for writting";
119 for ($i = 0; $i < $#lastline; $i++) {
120 for ($j = 0; $j <= $#columns; $j++) {
121 if ($columns[$j] eq $lastline[$i]) {
122 print DATAFILE "$columns[$j]$lastline[$i + 4] ";
129 # depends on $jumpcolumn, capture operation names and value of
130 # the "$param_inx" parameter for that perticular operation.
131 while ( $count <= $#alllines ) {
132 $line = $alllines[$count];
135 @line = split(/\s+/,$line); # splits line into tokens
136 # fill the csv(.dat) file with values of operations.
137 print DATAFILE "$line[0]";
138 for ($j = 0; $j <= $#columns; $j++) {
139 for ($i = 1; $i < $#line ; $i++) {
140 if ($columns[$j] eq $line[$i]) {
141 # capture the "$param_inx" parameter
142 print DATAFILE " $line[$i + $param_inx]";
156 # Open .csv file for reading columns titles.
157 open ( DATAFILE, "$file.dat" ) or die "Can't open csv file for reading titles\n";
158 my $titles = <DATAFILE>;
161 @titles = split (/\s+/, $titles);
162 # Open .scr file for writting instructions for gnuplot.
163 open ( SCRFILE, "> $file.scr" ) or die "Can't open scr file for writting\n";
164 print SCRFILE "set title \"$GraphTitle[1]\"\n";
165 print SCRFILE "set xlabel \"time\"\n";
166 if ($param_inx == 1) {
167 print SCRFILE "set ylabel \"units/interval\"\n";
168 } elsif ($param_inx == 3) {
169 print SCRFILE "set ylabel \"units\"\n";
171 print SCRFILE "set ylabel \"units/sec\"\n";
174 # generate instructions for gnuplot
175 for ($i = 2; $i <= ($#columns + 2); $i++) {
176 print SCRFILE "$plot \"$file.dat\" using 1:$i axes x1y1 title \"$titles[$i - 1]\" with line\n";
179 print SCRFILE "pause -1\n";
181 # invoke gnuplot to display graph.
182 system ("gnuplot $file.scr") == 0 or die "ERROR: while ploting graph.\nMake sure that gnuplot is working properly";