Whamcloud - gitweb
LU-5560 obd: reserve connection flag OBD_CONNECT2_FILE_SECCTX
[fs/lustre-release.git] / lustre-iokit / obdfilter-survey / iokit-plot-obdfilter
1 #!/usr/bin/perl -w
2 # GPL HEADER START
3 #
4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 2 only,
8 # as published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # General Public License version 2 for more details (a copy is included
14 # in the LICENSE file that accompanied this code).
15 #
16 # You should have received a copy of the GNU General Public License
17 # version 2 along with this program; If not, see
18 # http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19 #
20 # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 # CA 95054 USA or visit www.sun.com if you need additional information or
22 # have any questions.
23 #
24 # GPL HEADER END
25 #
26 # Copyright  2008 Sun Microsystems, Inc. All rights reserved
27 # Use is subject to license terms.
28 #
29 # Copyright (c) 2013, 2014, Intel Corporation.
30 #
31 # This file is part of Lustre, http://www.lustre.org/
32 # Lustre is a trademark of Sun Microsystems, Inc.
33 #
34 # Author: Jitendra Pawar <jitendra@clusterfs.com>
35
36 # Report generation for iokit-plot-obdfilter
37 # ====================================
38 # The iokit-plot-obdfilter script is used to generate csv file and
39 # instructions files for gnuplot from the output of obdfilter-survey script.
40 #
41 # The iokit-plot-obdfilter also creates .scr file that contains instructions
42 # for gnuplot to plot the graph. After generating .dat and .scr files this
43 # script invokes gnuplot to display graph.
44 #
45 # Syntax:
46 # $ obdfilter-survey > log_filename
47 # $ iokit-plot-obdfilter <log_filename>
48 # [Note: 1. Please use the .summary file generated by obdfilter-survey as log_file.
49 #           It is generally available at /tmp/obdfilter_survey_<date_time_system>.summary
50 #        2. This script may need modifications whenever there will be
51 #           modifications in output format of obdfilter-survey script.
52 #        3. Gnuplot version 4.0 or above is required.]
53
54 my @GraphTitle;
55 sub usage() {
56         print "Usage: $0 <log_filename> [--st=<subtitle>] [--y0=<Y-axis start point>]\n";
57         print "       The $0 parses and plots graphs for output of obdfilter-survey using gnuplot.\n";
58         print "       It generates <log_filename>-<Rsize><rd/wr>.dat and\n";
59         print "       <log_filename>-<Rsize>-<rd/wr/rrd/rwr/rwa>.scr files.\n";
60         print "       Those will be used for graphing the results\n";
61         print "OPTIONS:\n";
62         print " --st: SubTitle for the graph\n";
63         print " --y0: Start point of Y-axis, Default value automatically taken based on Y-axis values ranges\n";
64         print " log_file: use the .summary file generated by obdfilter-survey as log_file.\n";
65         print "           It is generally available at /tmp/obdfilter_survey_<date_time_system>.summary\n";
66         print "e.g.   # $0 obdfilter-log --st=\"Sub-Title\" --y0=50\n";
67         exit 1;
68 }
69
70 # check whether gnuplot exists?
71 system ("which gnuplot > /dev/null") == 0 or die "gnuplot does not exist, please install it and try again.\n";
72
73 #Subroutine to write .scr file that further used by gnuplot to plot the graph.
74 sub write_scr_file() {
75         my $op = $_[0];
76         my $rwlabel = $_[1];
77         print "generating plot $file-$rsz-$op.png\n";
78         open ( SCRFILE, "> $file-$rsz-$op.scr" ) or die "Can't open scr file for writing";
79
80         if ($subtitle) {
81                 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz KBytes, $subtitle\"\n";
82         } else {
83                 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz KBytes\"\n";
84         }
85         print SCRFILE "set xlabel \"Threads\"\n";
86         print SCRFILE "set ylabel \"Speeds(MB/s)\"\n";
87         print SCRFILE "set logscale x\n";
88         print SCRFILE "set grid\n";
89         print SCRFILE "set terminal png\n";
90         print SCRFILE "set output \"/dev/null\"\n";
91         if ($opt_y0 != -9999) {
92                 print SCRFILE "set yrange [ $opt_y0: ]\n";
93         }
94         my $plot = "plot";
95         $i = 2;
96         $xrange = 1;
97         # generate instructions for gnuplot, with adjusting X-axes ranges
98         for ($j = $first_obj; $j <= $obj ; $j = $j + $j) {
99                         printf SCRFILE "$plot \"$file-$rsz-$op.dat\" using 1:$i axes x%dy1 title \"$rwlabel-obj$j\" with line\n", $xrange;
100                 $i++;
101                 $plot = "replot";
102         }
103         print SCRFILE "set output \"$file-$rsz-$op.png\"\n";
104         print SCRFILE "replot\n";
105         close SCRFILE;
106         $graphgen = 1;
107         # invoke gnuplot to display graph.
108         system ("gnuplot $file-$rsz-$op.scr") == 0 or die "ERROR: while ploting graph";
109         system ("rm $file-$rsz-$op.scr");
110 }
111
112 #Subroutine to write .dat file that further used by gnuplot to plot the graph.
113 sub write_dat_file() {
114         my $op = $_[0];
115         print "writing data $file-$rsz-$op.dat\n";
116         # Open .csv/.dat file for writing required columns from log file.
117         open ( DATAFILE, "> $file-$rsz-$op.dat" ) or die "Can't open csv file for writing";
118         printf DATAFILE "%-6s", "thrd";
119         for ($j = $first_obj; $j <= $obj; $j = $j + $j) {
120                 printf DATAFILE "%-10s", "$op-obj$j";
121         }
122         for ( $i = $first_thread; $i <= $thread; $i = $i + $i ) {
123                 printf DATAFILE "\n%-6s", $i;
124                 for ($j = $first_obj; $j <= $obj; $j = $j + $j) {
125                 # switch-case can be used instead if else
126                         if ($op eq "rd") {
127                                         if ( $ard{$i}{$j} ) {
128                                                 printf DATAFILE "%-10s", $ard{$i}{$j};
129                                         } else {
130                                                 printf DATAFILE "%-10s", "-";
131                                         }
132                         } elsif ($op eq "wr" ) {
133                                         if ( $awr{$i}{$j} ) {
134                                                 printf DATAFILE "%-10s", $awr{$i}{$j};
135                                         } else {
136                                                 printf DATAFILE "%-10s", "-";
137                                         }
138                         } elsif ($op eq "rwr" ) {
139                                         if ( $arwr{$i}{$j} ) {
140                                                 printf DATAFILE "%-10s", $arwr{$i}{$j};
141                                         } else {
142                                                 printf DATAFILE "%-10s", "-";
143                                         }
144                         } elsif ($op eq "rrd" ) {
145                                         if ( $arrd{$i}{$j} ) {
146                                                 printf DATAFILE "%-10s", $arrd{$i}{$j};
147                                         } else {
148                                                 printf DATAFILE "%-10s", "-";
149                                         }
150                         } elsif ($op eq "rwa" ) {
151                                         if ( $arwa{$i}{$j} ) {
152                                                 printf DATAFILE "%-10s", $arwa{$i}{$j};
153                                         } else {
154                                                 printf DATAFILE "%-10s", "-";
155                                         }
156                         }
157                 }
158         }
159         close DATAFILE;
160 }
161
162 #Subroutine to call .scr and .dat file write routines.
163 sub write_files() {
164         for ($cnt = 0; $cnt < @operations; $cnt = $cnt + 1) {
165                 # switch-case can be used instead if else
166                 if($operations[$cnt] eq "read") {
167                         &write_dat_file("rd");
168                         &write_scr_file("rd", "read");
169                 } elsif ($operations[$cnt] eq "write") {
170                         &write_dat_file("wr");
171                         &write_scr_file("wr", "write");
172                 } elsif ($operations[$cnt] eq "reread") {
173                         &write_dat_file("rrd");
174                         &write_scr_file("rrd", "reread");
175                 } elsif ($operations[$cnt] eq "rewrite") {
176                         &write_dat_file("rwr");
177                         &write_scr_file("rwr", "rewrite");
178                 } elsif ($operations[$cnt] eq "rewrite_again") {
179                         &write_dat_file("rwa");
180                         &write_scr_file("rwa", "rewrite_again");
181                 }
182         }
183 }
184
185 if ( !$ARGV[0] ) {
186         usage();
187 }
188 $file = $ARGV[0];
189 $obj = 0;
190 $thread = 0;
191 $first_obj = 1;
192 $first_thread = 1;
193 $count = 0;
194 $rsz = 0;
195 $subtitle = "";
196 $opt_y0 = -9999;
197 $cnt = 0;
198 @operations = ();
199 $graphgen = 0;
200 # Command line parameter parsing
201 use Getopt::Long;
202 GetOptions ('help' => \$opt_help, 'st=s' => \$subtitle, 'y0=i' => \$opt_y0) or usage();
203 if ($opt_help) {
204         usage();
205 }
206 open ( PFILE, "$file") or die "Can't open results";
207 LABEL: while ( <PFILE> ) {
208         chomp;
209         @line = split( /\s+/ );
210         if ($count == 0) {
211                 @GraphTitle = @line;
212                 $count++;
213                 next LABEL;
214         }
215         $linelen = @line;
216         if ($linelen > 26 || $linelen < 11) {
217                 print "invalid file format at line $count\n";
218                 exit 1;
219         }
220         if (!$rsz && $line[5]) {
221                 $cnt = 0;
222                 $rsz = $line[5];
223                 $first_obj = $line[7];
224                 $first_thread = $line[9];
225                 for ($i = 10; $i <= $linelen; $i = $i + 5) {
226                         if ($line[$i]) {
227                                 $operations[$cnt] = $line[$i];
228                                 $cnt++;
229                         }
230                 }
231         }
232         if ($rsz ne $line[5]) {
233                 &write_files();
234                 $rsz = $line[5];
235                 $first_obj = $line[7];
236                 $first_thread = $line[9];
237                 @operations = ();
238                 $cnt = 0;
239                 for ($i = 10; $i <= $linelen; $i = $i + 5) {
240                         if ($line[$i]) {
241                                 $operations[$cnt] = $line[$i];
242                                 $cnt++;
243                         }
244                 }
245                 $obj = 0;
246                 $thread = 0;
247         }
248         for ($i = 0; $i < @operations; $i++) {
249                 # switch-case can be used instead if else
250                 if($operations[$i] eq "read") {
251                         $ard{$line[9]}{$line[7]} = $line[$i * 5 + 11];
252                 } elsif ($operations[$i] eq "write") {
253                         $awr{$line[9]}{$line[7]} = $line[$i * 5 + 11];
254                 } elsif ($operations[$i] eq "reread") {
255                         $arrd{$line[9]}{$line[7]} = $line[$i * 5 + 11];
256                 } elsif ($operations[$i] eq "rewrite") {
257                         $arwr{$line[9]}{$line[7]} = $line[$i * 5 + 11];
258                 } elsif ($operations[$i] eq "rewrite_again") {
259                         $arwa{$line[9]}{$line[7]} = $line[$i * 5 + 11];
260                 }
261         }
262         if ( $obj < $line[9] ) {
263                 $obj = $line[9];
264         }
265         if ( $thread < $line[7] ) {
266                 $thread = $line[7];
267         }
268         $count++;
269 }
270 close PFILE;
271 if ($count > 1 && $rsz) {
272         &write_files();
273 }
274 if (!$graphgen) {
275         print "Invalid log file format\n";
276 }