4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
22 # Copyright 2008 Sun Microsystems, Inc. All rights reserved
23 # Use is subject to license terms.
25 # Copyright (c) 2013, 2014, Intel Corporation.
27 # This file is part of Lustre, http://www.lustre.org/
28 # Lustre is a trademark of Sun Microsystems, Inc.
30 # Author: Jitendra Pawar <jitendra@clusterfs.com>
32 # Report generation for iokit-plot-obdfilter
33 # ====================================
34 # The iokit-plot-obdfilter script is used to generate csv file and
35 # instructions files for gnuplot from the output of obdfilter-survey script.
37 # The iokit-plot-obdfilter also creates .scr file that contains instructions
38 # for gnuplot to plot the graph. After generating .dat and .scr files this
39 # script invokes gnuplot to display graph.
42 # $ obdfilter-survey > log_filename
43 # $ iokit-plot-obdfilter <log_filename>
44 # [Note: 1. Please use the .summary file generated by obdfilter-survey as log_file.
45 # It is generally available at /tmp/obdfilter_survey_<date_time_system>.summary
46 # 2. This script may need modifications whenever there will be
47 # modifications in output format of obdfilter-survey script.
48 # 3. Gnuplot version 4.0 or above is required.]
52 print "Usage: $0 <log_filename> [--st=<subtitle>] [--y0=<Y-axis start point>]\n";
53 print " The $0 parses and plots graphs for output of obdfilter-survey using gnuplot.\n";
54 print " It generates <log_filename>-<Rsize><rd/wr>.dat and\n";
55 print " <log_filename>-<Rsize>-<rd/wr/rrd/rwr/rwa>.scr files.\n";
56 print " Those will be used for graphing the results\n";
58 print " --st: SubTitle for the graph\n";
59 print " --y0: Start point of Y-axis, Default value automatically taken based on Y-axis values ranges\n";
60 print " log_file: use the .summary file generated by obdfilter-survey as log_file.\n";
61 print " It is generally available at /tmp/obdfilter_survey_<date_time_system>.summary\n";
62 print "e.g. # $0 obdfilter-log --st=\"Sub-Title\" --y0=50\n";
66 # check whether gnuplot exists?
67 system ("which gnuplot > /dev/null") == 0 or die "gnuplot does not exist, please install it and try again.\n";
69 #Subroutine to write .scr file that further used by gnuplot to plot the graph.
70 sub write_scr_file() {
73 print "generating plot $file-$rsz-$op.png\n";
74 open ( SCRFILE, "> $file-$rsz-$op.scr" ) or die "Can't open scr file for writing";
77 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz KBytes, $subtitle\"\n";
79 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz KBytes\"\n";
81 print SCRFILE "set xlabel \"Threads\"\n";
82 print SCRFILE "set ylabel \"Speeds(MB/s)\"\n";
83 print SCRFILE "set logscale x\n";
84 print SCRFILE "set grid\n";
85 print SCRFILE "set terminal png\n";
86 print SCRFILE "set output \"/dev/null\"\n";
87 if ($opt_y0 != -9999) {
88 print SCRFILE "set yrange [ $opt_y0: ]\n";
93 # generate instructions for gnuplot, with adjusting X-axes ranges
94 for ($j = $first_obj; $j <= $obj ; $j = $j + $j) {
95 printf SCRFILE "$plot \"$file-$rsz-$op.dat\" using 1:$i axes x%dy1 title \"$rwlabel-obj$j\" with line\n", $xrange;
99 print SCRFILE "set output \"$file-$rsz-$op.png\"\n";
100 print SCRFILE "replot\n";
103 # invoke gnuplot to display graph.
104 system ("gnuplot $file-$rsz-$op.scr") == 0 or die "ERROR: while ploting graph";
105 system ("rm $file-$rsz-$op.scr");
108 #Subroutine to write .dat file that further used by gnuplot to plot the graph.
109 sub write_dat_file() {
111 print "writing data $file-$rsz-$op.dat\n";
112 # Open .csv/.dat file for writing required columns from log file.
113 open ( DATAFILE, "> $file-$rsz-$op.dat" ) or die "Can't open csv file for writing";
114 printf DATAFILE "%-6s", "thrd";
115 for ($j = $first_obj; $j <= $obj; $j = $j + $j) {
116 printf DATAFILE "%-10s", "$op-obj$j";
118 for ( $i = $first_thread; $i <= $thread; $i = $i + $i ) {
119 printf DATAFILE "\n%-6s", $i;
120 for ($j = $first_obj; $j <= $obj; $j = $j + $j) {
121 # switch-case can be used instead if else
123 if ( $ard{$i}{$j} ) {
124 printf DATAFILE "%-10s", $ard{$i}{$j};
126 printf DATAFILE "%-10s", "-";
128 } elsif ($op eq "wr" ) {
129 if ( $awr{$i}{$j} ) {
130 printf DATAFILE "%-10s", $awr{$i}{$j};
132 printf DATAFILE "%-10s", "-";
134 } elsif ($op eq "rwr" ) {
135 if ( $arwr{$i}{$j} ) {
136 printf DATAFILE "%-10s", $arwr{$i}{$j};
138 printf DATAFILE "%-10s", "-";
140 } elsif ($op eq "rrd" ) {
141 if ( $arrd{$i}{$j} ) {
142 printf DATAFILE "%-10s", $arrd{$i}{$j};
144 printf DATAFILE "%-10s", "-";
146 } elsif ($op eq "rwa" ) {
147 if ( $arwa{$i}{$j} ) {
148 printf DATAFILE "%-10s", $arwa{$i}{$j};
150 printf DATAFILE "%-10s", "-";
158 #Subroutine to call .scr and .dat file write routines.
160 for ($cnt = 0; $cnt < @operations; $cnt = $cnt + 1) {
161 # switch-case can be used instead if else
162 if($operations[$cnt] eq "read") {
163 &write_dat_file("rd");
164 &write_scr_file("rd", "read");
165 } elsif ($operations[$cnt] eq "write") {
166 &write_dat_file("wr");
167 &write_scr_file("wr", "write");
168 } elsif ($operations[$cnt] eq "reread") {
169 &write_dat_file("rrd");
170 &write_scr_file("rrd", "reread");
171 } elsif ($operations[$cnt] eq "rewrite") {
172 &write_dat_file("rwr");
173 &write_scr_file("rwr", "rewrite");
174 } elsif ($operations[$cnt] eq "rewrite_again") {
175 &write_dat_file("rwa");
176 &write_scr_file("rwa", "rewrite_again");
196 # Command line parameter parsing
198 GetOptions ('help' => \$opt_help, 'st=s' => \$subtitle, 'y0=i' => \$opt_y0) or usage();
202 open ( PFILE, "$file") or die "Can't open results";
203 LABEL: while ( <PFILE> ) {
205 @line = split( /\s+/ );
212 if ($linelen > 26 || $linelen < 11) {
213 print "invalid file format at line $count\n";
216 if (!$rsz && $line[5]) {
219 $first_obj = $line[7];
220 $first_thread = $line[9];
221 for ($i = 10; $i <= $linelen; $i = $i + 5) {
223 $operations[$cnt] = $line[$i];
228 if ($rsz ne $line[5]) {
231 $first_obj = $line[7];
232 $first_thread = $line[9];
235 for ($i = 10; $i <= $linelen; $i = $i + 5) {
237 $operations[$cnt] = $line[$i];
244 for ($i = 0; $i < @operations; $i++) {
245 # switch-case can be used instead if else
246 if($operations[$i] eq "read") {
247 $ard{$line[9]}{$line[7]} = $line[$i * 5 + 11];
248 } elsif ($operations[$i] eq "write") {
249 $awr{$line[9]}{$line[7]} = $line[$i * 5 + 11];
250 } elsif ($operations[$i] eq "reread") {
251 $arrd{$line[9]}{$line[7]} = $line[$i * 5 + 11];
252 } elsif ($operations[$i] eq "rewrite") {
253 $arwr{$line[9]}{$line[7]} = $line[$i * 5 + 11];
254 } elsif ($operations[$i] eq "rewrite_again") {
255 $arwa{$line[9]}{$line[7]} = $line[$i * 5 + 11];
258 if ( $obj < $line[9] ) {
261 if ( $thread < $line[7] ) {
267 if ($count > 1 && $rsz) {
271 print "Invalid log file format\n";