trace-parse.pl 8.51 KB
Newer Older
1 2 3
#!/usr/bin/perl
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2011 University of Utah and the Flux Group.
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
# All rights reserved.
#

use Getopt::Std;

sub usage()
{
    exit(1);
}
my $optlist = "pi:cT:j";

my $plotem = 0;
my $plotinterval = 500000;	# us between data points
my $nextplot = -1;
my ($netfd, $dcfd, $diskfd);
my $cumulative = 0;
my $dojpeg = 0;
my $ptitle;

my $isclient;
my $netstart;
my ($gotevents, $totevents, $starttime, $tracelevel);
my $laststamp;
my $lineno = 0;

my ($c_blocks, $c_blocksize);
my ($c_firstrecv, $c_lastrecv, $c_recvbytes);
my ($c_firstdecomp, $c_lastdecomp, $c_decompbytes);
my ($c_firstwrite, $c_lastwrite, $c_writebytes);
my ($c_prevstamp, $c_prevrbytes, $c_prevdbytes, $c_prevwbytes);
35
my ($c_fsyncstart, $c_fsyncend);
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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215

#
# Parse command arguments.
#
%options = ();
if (! getopts($optlist, \%options)) {
    usage();
}
if (defined($options{"c"})) {
    $cumulative = 1;
    $plotinterval = 100000;
}
if (defined($options{"h"})) {
    usage();
}
if (defined($options{"i"})) {
    $plotinterval = int($options{"i"});
}
if (defined($options{"j"})) {
    $dojpeg = 1;
}
if (defined($options{"p"})) {
    $plotem = 1;
}
if (defined($options{"T"})) {
    $ptitle = $options{"T"};
}

while (@ARGV) {
    my $file = shift @ARGV;
    processfile($file);
}

#
# Round up a time in seconds to the next plot interval value.
#
sub
plotroundup($)
{
    my $val = shift;

    $val = int($val * 1000000) + $plotinterval;
    $val = int($val / $plotinterval) * $plotinterval;
    return $val / 1000000.0;
}

sub
processfile($)
{
    my ($file) = @_;
    my ($netfile, $dcfile, $diskfile);

    if (!open(FD, "$file")) {
	printf STDERR "$file: $!\n";
	return 1;
    }

    if ($plotem) {
	$netfile = "$ptitle-net.data";
	$dcfile = "$ptitle-dcomp.data";
	$diskfile = "$ptitle-disk.data";
	if (!open($netfd, ">$netfile") || !open($dcfd, ">$dcfile") ||
	    !open($diskfd, ">$diskfile")) {
	    printf STDERR "WARNING: can't open a plot file, not generating\n";
	    $plotem = 0;
	} else {
	    $nextplot = 0;
	}
    }

    $lineno = 0;
    while (<FD>) {
	chomp;
	$lineno++;

	# header
	if (/(\d+) of (\d+) events, start=(\d+\.\d+), level=(\d+):/) {
	    if (defined($gotevents)) {
		print STDERR "$lineno: two event lines; tracefile has mulitple runs?\n";
		exit(1);
	    }
	    $gotevents = $1;
	    $totevents = $2;
	    $starttime = $3;
	    $tracelevel = $4;

	    if ($gotevents != $totevents) {
		print STDERR "$lineno: WARNING: only $gotevents of $totevents events recorded; all bets off!\n";
	    }
	    next;
	}

	# client event record
	if (/\s+\+(\d+\.\d+): C: (\d+\.\d+\.\d+\.\d+): (.*)/) {
	    $laststamp = $1;
	    processclient($1, $2, $3);
	    next;
	}

	# server event record
	if (/\s+\+(\d+\.\d+): S: (.*)/) {
	    $laststamp = $1;
	    processserver($1, $2);
	    next;
	}

	print STDERR "Record in unrecognized format:\n    $_\n";
    }
    finishclient($laststamp);
    finishserver($laststamp);

    close(FD);

    if ($plotem) {
	#
	# Round end of net/decompress activity up to interval boundaries
	# so we can show them on the graph
	#
	my $nstart = plotroundup($c_firstrecv);
	my $nstop = plotroundup($c_lastrecv);
	my $dstart = plotroundup($c_firstdecomp);
	my $dstop = plotroundup($c_lastdecomp);
	my $wstart = plotroundup($c_firstwrite);
	my $wstop = plotroundup($c_lastwrite);

	my $gnpfile = "$ptitle.gnp";
	if (!open(PD, ">$gnpfile")) {
	    printf STDERR "$gnpfile: WARNING: cannot open ($!), not generating\n";
	} else {
	    # XXX
	    my $ylim = $cumulative ? 40 : 100;

	    if ($dojpeg) {
		print PD
		    "set terminal jpeg medium\n",
		    "set output '$ptitle.jpg'\n";
	    } else {
		print PD
		    "set terminal postscript color\n",
		    "set output '$ptitle.ps'\n";
	    }
	    print PD
		"set yrange [0:$ylim]\n",
		"set xlabel 'Elapsed time (sec)'\n",
		"set ylabel 'Throughput (MB/sec)'\n",
		"set key top left\n",
		"set title '$ptitle'\n",
		"set arrow from $nstart, graph 0 to $nstart, graph 1 nohead lt 1\n",
		"set arrow from $nstop, graph 0 to $nstop, graph 1 nohead lt 1\n",
		"set arrow from $dstart, graph 0 to $dstart, graph 1 nohead lt 2\n",
		"set arrow from $dstop, graph 0 to $dstop, graph 1 nohead lt 2\n",
		"set arrow from $wstart, graph 0 to $wstart, graph 1 nohead lt 3\n",
		"set arrow from $wstop, graph 0 to $wstop, graph 1 nohead lt 3\n",
		"plot '$netfile' title 'net read' with lines, ",
		"'$dcfile' title 'decompress' with lines, ",
		"'$diskfile' title 'disk write' with lines\n";
	    close(PD);
	}
	close($netfd);
	close($dcfd);
	close($diskfd);
    }
}

