From 9ead8e416545665273d929fdb99ec0436a1be029 Mon Sep 17 00:00:00 2001 From: farrokhi Date: Sat, 26 Jul 2014 12:08:40 +0430 Subject: [PATCH] - name output PNG file based on input filename --- prototype/pcaputil.pl | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/prototype/pcaputil.pl b/prototype/pcaputil.pl index cf3e60d..674f571 100755 --- a/prototype/pcaputil.pl +++ b/prototype/pcaputil.pl @@ -2,6 +2,7 @@ use strict; use warnings; +use File::Basename; use Net::Pcap; use NetPacket::IP; use Getopt::Std; @@ -126,18 +127,17 @@ sub dump_data_double { sub create_graph { - my ($dataset) = @_; + my $dataset = shift; + my $filename = shift . "-" . $dataset . ".png"; + my $ylabel = ""; - my $filename = ""; my $lddinecolor = ""; my $plotline = ""; my $title = ""; - if ($dataset eq 'pps') { $ylabel = "Packets"; - $filename = "pps"; $title = "Packet Traffic Volume"; if ($duplex) # full duplex graph @@ -153,7 +153,6 @@ sub create_graph { if ($dataset eq 'bps') { $ylabel = "Bits"; - $filename = "bps"; $title = "Traffic Volume"; if ($duplex) # full duplex graph @@ -180,12 +179,12 @@ set size 2,1.6 set size ratio 0.4 set ylabel "$ylabel" set xlabel "Time (Seconds)" -set style line 1 lc rgb '#4d0000' lt 1 lw 3 -set style line 2 lc rgb '#00004d' lt 1 lw 3 +set style line 1 lc rgb '#6d0000' lt 1 lw 3 +set style line 2 lc rgb '#0000cc' lt 1 lw 3 $plotline END_MESSAGE - open(GNUPLOT, "| gnuplot | epstopdf -f | convert -density 300 - $filename.png"); + open(GNUPLOT, "| gnuplot | epstopdf -f | convert -colorspace rgb -density 300 - PNG32:$filename"); print GNUPLOT $gpi; close(GNUPLOT); } @@ -254,18 +253,20 @@ if ($pktcount < 2) { exit(); } +my($filename, $dirs, $suffix) = fileparse($inputfile, qr/\.[^.]*/); + if (defined $opts{p}) { print("Creating PPS graph..."); if ($duplex) { - dump_data_double(\@pps_src,\@pps_dst); + dump_data_double(\@pps_src, \@pps_dst); } else { - dump_data_single(\@pps_src); + dump_data_single(\@pps_src, $filename); } - create_graph('pps'); + create_graph('pps', $filename); print("Done.\n"); } @@ -274,12 +275,12 @@ if (defined $opts{b}) print("Creating BPS graph..."); if ($duplex) { - dump_data_double(\@bps_src,\@bps_dst); + dump_data_double(\@bps_src, \@bps_dst, $filename); } else { - dump_data_single(\@bps_src); + dump_data_single(\@bps_src, $filename); } - create_graph('bps'); + create_graph('bps', $filename); print("Done.\n"); }