aboutsummaryrefslogtreecommitdiff
path: root/sys/symtab/stinfo.x
blob: cbc2f4418fbceee53d825bfe8e3345891e04fb04 (plain) (blame)
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
131
132
133
134
135
136
137
138
139
140
141
142
# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.

include	"symtab.h"

# STINFO -- Print interesting information on the inner workings and contents
# of the symbol table.

procedure stinfo (stp, fd, verbose)

pointer	stp			# symtab descriptor
int	fd			# output file
int	verbose			# if YES, trace each thread

pointer	index, stab, sbuf, ep
int	keylen, min_keylen, max_keylen, nsymbols, el, i, head
int	nthreads, max_threadlen, nonnull_threads, nsym
real	sum, mean_hash_index, avg_keylen, avg_threadlen
int	strlen()

begin
	index = ST_INDEX(stp)
	stab  = ST_STABP(stp)
	sbuf  = ST_SBUFP(stp)

	# Print the symbol table name.
	ep = sbuf + ST_NAME(stp)
	call fprintf (fd, "name: %s\n")
	    if (Memc[ep] == EOS)
		call pargstr ("(none given)")
	    else
		call pargstr (Memc[ep])

	# Print information on memory usage.
	call fprintf (fd,
	    "index=(%x,%d), stab=(%x,%d,%d%%), sbuf=(%x,%d,%d%%)\n")
	    call pargi (index)
	    call pargi (ST_INDEXLEN(stp))
	    call pargi (stab)
	    call pargi (ST_STABLEN(stp))
	    call pargr (ST_STABOP(stp) * 100.0 / ST_STABLEN(stp))
	    call pargi (sbuf)
	    call pargi (ST_SBUFLEN(stp))
	    call pargr (ST_SBUFOP(stp) * 100.0 / ST_SBUFLEN(stp))

	call fprintf (fd,
	    "sbuf reallocated %d times, stab reallocated %d times\n")
	    call pargi (ST_SBUFNGROW(stp))
	    call pargi (ST_STABNGROW(stp))

	# Scan the symbols and compute the min, max, and mean key lengths.
	# Count the number of symbols.

	min_keylen = MAX_SZKEY
	max_keylen = 0
	avg_keylen = 0
	nsymbols   = 0
	sum	   = 0

	for (el = ST_LASTSYMBOL(stp);  el != NULL;  el = E_NEXTGLOB(ep)) {
	    nsymbols = nsymbols + 1
	    ep = stab + el

	    keylen = strlen (Memc[sbuf+E_KEY(ep)])
	    min_keylen = min (min_keylen, keylen)
	    max_keylen = max (max_keylen, keylen)
	    sum = sum + keylen
	}

	if (nsymbols > 0)
	    avg_keylen = sum / nsymbols
	else
	    min_keylen = 0

	call fprintf (fd,
	    "nsymbols=%d, minkeylen=%d, maxkeylen=%d, avgkeylen=%.1f\n")
	    call pargi (nsymbols)
	    call pargi (min_keylen)
	    call pargi (max_keylen)
	    call pargr (avg_keylen)

	# Scan the index and compute the number of nonnull threads, the
	# mean and max thread lengths, and the mean hash index, which should
	# be near the center of the index.

	nthreads = ST_INDEXLEN(stp)
	mean_hash_index = 0
	nonnull_threads = 0
	max_threadlen = 0
	avg_threadlen = 0
	sum = 0

	if (verbose == YES)
	    call fprintf (fd, "----------- threads ----------\n")

	do i = 1, nthreads {
	    if (verbose == YES) {
		call fprintf (fd, "[%4d] ")
		    call pargi (i)
	    }

	    head = Memi[index+i-1]
	    if (head != NULL) {
		nonnull_threads = nonnull_threads + 1

		# Count the number of symbols on the thread.
		nsym = 0
		for (el=head;  el != NULL;  el=E_NEXTHASH(ep)) {
		    nsym = nsym + 1
		    ep = stab + el

		    if (verbose == YES) {
			call fprintf (fd, "%s ")
			    call pargstr (Memc[sbuf+E_KEY(ep)])
		    }
		}


		max_threadlen = max (max_threadlen, nsym)
		sum = sum + (nsym * i)
	    }

	    if (verbose == YES)
		call fprintf (fd, "\n")
	}

	if (nonnull_threads > 0) {
	    avg_threadlen = real(nsymbols) / nonnull_threads
	    mean_hash_index = sum / nsymbols
	}

	if (verbose == YES)
	    call fprintf (fd, "---------------------\n")

	call fprintf (fd,
	    "nthreads=%d, maxlen=%d, avglen=%.1f, meanindex=%.1f\n")
	    call pargi (nonnull_threads)
	    call pargi (max_threadlen)
	    call pargr (avg_threadlen)
	    call pargr (mean_hash_index)
	
	call flush (fd)
end