sub
processclient($$$)
{
    my ($stamp, $ip, $msg) = @_;

    if (!defined($ptitle)) {
	$ptitle = $ip;
    }

    if ($nextplot >= 0) {
	while (($stamp * 1000000) > $nextplot) {
	    plotclient($nextplot);
	    $nextplot += $plotinterval;
	}
    }

216 217
    if ($msg =~ /^got JOIN reply, chunksize=(\d+), blocksize=(\d+), imagebytes=(\d+)/) {
	$c_blocks = int($3 / $2);
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
	$c_blocksize = $2;
    }

    if ($msg =~ /^send REQUEST, (\d+)\[(\d+)-(\d+)\]/) {
	;
    }

    if ($msg =~ /^got block, wait=(\d+\.\d+), (\d+) good blocks recv \((\d+) total\)/) {
	if ($tracelevel >= 4) {
	    $c_firstrecv = $stamp
		if (!defined($c_firstrecv));
	    $c_lastrecv = $stamp;
	}
	$c_recvbytes = $2 * $c_blocksize;
    }

    if ($msg =~ /^start chunk (\d+), block (\d+), (\d+) chunks in progress \(goodblks=(\d+)\)/) {
	if ($tracelevel < 4) {
	    $c_firstrecv = $stamp
		if (!defined($c_firstrecv));
	    $c_lastrecv = $stamp;
	}
	$c_recvbytes = $4 * $c_blocksize;
    }

    if ($msg =~ /^end chunk (\d+), block (\d+), (\d+) chunks in progress \(goodblks=(\d+)\)/) {
	$c_recvbytes = $4 * $c_blocksize;	
    }
    if ($msg =~ /^decompressing chunk (\d+), idle=(\d+), \(dblock=(\d+), widle=(\d+)\)/) {
	$c_firstdecomp = $stamp
	    if (!defined($c_firstdecomp));
    }
250
    if ($msg =~ /^chunk (\d+) \(\d+ bytes\) decompressed, (\d+) left/) {
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
	$c_lastdecomp = $stamp;
    }
    if ($msg =~ /^decompressed (\d+) bytes total/) {
	$c_decompbytes = $1;
    }

    if ($msg =~ /^writer STARTED, (\d+) bytes written/) {
	$c_firstwrite = $stamp
	    if (!defined($c_firstwrite));
	$c_lastwrite = $stamp;
	$c_writebytes = $1;
    }
    if ($msg =~ /^writer RUNNING, (\d+) bytes written/) {
	$c_lastwrite = $stamp;
	$c_writebytes = $1;
    }
    if ($msg =~ /^writer IDLE, (\d+) bytes written/) {
	$c_lastwrite = $stamp;
	$c_writebytes = $1;
    }
271 272 273 274 275 276
    if ($msg =~ /^fsync START/) {
	$c_fsyncstart = $stamp;
    }
    if ($msg =~ /^fsync END/) {
	$c_fsyncend = $stamp;
    }
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
}

