📄 make-graph.pl
字号:
#!/usr/bin/perl -wuse strict;use Getopt::Long;my $xstat = "BW_TOTALS:overall_bw";my @ystat = ("OVERALL_LOOKUPS:lookup_mean");my $xlabel;my @ylabel;my $hulllabel = "BW_TOTALS:live_bw"; my $param;my $paramname = "param";my %paramvals;my $epsfile;my $colorepsfile;my $pngfile;my @indats = ();my $xrange;my $yrange;my @graphlabels = ();my @hulllabelcmds = ();my $title;my $xop;my @yop = ();my $hullop;my $plottype;my $xparen = "";my @yparen = ("");my $hullparen = "";my $grid = 0;my $rtmgraph = 0;my $fontsize = 26;my $linewidth = 1;my $keypos = "top";sub usage { select(STDERR); print <<'EOUsage'; make-graph.pl [options] Options: --help Display this help message --x <stat> Which stat to put on the x-axis --y <stat> Which stat to put on the y-axis Can specify more than one y (NOTE: both labels above can be either a name of a stat (i.e. "BW_TOTALS:overall_bw"), the position of a stat (i.e. "33"), or it could specify a parameter (i.e. "param1") specifies the 1st parameter in the argsfile You can also perform operations on axes (i.e. "--x param6*2") --xrange <min:max> X-axis range (i.e. 0:500) --yrange <min:max> Y-axis range (i.e. 0:500) --xlabel <label> X-axis label --ylabel <label> Y-axis label Can specify more than one ylabel (if more than one is given, the last is the axis label) --epsfile <filename> Save the postscript, instead of using gv --colorepsfile <filename> Save the postscript in color --pngfile <filename> Save the png file --param <param_num> Color the dots by this parameter. Can be the parameter name or a number. To plot only certain values, use "--param base=2,8,32". --paramname <param_name> The name corresponding to the above param --datfile <filename> Where the (merged) stats are May be specified more than once --label <filename> How to label different the dat files May be specified more than once Must correspond (in order) to the datfiles --title <title> Title for the graph --plottype <type> Type of plot. Defaults to "points" (or "lines" for --convex), also accepts "lines" and "linespoints" --keypos <key position> left,right,top,bottom --grid Set grid lines on the graph --convex [both] Generate convex hull graphs, not scatterplots If "both" is specified, both points and convex hull are shown --overallconvex [<label>] If plotting parameter values, this forces the overall hull to be plotted as well. Optionally specify a label for the overall. --hulllabel [<stat>] Only valid with --convex. Labels each point on the hull with the value of a specific statistic or parameter. Defaults to "LOOKUP_RATES:success". --fontsize <size> How big is the font? Default=26. --linewidth <size> How fat are the lines? Default=1. --rtmgraph Only valid with --param and --convex. Holds all parameters but --param constant to values of points on the convex hull, and shows the effect of varying that parameter. --extend Extend convex hulls horizontally to the right (only works with --convex and --xrange)EOUsage exit(1);}# now, figure out what directory we're in, and what# directory this script is in. Get the p2psim commandmy $script_dir = "$0";if( $script_dir !~ m%^/% ) { # relative pathname $script_dir = $ENV{"PWD"} . "/$script_dir";} $script_dir =~ s%/(./)?[^/]*$%%; # strip off script namemy $con_cmd = "$script_dir/find_convexhull.py";# Get the user-defined parameters.# First parse optionsmy %options;&GetOptions( \%options, "help|?", "x=s", "y=s@", "epsfile=s", "colorepsfile=s","pngfile=s", "param=s", "paramname=s", "datfile=s@", "label=s@", "xrange=s", "yrange=s", "xlabel=s", "ylabel=s@", "title=s", "convex:s", "plottype=s", "keypos=s","grid", "rtmgraph", "hulllabel:s", "overallconvex:s", "fontsize=s", "linewidth=s", "extend" ) or &usage;if( $options{"help"} ) { &usage();}if( defined $options{"x"} ) { if( $options{"x"} =~ /^([\*\+\-\/].*)$/ ) { $xstat = "$xstat" . $options{"x"}; } else { $xstat = $options{"x"}; }}if( defined $options{"y"} ) { my $i = 0; foreach my $y (@{$options{"y"}}) { if( $y =~ /^([\*\+\-\/].*)$/ and $i == 0 ) { $ystat[$i] = "$ystat[$i]" . $y; } else { $ystat[$i] = $y; } $i++; }}if( defined $options{"hulllabel"} and $options{"hulllabel"} ne "" ) { if( $options{"hulllabel"} =~ /^([\*\+\-\/].*)$/ ) { $hulllabel = "$hulllabel" . $options{"hulllabel"}; } else { $hulllabel = $options{"hulllabel"}; }}if( defined $options{"xlabel"} ) { $xlabel = $options{"xlabel"};} else { $xlabel = $xstat;}my @templabel = ();if( defined $options{"ylabel"} ) { @templabel = @{$options{"ylabel"}};}# go once extra for the axis labelfor( my $i = 0; $i <= ($#ystat+1); $i++ ) { if( defined $templabel[$i] ) { $ylabel[$i] = $templabel[$i]; } elsif( $i <= $#ystat ) { $ylabel[$i] = $ystat[$i]; }}my $xmin;my $xmax;if( defined $options{"xrange"} ) { $xrange = $options{"xrange"}; if( !($xrange =~ /^([\.\d]+)\:([\.\d]+)$/ ) ) { die( "xrange not in valid format: $xrange" ); } else { if( $2 <= $1 ) { die( "max in xrange is bigger than min: $xrange" ); } $xmin = $1; $xmax = $2; }}my $ymin;my $ymax;if( defined $options{"yrange"} ) { $yrange = $options{"yrange"}; if( !($yrange =~ /^([\.\d]+)\:([\.\d]+)$/ ) ) { die( "yrange not in valid format: $yrange" ); } else { if( $2 <= $1 ) { die( "max in yrange is bigger than min: $yrange" ); } $ymin = $1; $ymax = $2; }}if( defined $options{"epsfile"} ) { $epsfile = $options{"epsfile"};}if (defined $options{"colorepsfile"}) { $colorepsfile = $options{"colorepsfile"};}if (defined $options{"pngfile"}) { $pngfile = $options{"pngfile"};}if( defined $options{"param"} ) { my @paramsplit = split( /=/, $options{"param"} ); if( $#paramsplit > 1 ) { die( "Bad param specification: " . $options{"param"} ); } my $paramval = $paramsplit[0]; # could be numeric or a string if( $paramval =~ /^\d+$/ ) { $param = $paramval - 1; if( $param < 0 ) { die( "Bad param value: " . ($param+1) ); } } else { $param = $paramval; $paramname = $paramval; } if( defined $options{"paramname"} ) { $paramname = $options{"paramname"}; } if( defined $paramsplit[1] ) { my @vals = split(/\,/, $paramsplit[1]); %paramvals = (); foreach my $v (@vals) { $paramvals{$v} = 1; } }}{;}if( defined $options{"datfile"} ) { @indats = @{$options{"datfile"}};} else { print STDERR "datfile(s) not specified\n"; &usage();}foreach my $datfile (@indats) { if( ! -f $datfile ) { print STDERR "datfile not a file: $datfile\n"; &usage(); }}if( defined $options{"label"} ) { @graphlabels = @{$options{"label"}};}if( $#graphlabels > $#indats ) { print STDERR "More labels than datfiles!\n"; &usage();}if( defined $options{"title"} ) { $title = $options{"title"};}if( defined $options{"plottype"} ) { $plottype = $options{"plottype"}; if( $plottype ne "points" and $plottype ne "lines" and $plottype ne "linespoints" ) { die( "Not a valid pointtype: $plottype" ); }}if ( defined $options{"keypos"}) { $keypos = $options{"keypos"};}if( defined $options{"grid"} ) { $grid = 1;}if( defined $options{"rtmgraph"} ) { $rtmgraph = 1;}if( defined $options{"fontsize"} ) { $fontsize = $options{"fontsize"};}if( defined $options{"linewidth"} ) { $linewidth = $options{"linewidth"};}#figure out label issuesmy %labelhash = ();for( my $i = 0; $i <= $#indats; $i++ ) { my $datfile = $indats[$i]; if( defined $graphlabels[$i] ) { $labelhash{$datfile} = $graphlabels[$i]; } else { $labelhash{$datfile} = $datfile; }}my @statlabels;my $xparam = 0;my @yparam = ();my $hullparam = 0;foreach my $y (@ystat) { push @yparam, 0;}my %xposes = ();my %yposes = ();my %hullposes = ();my @datfiles = ();my @xopsplit;my @hullopsplit;my @rtmfiles = ();my $index = 0;foreach my $datfile (@indats) { my $xpos; my @ypos; my $hullpos; open( DAT, "<$datfile" ) or die( "Cannot read $datfile" ); my @dat = <DAT>; close( DAT ); @statlabels = split( /\s+/, $dat[0] ); # find the x and y label positions if( $xstat =~ /^param(\d+)/ ) { if( $1 < 1 ) { die( "Can't have --x param$1" ); } $xpos = $1 - 1; $xparam = 1; } for( my $i = 0; $i <= $#ystat; $i++ ) { if( $ystat[$i] =~ /^param(\d+)/ ) { if( $1 < 1 ) { die( "Can't have --y param$1" ); } $ypos[$i] = $1 - 1; $yparam[$i] = 1; $yposes{"$i-$datfile"} = $ypos[$i]; } } if( $hulllabel =~ /^param(\d+)/ ) { if( $1 < 1 ) { die( "Can't have --hulllabel param$1" ); } $hullpos = $1 - 1; $hullparam = 1; } # look for ops (only done first time around if( $xstat =~ /(\(?)([^\+\-\*\/]*)([\*\+\-\/].*)$/ ) { if( defined $1 ) { $xparen = $1; } else { $xparen = ""; } $xstat = $2; $xop = $3; @xopsplit = &get_opsplit( $xop ); } for( my $i = 0; $i <= $#ystat; $i++ ) { if( $ystat[$i] =~ /(\(?)([^\+\-\*\/]*)([\*\+\-\/].*)$/ ) { if( defined $1 ) { $yparen[$i] = $1; } else { $yparen[$i] = ""; } $ystat[$i] = $2; $yop[$i] = $3; # split later on demand } } if( $hulllabel =~ /(\(?)([^\+\-\*\/]*)([\*\+\-\/].*)$/ ) { if( defined $1 ) { $hullparen = $1; } else { $hullparen = ""; } $hulllabel = $2; $hullop = $3; @hullopsplit = &get_opsplit( $hullop ); } for( my $i = 0; $i <= $#statlabels; $i++ ) { my $l = $statlabels[$i]; my $stat = "#"; if( $l =~ /^\d+\)([^\(]*)(\(|$)/ ) { $stat = $1; } if( !$xparam && ($l =~ /^\d+\)($xstat)(\(|$)/ || $l =~ /^$xstat\)([^\(]*)(\(|$)/ ) ) { $xstat = $1; $xpos = $i; } elsif( $l =~ /^param(\d+)\)($xstat)(\(|$)/ ) { # we have ourselves a parameter. $xparam = 1; $xpos = $1 - 1; } # if there's a stat in the op, check it against this guy as well if( defined $xop && index( $xop, $stat ) != -1 ) { $xposes{"$index$stat"} = $i; } for( my $j = 0; $j <= $#ystat; $j++ ) { if( !$yparam[$j] && ($l =~ /^\d+\)($ystat[$j])(\(|$)/ || $l =~ /^$ystat[$j]\)([^\(])*(\(|$)/ ) ) { $ystat[$j] = $1; $ypos[$j] = $i; } elsif( $l =~ /^param(\d+)\)($ystat[$j])(\(|$)/ ) { # we have ourselves a parameter. $ypos[$j] = $1 - 1; $yparam[$j] = 1; $yposes{"$j-$datfile"} = $ypos[$j]; } if( defined $yop[$j] && index( $yop[$j], $stat ) != -1 ) { $yposes{"$j-$index$stat"} = $i; } } if( !$hullparam && ($l =~ /^\d+\)($hulllabel)(\(|$)/ || $l =~ /^$hulllabel\)([^\(]*)(\(|$)/ ) ) { $hulllabel = $1; $hullpos = $i; } elsif( $l =~ /^param(\d+)\)($hulllabel)(\(|$)/ ) { # we have ourselves a parameter. $hullparam = 1; $hullpos = $1 - 1; } # if there's a stat in the op, check it against this guy as well if( defined $hullop && index( $hullop, $stat ) != -1 ) { $hullposes{"$index$stat"} = $i; } } {;} # stupid emacs can't handle reg expressions very well if( !defined $xpos ) { die( "$xstat not a valid label in $datfile\n"); } $xposes{$datfile} = $xpos; for( my $j = 0; $j <= $#ystat; $j++ ) { if( !defined $ypos[$j] ) { die( "$ystat[$j] not a valid label in $datfile\n"); } $yposes{"$j-$datfile"} = $ypos[$j]; } if( !defined $hullpos ) { die( "$hulllabel not a valid label in $datfile\n"); } $hullposes{$datfile} = $hullpos; # if we're plotting vs some parameter, we have to rewrite the data with # that parameter along with the others if( $xparam or grep( /1/, @yparam ) or $hullparam ) { my $last_valx = -1; my @last_valy = (); my $last_valhull = -1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -