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