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.sun.com/software/products/lustre/docs/GPLv2.pdf
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
26 # Copyright 2008 Sun Microsystems, Inc. All rights reserved
27 # Use is subject to license terms.
29 # Copyright (c) 2013, Intel Corporation.
31 # This file is part of Lustre, http://www.lustre.org/
32 # Lustre is a trademark of Sun Microsystems, Inc.
34 # Author: Jitendra Pawar <jitendra@clusterfs.com>
36 # Report generation for plot-obdfilter
37 # ====================================
38 # The plot-obdfilter script is used to generate csv file and
39 # instructions files for gnuplot from the output of obdfilter-survey script.
41 # The 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.
46 # $ obdfilter-survey > log_filename
47 # $ 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.]
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";
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";
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";
73 #Subroutine to write .scr file that further used by gnuplot to plot the graph.
74 sub write_scr_file() {
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";
81 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz KBytes, $subtitle\"\n";
83 print SCRFILE "set title \"@GraphTitle\\n$rwlabel, Rsize = $rsz KBytes\"\n";
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";
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;
103 print SCRFILE "set output \"$file-$rsz-$op.png\"\n";
104 print SCRFILE "replot\n";
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");
112 #Subroutine to write .dat file that further used by gnuplot to plot the graph.
113 sub write_dat_file() {
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";
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
127 if ( $ard{$i}{$j} ) {
128 printf DATAFILE "%-10s", $ard{$i}{$j};
130 printf DATAFILE "%-10s", "-";
132 } elsif ($op eq "wr" ) {
133 if ( $awr{$i}{$j} ) {
134 printf DATAFILE "%-10s", $awr{$i}{$j};
136 printf DATAFILE "%-10s", "-";
138 } elsif ($op eq "rwr" ) {
139 if ( $arwr{$i}{$j} ) {
140 printf DATAFILE "%-10s", $arwr{$i}{$j};
142 printf DATAFILE "%-10s", "-";
144 } elsif ($op eq "rrd" ) {
145 if ( $arrd{$i}{$j} ) {
146 printf DATAFILE "%-10s", $arrd{$i}{$j};
148 printf DATAFILE "%-10s", "-";
150 } elsif ($op eq "rwa" ) {
151 if ( $arwa{$i}{$j} ) {
152 printf DATAFILE "%-10s", $arwa{$i}{$j};
154 printf DATAFILE "%-10s", "-";
162 #Subroutine to call .scr and .dat file write routines.
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");
200 # Command line parameter parsing
202 GetOptions ('help' => \$opt_help, 'st=s' => \$subtitle, 'y0=i' => \$opt_y0) or usage();
206 open ( PFILE, "$file") or die "Can't open results";
207 LABEL: while ( <PFILE> ) {
209 @line = split( /\s+/ );
216 if ($linelen > 26 || $linelen < 11) {
217 print "invalid file format at line $count\n";
220 if (!$rsz && $line[5]) {
223 $first_obj = $line[7];
224 $first_thread = $line[9];
225 for ($i = 10; $i <= $linelen; $i = $i + 5) {
227 $operations[$cnt] = $line[$i];
232 if ($rsz ne $line[5]) {
235 $first_obj = $line[7];
236 $first_thread = $line[9];
239 for ($i = 10; $i <= $linelen; $i = $i + 5) {
241 $operations[$cnt] = $line[$i];
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];
262 if ( $obj < $line[9] ) {
265 if ( $thread < $line[7] ) {
271 if ($count > 1 && $rsz) {
275 print "Invalid log file format\n";