Debian Codegraph @

bin/raw2gp

raw
1 eval 'exec perl -I ./bin -S $0 ${1+"$@"}' #-*-Perl-*-
2 if 0;
3
4 require 5.001;
5
6 ($progname) = ($0 =~ m!([^/]+)$!);
7 sub usage {
8 die <<END;
9 usage: $progname [options] [trace files...]
10
11 options:
12 -a plot acks
13 -s SCALE scale TCP sequence numbers by SCALE
14 -m MODULUS treat TCP sequence numbers as mod MODULUS
15 -g use gnuplot
16 -q show queueing delay by connecting lines (only for xgraph)
17 # -l show packet length
18
19 Traditional ``wrapping'' ns plots (as called from the test scripts)
20 can be generated with -s 0.01 -m 90.
21 END
22 };
23
24 require 'getopts.pl';
25 &Getopts('ags:m:ql') || usage;
26
27 # calculate offsets. Do we need this?
28 # $offset = int($modulus / 10 + 1) * 10;
29 # $offset = 1;
30
31 # Default options args
32 $modulus = defined($opt_m) ? $opt_m : 2 ** 31;
33 $scale = defined($opt_s) ? $opt_s : 1;
34 $plot_acks = defined($opt_a);
35
36 # XXXXXX
37 # XXX This is going to break because we have to set @INC correctly
38 # XXX We need a clean way to set this for all scripts.
39 # XXXXXX
40 require 'dynamics.pl';
41 if (defined($opt_g)) {
42 require 'gnuplot.pl';
43 if (defined($opt_q)) {
44 warn 'ouch';
45 undef $opt_q;
46 }
47 } else {
48 require 'xgraph.pl';
49 }
50
51 $maxY = 0;
52 @p = @a = @d = (); # @p: list of "$x $y" pairs for data packets
53 # @a: list of "$x $y" pairs for acks
54 # @d: .. drops
55 %q_time_seg = ();
56
57
58 $file = $acks = '';
59
60 sub translate_point {
61 my($time, $seq, $flow) = @_;
62 return ($time, $flow + ($seq % $modulus) * $scale);
63 }
64
65 ($minY, $maxY) = (9999999, -9999999);
66 while (<>) {
67 $dfile = $ARGV;
68 next if /rtProto/;
69 @F = split;
70 /testName/ && do {
71 $file = $F[2];
72 $file =~ s/_/-/g;
73 next;
74 };
75 /^[\+-] / && do {
76 $maxY = $F[7] if ($maxY < $F[7]);
77 $is_ack = ($F[4] eq 'ack');
78 next if ($is_ack && !$plot_acks);
79
80 ($x, $y) = translate_point(@F[1, 10, 7]);
81 if (defined($opt_q)) { # XXX intense xgraph-ism here
82 if (/^\+/) {
83 $statement = undef;
84 $q_time_seg{$is_ack,$y} = $x;
85 };
86 $statement = "move $q_time_seg{$is_ack,$y} $y\ndraw $x $y\n"
87 if (/^\-/);
88 } else {
89 $statement = "$x $y\n";
90 };
91 if (defined($statement)) {
92 if ($is_ack) {
93 push(@a, $statement);
94 } else {
95 push(@p, $statement);
96 };
97 };
98 $minY = $y if ($minY > $y);
99 $maxY = $y if ($maxY < $y);
100 next;
101 };
102 /^d / && do {
103 ($x, $y) = translate_point(@F[1, 10, 7]);
104 push(@d, "$x $y\n");
105 $minY = $y if ($minY > $y);
106 $maxY = $y if ($maxY < $y);
107 next;
108 };
109 /^v / && (parseDynamics(@F), next);
110 }
111
112 if ($file eq '') {
113 ($file) = ($dfile =~ m!([^/]+)$!);
114 }
115
116 plotPreamble(STDOUT, $file, 'time', ($#p < $[ ? '0:2' : ''), 'packets', '');
117 plot(STDOUT, 0, 'packets', 'w points 1 5', @p);
118
119 if ($opt_g) {
120 plot(STDOUT, 0, 'acks', 'w dots', @a);
121 } else {
122 # for xgraphs, insert dummy data sets so we get X's for marks in data-set 4
123 plot(STDOUT, 0, 'acks', 'plot 2', "0 1\n", @a);
124 }
125
126 plot(STDOUT, 0, 'drops', 'w points 1 4', @d);
127 plotDynamics(STDOUT, $minY, $maxY);
128 plotPostamble(STDOUT);
129
130 exit;