File: tracemunge.sh

package info (click to toggle)
zmailer 2.99.51.52pre3-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 16,596 kB
  • ctags: 7,422
  • sloc: ansic: 90,470; sh: 3,608; makefile: 2,784; perl: 1,585; python: 115; awk: 22
file content (81 lines) | stat: -rwxr-xr-x 1,365 bytes parent folder | download | duplicates (3)
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
#! /bin/sh
# Replaces addresses ($3 on '-' and $4 on '+' with unique block numbers
# to minimize the number of blocks presently allocated.
# For trace driven simulation of mallocs.
# Mark Moraes, University of Toronto.
gawk 'BEGIN {
	nextfree = 0;
}
/^[?!]/ {
	print
	next
}
/^\+ / {
	if (nfree > 0) {
		# if we have some existing free blocks numbers, pick one
		for(i in freenums) {
			delete freenums[i];
			nfree--;
			break;
		}
	} else {
		# new block number
		i = nextfree;
		nextfree++;
	}
	if ($4 in blks) {
		print "! block allocated again without free:", $0;
	}
	blks[$4] = i;
	print $1, $2, $3, $4, i;
	next;
}
/^\+\+ / {
	if ($4 in blks) {
		print $0, blks[$4]
	} else {
		print "! realloc on unallocated block:", $0;
	}
	next
}
/^- / {
	if (newblk != 0) {
		print "--", $2, $3;
		newblk = 0;
	} else if ($3 in blks) {
		i = blks[$3];
		delete blks[$3];
		freenums[i] = i;
		nfree++;
		print $1, $2, $3, i;
	} else {
		print "! freeing block that wasnt allocated:", $0;
	}
	next;
}
/^sbrk / {
	newblk = $2;
	heap += newblk;
	next;
}
/^heapstart / {
	print;
	heapstart = $2;
	next;
}
$0 ~ /^allocheader / || $0 ~ /^freeheader / || $0 ~ /^heapend / || $0 ~ /^no-op/ {
	print;
	next;
}
/^wordsize / {
	wdsize = $2;
	print;
	next;
}
{
	print "?", $0;
}
END {
	printf "! %d blocks used\n", nextfree;
	printf "! heap grew to %d bytes\n", wdsize * heap;
}' $@