File: raw2gp

package info (click to toggle)
ns2 2.35%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 78,756 kB
  • ctags: 27,476
  • sloc: cpp: 172,923; tcl: 107,130; perl: 6,391; sh: 6,143; ansic: 5,846; makefile: 812; awk: 525; csh: 355
file content (130 lines) | stat: -rwxr-xr-x 2,967 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
eval 'exec perl -I ./bin -S $0 ${1+"$@"}'		#-*-Perl-*-
	if 0;

require 5.001;

($progname) = ($0 =~ m!([^/]+)$!);
sub usage {
    die <<END;
usage: $progname [options] [trace files...]

options:
    -a		plot acks
    -s SCALE    scale TCP sequence numbers by SCALE
    -m MODULUS  treat TCP sequence numbers as mod MODULUS
    -g		use gnuplot
    -q		show queueing delay by connecting lines (only for xgraph)
#    -l		show packet length

Traditional ``wrapping'' ns plots (as called from the test scripts)
can be generated with -s 0.01 -m 90.
END
};

require 'getopts.pl';
&Getopts('ags:m:ql') || usage;

# calculate offsets.  Do we need this?
# $offset = int($modulus / 10 + 1) * 10;
# $offset = 1;

# Default options args
$modulus = defined($opt_m) ? $opt_m : 2 ** 31;
$scale = defined($opt_s) ? $opt_s : 1;
$plot_acks = defined($opt_a);

# XXXXXX
# XXX This is going to break because we have to set @INC correctly
# XXX We need a clean way to set this for all scripts.
# XXXXXX
require 'dynamics.pl';
if (defined($opt_g)) {
    require 'gnuplot.pl';
    if (defined($opt_q)) {
        warn 'ouch';
        undef $opt_q;
    }
} else {
    require 'xgraph.pl';
}

$maxY = 0;
@p = @a = @d = ();		# @p:  list of "$x $y" pairs for data packets
				# @a:  list of "$x $y" pairs for acks
				# @d:  .. drops
%q_time_seg = ();


$file = $acks = '';

sub translate_point {
    my($time, $seq, $flow) = @_;
    return ($time, $flow + ($seq % $modulus) * $scale);
}

($minY, $maxY) = (9999999, -9999999);
while (<>) {
    $dfile = $ARGV;
    next if /rtProto/;
    @F = split;
    /testName/ && do {
	$file = $F[2];
	$file =~ s/_/-/g;
	next;
    };
    /^[\+-] / && do {
	$maxY = $F[7] if ($maxY < $F[7]);
	$is_ack = ($F[4] eq 'ack');
	next if ($is_ack && !$plot_acks);

	($x, $y) = translate_point(@F[1, 10, 7]);
	if (defined($opt_q)) {	# XXX intense xgraph-ism here
	    if (/^\+/) {
		$statement = undef;
		$q_time_seg{$is_ack,$y} = $x;
	    };
	    $statement = "move $q_time_seg{$is_ack,$y} $y\ndraw $x $y\n"
		if (/^\-/);
	} else {
	    $statement = "$x $y\n";
	};
	if (defined($statement)) {
	    if ($is_ack) { 
		push(@a, $statement);
	    } else {
	        push(@p, $statement);
	    };
	};
	$minY = $y if ($minY > $y);
	$maxY = $y if ($maxY < $y);
	next;
    };
    /^d / && do {
	($x, $y) = translate_point(@F[1, 10, 7]);
	push(@d, "$x $y\n");
	$minY = $y if ($minY > $y);
	$maxY = $y if ($maxY < $y);
	next;
    };
    /^v / && (parseDynamics(@F), next);
}	

if ($file eq '') {
	($file) = ($dfile =~ m!([^/]+)$!);
}

plotPreamble(STDOUT, $file, 'time', ($#p < $[ ? '0:2' : ''), 'packets', '');
plot(STDOUT, 0, 'packets', 'w points 1 5', @p);

if ($opt_g) {
    plot(STDOUT, 0, 'acks',    'w dots', @a);
} else {
    # for xgraphs, insert dummy data sets so we get X's for marks in data-set 4
    plot(STDOUT, 0, 'acks',	'plot 2', "0 1\n", @a);
}

plot(STDOUT, 0, 'drops',   'w points 1 4', @d);
plotDynamics(STDOUT, $minY, $maxY);
plotPostamble(STDOUT);

exit;