Whamcloud - gitweb
LU-13090 utils: fix lfs_migrate -p for file with pool
[fs/lustre-release.git] / lustre-iokit / ost-survey / iokit-plot-ost
1 #!/usr/bin/perl -w
2 # Report generation for ost-survey.pl
3 # ===================================
4 # The iokit-plot-ost script is used to generate csv file and
5 # instructions files for gnuplot from the output of ost-survey.pl script.
6 #
7 # iokit-plot-ost 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 # $ iokit-plot-ost <log_filename>
13 # Note:  1. This script may need modifications whenever there will be
14 #           modifications in output format of ost-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 "       $0 produces graphs from the output of ost-survey.pl\n";
21         print "       using gnuplot.\n";
22         print "e.g.# perl ost-survey /mnt/lustre > ost-log; perl $0 ost-log\n";
23         exit 1;
24 }
25
26 my $count = 0;          # count for number of rows in csv(.dat) file.
27 my @line;               # To store recently read line from log file
28 my $flag = 0;
29 my @GraphTitle;
30 if ( !$ARGV[0] ) {
31         usages_msg();
32 }
33
34 $file = $ARGV[0];
35 # Open log file for reading
36 open ( PFILE, "$file") or die "Can't open results log file";
37 # Open .csv file for writting required columns from log file.
38 open ( DATAFILE, "> $file.dat" ) or die "Can't open csv file for writting";
39 LABLE:while ( <PFILE> ) {
40         chomp;
41         @line = split( /\s+/ ); # splits line into tokens
42         # This comparison may be changed if there will be changes log file.
43         if ( $line[0] eq "Ost#" ) {
44                 print DATAFILE "$line[0] $line[1] $line[2]\n";
45                 $flag = 1;
46                 <PFILE>; # skip the "---------" line from result file.
47                 last LABLE;
48         }
49         if ($line[2] eq "OST" && $line[3] eq "speed") {
50                 @GraphTitle = @line;
51                 @GraphTitle = split( /:/ );
52         }
53 }
54 if ( !$flag) {
55         print "Invalid logfile format\n";
56         exit 1;
57 }
58 while ( <PFILE> )  {
59         chomp;
60         @line = split( /\s+/ ); # splits line into tokens
61         if ( $line[1] ne "Inactive" ) {
62                 print DATAFILE "$count $line[1] $line[2]\n";
63         }
64         $count = $count + 1;
65 }
66 close PFILE;
67 close DATAFILE;
68 # Open .scr file for writting instructions for gnuplot.
69 open ( SCRFILE, "> $file.scr" ) or die "Can't open scr file for writting";
70 # generate instructions for gnuplot. decide axes depends on ranges in @columnvalues
71 print SCRFILE "set title \"$GraphTitle[1]\"\n";
72 print SCRFILE "set xlabel \"OST index\"\n";
73 print SCRFILE "set ylabel \"MB/s\"\n";
74 print SCRFILE "set boxwidth 0.2\n";
75 print SCRFILE "plot \"$file.dat\" using 1:2 axes x1y1 title \"Read(MB/s)\" with boxes fs solid 0.7\n";
76 print SCRFILE "replot \"$file.dat\" using (\$1 + 0.2):3 axes x1y1 title \"Write(MB/s)\" with boxes fs solid 0.7\n";
77 print SCRFILE "pause -1\n";
78 close SCRFILE;
79 # invoke gnuplot to display graph.
80 system ("gnuplot $file.scr") == 0 or die "ERROR: while ploting graph.\nMake sure that gnuplot is working properly";