sub
nz($)
{
    my ($val) = @_;
    return ($val == 0 ? 1 : $val);
}

sub
plotclient($)
{
    my ($stamp) = @_;
    my ($rbytes, $dbytes, $wbytes, $ilen);

    if ($cumulative) {
	$rbytes = $c_recvbytes;
	$dbytes = $c_decompbytes;
	$wbytes = $c_writebytes;
	$ilen = $stamp / 1000000;

    } else {
	$rbytes = $c_recvbytes - $c_prevrbytes;
	$dbytes = $c_decompbytes - $c_prevdbytes;
	$wbytes = $c_writebytes - $c_prevwbytes;
	$ilen = $plotinterval / 1000000;
    }
    $c_prevrbytes = $c_recvbytes;
    $c_prevdbytes = $c_decompbytes;
    $c_prevwbytes = $c_writebytes;

    printf({$netfd} "%.3f: %.6f\n",
	   $stamp / 1000000, $rbytes / nz($ilen) / 1000000);
    printf({$dcfd} "%.3f: %.6f\n",
	   $stamp / 1000000, $dbytes / nz($ilen) / 1000000);
    printf({$diskfd} "%.3f: %.6f\n",
	   $stamp / 1000000, $wbytes / nz($ilen) / 1000000);
}

sub
finishclient($)
{
    my ($stamp) = @_;
    my $etime;

322 323 324 325
    if ($c_decompbytes == 0) {
	print STDERR "WARNING: no decompression count, try -tt\n";
    }

326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
    if ($nextplot >= 0) {
	while (($stamp * 1000000) > $nextplot) {
	    plotclient($nextplot);
	    $nextplot += $plotinterval;
	}
    }
    $etime = $c_lastrecv - $c_firstrecv;
    my $rbytes = $c_blocks * $c_blocksize;
    printf("Receive:    %.2f MB/sec: %d bytes (%d %dK blocks) in %.3f sec (%.3f to %.3f)\n",
	   $rbytes / nz($etime) / 1000000.0,
	   $rbytes, $c_blocks, $c_blocksize/1024,
	   $etime, $c_firstrecv, $c_lastrecv);

    $etime = $c_lastdecomp - $c_firstdecomp;
    printf("Decompress: %.2f MB/sec: %d->%d bytes in %.3f sec (%.3f to %.3f)\n",
	   $c_decompbytes / nz($etime) / 1000000.0,
	   $rbytes, $c_decompbytes, $etime, $c_firstdecomp, $c_lastdecomp);

344 345 346
    if (($c_fsyncend - $c_fsyncstart) * 1000 >= 1) {
	$c_lastwrite = $c_fsyncend;
    }
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
    $etime = $c_lastwrite - $c_firstwrite;
    printf("Write:      %.2f MB/sec: %d bytes in %.3f sec (%.3f to %.3f)\n",
	   $c_writebytes / nz($etime) / 1000000.0,
	   $c_writebytes, $etime, $c_firstwrite, $c_lastwrite);
}

sub
processserver($$)
{
    my ($stamp, $msg) = @_;
    my $clientip = undef;

    if ($msg =~ /(\d+\.\d+\.\d+\.\d+): (.*)/) {
	$clientip = $1;
	$msg = $2;
    }
}

sub
finishserver($)
{
    my ($stamp) = @_;
}

exit(0);