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/
29 # Author: Jitendra Pawar <jitendra@clusterfs.com>
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.
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.
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.]
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";
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";
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";
68 #Subroutine to write .scr file that further used by gnuplot to plot the graph.
69 sub write_scr_file() {
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";
76 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz KBytes, $subtitle\"\n";
78 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz KBytes\"\n";
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";
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;
98 print SCRFILE "set output \"$file-$rsz-$op.png\"\n";
99 print SCRFILE "replot\n";
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");
107 #Subroutine to write .dat file that further used by gnuplot to plot the graph.
108 sub write_dat_file() {
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";
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
122 if ( $ard{$i}{$j} ) {
123 printf DATAFILE "%-10s", $ard{$i}{$j};
125 printf DATAFILE "%-10s", "-";
127 } elsif ($op eq "wr" ) {
128 if ( $awr{$i}{$j} ) {
129 printf DATAFILE "%-10s", $awr{$i}{$j};
131 printf DATAFILE "%-10s", "-";
133 } elsif ($op eq "rwr" ) {
134 if ( $arwr{$i}{$j} ) {
135 printf DATAFILE "%-10s", $arwr{$i}{$j};
137 printf DATAFILE "%-10s", "-";
139 } elsif ($op eq "rrd" ) {
140 if ( $arrd{$i}{$j} ) {
141 printf DATAFILE "%-10s", $arrd{$i}{$j};
143 printf DATAFILE "%-10s", "-";
145 } elsif ($op eq "rwa" ) {
146 if ( $arwa{$i}{$j} ) {
147 printf DATAFILE "%-10s", $arwa{$i}{$j};
149 printf DATAFILE "%-10s", "-";
157 #Subroutine to call .scr and .dat file write routines.
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");
195 # Command line parameter parsing
197 GetOptions ('help' => \$opt_help, 'st=s' => \$subtitle, 'y0=i' => \$opt_y0) or usage();
201 open ( PFILE, "$file") or die "Can't open results";
202 LABEL: while ( <PFILE> ) {
204 @line = split( /\s+/ );
211 if ($linelen > 26 || $linelen < 11) {
212 print "invalid file format at line $count\n";
215 if (!$rsz && $line[5]) {
218 $first_obj = $line[7];
219 $first_thread = $line[9];
220 for ($i = 10; $i <= $linelen; $i = $i + 5) {
222 $operations[$cnt] = $line[$i];
227 if ($rsz ne $line[5]) {
230 $first_obj = $line[7];
231 $first_thread = $line[9];
234 for ($i = 10; $i <= $linelen; $i = $i + 5) {
236 $operations[$cnt] = $line[$i];
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];
257 if ( $obj < $line[9] ) {
260 if ( $thread < $line[7] ) {
266 if ($count > 1 && $rsz) {
270 print "Invalid log file format\n";