- name output PNG file based on input filename

This commit is contained in:
farrokhi 2014-07-26 12:08:40 +04:30
parent ced02e2365
commit 9ead8e4165

View File

@ -2,6 +2,7 @@
use strict; use strict;
use warnings; use warnings;
use File::Basename;
use Net::Pcap; use Net::Pcap;
use NetPacket::IP; use NetPacket::IP;
use Getopt::Std; use Getopt::Std;
@ -126,18 +127,17 @@ sub dump_data_double {
sub create_graph { sub create_graph {
my ($dataset) = @_; my $dataset = shift;
my $filename = shift . "-" . $dataset . ".png";
my $ylabel = ""; my $ylabel = "";
my $filename = "";
my $lddinecolor = ""; my $lddinecolor = "";
my $plotline = ""; my $plotline = "";
my $title = ""; my $title = "";
if ($dataset eq 'pps') if ($dataset eq 'pps')
{ {
$ylabel = "Packets"; $ylabel = "Packets";
$filename = "pps";
$title = "Packet Traffic Volume"; $title = "Packet Traffic Volume";
if ($duplex) # full duplex graph if ($duplex) # full duplex graph
@ -153,7 +153,6 @@ sub create_graph {
if ($dataset eq 'bps') if ($dataset eq 'bps')
{ {
$ylabel = "Bits"; $ylabel = "Bits";
$filename = "bps";
$title = "Traffic Volume"; $title = "Traffic Volume";
if ($duplex) # full duplex graph if ($duplex) # full duplex graph
@ -180,12 +179,12 @@ set size 2,1.6
set size ratio 0.4 set size ratio 0.4
set ylabel "$ylabel" set ylabel "$ylabel"
set xlabel "Time (Seconds)" set xlabel "Time (Seconds)"
set style line 1 lc rgb '#4d0000' lt 1 lw 3 set style line 1 lc rgb '#6d0000' lt 1 lw 3
set style line 2 lc rgb '#00004d' lt 1 lw 3 set style line 2 lc rgb '#0000cc' lt 1 lw 3
$plotline $plotline
END_MESSAGE 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; print GNUPLOT $gpi;
close(GNUPLOT); close(GNUPLOT);
} }
@ -254,6 +253,8 @@ if ($pktcount < 2) {
exit(); exit();
} }
my($filename, $dirs, $suffix) = fileparse($inputfile, qr/\.[^.]*/);
if (defined $opts{p}) if (defined $opts{p})
{ {
print("Creating PPS graph..."); print("Creating PPS graph...");
@ -263,9 +264,9 @@ if (defined $opts{p})
} }
else else
{ {
dump_data_single(\@pps_src); dump_data_single(\@pps_src, $filename);
} }
create_graph('pps'); create_graph('pps', $filename);
print("Done.\n"); print("Done.\n");
} }
@ -274,12 +275,12 @@ if (defined $opts{b})
print("Creating BPS graph..."); print("Creating BPS graph...");
if ($duplex) if ($duplex)
{ {
dump_data_double(\@bps_src,\@bps_dst); dump_data_double(\@bps_src, \@bps_dst, $filename);
} }
else else
{ {
dump_data_single(\@bps_src); dump_data_single(\@bps_src, $filename);
} }
create_graph('bps'); create_graph('bps', $filename);
print("Done.\n"); print("Done.\n");
} }