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