Debian Codegraph @

bin/raw2xg

raw
1 eval 'exec perl -S $0 ${1+"$@"}' # -*-perl-*-
2 if 0;
3
4 require 5.001;
5
6 ($progname) = ($0 =~ m!([^/]+)$!);
7 sub usage {
8 print STDERR <<END;
9 usage: $progname [options] [trace files...]
10
11 options:
12 -a plot acks
13 -s SCALE scale TCP sequence numbers by SCALE
14 -n FACTOR scale flow number by FACTOR
15 -m MODULUS treat TCP sequence numbers as mod MODULUS
16 -q show queueing delay by connecting lines
17 -l show packet length
18 -t TITLE title of test
19 -e plot ecn flags
20 -d plot only drops and ECN marks
21 -v plot events
22 -c leave out empty lists
23 -x really leave out ALL of the empty lists
24 -f plot acks from tcp-full
25 -g for plotting acks from tcp-full, one direction has source 0
26 -p don't add the x-graph preface
27 -y fix the y-axis when there are no drops
28 -r plot arrivals only
29
30 Traditional ``wrapping'' ns plots (as called from the test scripts)
31 can be generated with -s 0.01 -m 90.
32 END
33 exit 1;
34 };
35 $usage = "usage: $progname [-a] [trace files...]\n";
36
37 require 'getopts.pl';
38 &Getopts('acefgds:m:n:qrplvt:xy') || usage;
39
40 $c = 0;
41 @p = @pc = @pg = @a = @ac = @ae = @d = @lu = @ld = ();
42 @vto = @vss = @vfr = @vrfr = @vnrfr = @vfc = ();
43 %q_time_seg = ();
44 $scale = defined($opt_s) ? $opt_s : 1;
45 $modulus = defined($opt_m) ? $opt_m : 2 ** 31;
46 $flow_factor = defined($opt_n) ? $opt_n : 1;
47 $plot_acks = defined($opt_a);
48 $plot_ecn = defined($opt_e);
49 $plot_drops = defined($opt_d);
50 $plot_event = defined($opt_v);
51 $no_padding = defined($opt_c);
52 $really_no_padding = defined($opt_x);
53 $plot_full = defined($opt_f);
54 $source_zero = defined($opt_g);
55 $no_title = defined($opt_p);
56 $last_line = defined($opt_y);
57 $plot_arrivals = defined($opt_r);
58
59 $file = $acks = '';
60
61 sub translate_point {
62 my($time, $seq, $flow) = @_;
63 if ($seq == -1) {$seq = 0;}
64 $plotted = $flow * $flow_factor + ($seq % $modulus) * $scale;
65 $plotted =~ s/\.e/e/g; # to ensure Cygwin compatibility,
66 return ($time, $plotted);
67 }
68
69 while (<>) {
70 $dfile = $ARGV;
71 @F = split;
72 /testName/ && ($file = $F[2], next);
73 /^[\+-] / && do {
74 $c = $F[7] if ($c < $F[7]);
75 $is_ack = ($F[4] eq 'ack' || $F[4] eq 'tcpFriendCtl');
76 $is_ecn = ($F[6] =~ /E/);
77 $is_cong = ($F[6] =~ /A/);
78 $is_echo = ($F[6] =~ /C/);
79 $is_tcp = ($F[4] eq 'tcp');
80 $source_0 = ($F[8] eq '0.0');
81 $large_pkt = ($F[5] > 40);
82 next if ($is_ack && !$plot_acks);
83 next if (($F[0] eq "-") && $plot_arrivals);
84 ### if ($large_pkt) { print("Large");} else {print("Small");}
85
86 $use_full = 0;
87 if ($plot_full){ $use_full = 1;}
88 ## if ($plot_full){if ($large_pkt) { $use_full = 1;}}
89 ##if (!$source_zero) { $use_full = 1;
90 ## } else { if ($source_0) { if ($is_tcp) { $use_full = 1; }
91 ## }}}
92 if ($use_full == 1){
93 ## ($plot_full && (!$source_zero || ($source_0 && $is_tcp)))
94 ## F[10]: seq. no.; F[12]: ack no.;
95 ($x, $y) = translate_point(@F[1, 12, 7]);
96 } else {
97 ($x, $y) = translate_point(@F[1, 10, 7]);
98 }
99 if (defined($opt_q)) {
100 if (/^\+/) {
101 $statement = undef;
102 $q_time_seg{$is_ack,$y} = $x;
103 };
104 $statement = "move $q_time_seg{$is_ack,$y} $y\ndraw $x $y\n"
105 if (/^\-/);
106 } else {
107 $statement = "$x $y\n";
108 };
109 if (defined($statement)) {
110 if ($plot_drops) {
111 if ($is_ecn) {
112 push(@pc, $statement);
113 };
114 } else {
115 if ($is_ack) {
116 if ($is_ecn) {
117 push(@ac, $statement);
118 } else {
119 push(@a, $statement);
120 };
121 if ($is_echo) {
122 push(@ae, $statement);
123 };
124 } else {
125 if ($is_ecn) {
126 push(@pc, $statement);
127 } else {
128 push(@p, $statement);
129 };
130 if ($is_cong) {
131 push(@pg, $statement);
132 }
133 };
134 };
135 };
136 next;
137 };
138 /^d / && do {
139 ($x, $y) = translate_point(@F[1, 10, 7]);
140 push(@d, "$x $y\n");
141 next;
142 };
143 /link-down/ && (push(@ld, $F[1]), next);
144 /link-up/ && (push(@lu, $F[1]), next);
145 if ($plot_event) {
146 /^E / && do {
147 ($x, $y) = translate_point(@F[1, 7, 6]);
148 if ($F[5] eq 'TCP_TIMEOUT') {
149 push(@vto, "$x $y\n");
150 next;
151 }
152 if ($F[5] eq 'SLOW_START') {
153 push(@vss, "$x $y\n");
154 next;
155 }
156 if ($F[5] eq 'FAST_RETX') {
157 push(@vfr, "$x $y\n");
158 next;
159 }
160 if ($F[5] eq 'RENO_FAST_RETX') {
161 push(@vrfr, "$x $y\n");
162 next;
163 }
164 if ($F[5] eq 'NEWRENO_FAST_RETX') {
165 push(@vnrfr, "$x $y\n");
166 next;
167 }
168 if ($F[5] eq 'FAST_RECOVERY') {
169 push(@vfc, "$x $y\n");
170 next;
171 }
172 };
173 }
174 }
175
176 if ($file eq '') {
177 ($file) = ($dfile =~ m!([^/]+)$!);
178 }
179
180 if (!$no_title) {
181 $title = defined($opt_t) ? $opt_t : $file;
182 print "TitleText: $title\n" .
183 "Device: Postscript\n" .
184 "BoundBox: true\n" .
185 "Ticks: true\n" .
186 (defined($opt_q) ? "" : "NoLines: true\n") .
187
188 "Markers: true\n" .
189 "XUnitText: time\n" .
190 "YUnitText: packets\n";
191 }
192
193 print "\n\"packets\n", @p;
194
195
196
197 if (defined($pc[0])) {
198 @sorted_pc = sort (@pc);
199 print "\n\"ecn_packets\n", @pc[0..3], @sorted_pc;
200 } else {
201 if (!$no_padding) {
202 printf "\n\"skip-1\n0 1\n";
203 }
204 }
205
206 # insert dummy data sets so we get X's for marks in data-set 4
207 if (!$really_no_padding && !defined($a[0])) {
208 push(@a, "0 1\n");
209 }
210 if ($plot_acks) {
211 @sorted_a = sort (@a);
212 print "\n\"acks\n", @sorted_a;
213 if ($plot_ecn && defined($ac[0])) {
214 @sorted_ac = sort (@ac);
215 print "\n\"ecn-acks\n", @sorted_ac;
216 }
217 if ($plot_ecn && defined($ae[0])) {
218 @sorted_ae = sort (@ae);
219 print "\n\"echo-acks\n", @sorted_ae;
220 }
221 } else {
222 if (!$no_padding) {
223 printf "\n\"skip-2\n0 1\n";
224 }
225 }
226
227 #
228 # Repeat the first line twice in the drops file because often we have only
229 # one drop and xgraph won't print marks for data sets with only one point.
230 #
231 @sorted_d = sort (@d);
232 print "\n\"drops\n", @d[0..3], @sorted_d;
233
234 if ($plot_event) {
235 # Event tracing
236 print "\n\"events\n";
237 @sorted_vto = sort (@vto);
238 print "\n\"event_timeout\n", @vto[0..3], @sorted_vto;
239 @sorted_vss = sort (@vss);
240 print "\n\"event_slowstart\n", @vss[0..3], @sorted_vss;
241 @sorted_vfr = sort (@vfr);
242 print "\n\"event_fastretx\n", @vfr[0..3], @sorted_vfr;
243 @sorted_vrfr = sort (@vrfr);
244 print "\n\"event_renofastretx\n", @vrfr[0..3], @sorted_vrfr;
245 @sorted_vnrfr = sort (@vnrfr);
246 print "\n\"event_nrenofastretx\n", @vnrfr[0..3], @sorted_vnrfr;
247 @sorted_vfc = sort (@vfc);
248 print "\n\"event_fastrecovery\n", @vfc[0..3], @sorted_vfc;
249 }
250
251
252
253 $c++;
254 print "\n";
255 foreach $i (@ld) {
256 print "\"link-down\n$i 0\n$i $c\n";
257 }
258 foreach $i (@lu) {
259 print "\"link-up\n$i 0\n$i $c\n";
260 }
261
262 if ($plot_ecn && defined($pg[0])) {
263 if (!$really_no_padding && !defined($d[0])) {
264 printf "\n\"skip-3\n0 1\n";
265 }
266 @sorted_pg = sort (@pg);
267 print "\n\"cong_act_packets\n", @pg[0..3], @sorted_pg;
268 }
269
270 if ($last_line) {
271 # To bring the y-axis up to 2.0
272 if (!$plot_full) {
273 printf "\n\"skip\n0 2\n";
274 } else {
275 printf "\n\"skip\n0 1024\n";
276 }
277 }
278
279 exit 0;