xref: /onnv-gate/usr/src/lib/libast/common/hash/hashdump.c (revision 4887:feebf9260c2e)
1*4887Schin /***********************************************************************
2*4887Schin *                                                                      *
3*4887Schin *               This software is part of the ast package               *
4*4887Schin *           Copyright (c) 1985-2007 AT&T Knowledge Ventures            *
5*4887Schin *                      and is licensed under the                       *
6*4887Schin *                  Common Public License, Version 1.0                  *
7*4887Schin *                      by AT&T Knowledge Ventures                      *
8*4887Schin *                                                                      *
9*4887Schin *                A copy of the License is available at                 *
10*4887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
11*4887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12*4887Schin *                                                                      *
13*4887Schin *              Information and Software Systems Research               *
14*4887Schin *                            AT&T Research                             *
15*4887Schin *                           Florham Park NJ                            *
16*4887Schin *                                                                      *
17*4887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
18*4887Schin *                  David Korn <dgk@research.att.com>                   *
19*4887Schin *                   Phong Vo <kpv@research.att.com>                    *
20*4887Schin *                                                                      *
21*4887Schin ***********************************************************************/
22*4887Schin #pragma prototyped
23*4887Schin /*
24*4887Schin  * Glenn Fowler
25*4887Schin  * AT&T Bell Laboratories
26*4887Schin  *
27*4887Schin  * hash table library
28*4887Schin  */
29*4887Schin 
30*4887Schin #include "hashlib.h"
31*4887Schin 
32*4887Schin /*
33*4887Schin  * dump HASH_* flags
34*4887Schin  */
35*4887Schin 
36*4887Schin static void
37*4887Schin dumpflags(register int flags)
38*4887Schin {
39*4887Schin 	if (flags & HASH_ALLOCATE) sfprintf(sfstderr, "allocate ");
40*4887Schin 	if (flags & HASH_BUCKET) sfprintf(sfstderr, "bucket ");
41*4887Schin 	if (flags & HASH_FIXED) sfprintf(sfstderr, "fixed ");
42*4887Schin 	if (flags & HASH_HASHED) sfprintf(sfstderr, "hashed ");
43*4887Schin 	if (flags & HASH_RESIZE) sfprintf(sfstderr, "resize ");
44*4887Schin 	if (flags & HASH_STATIC) sfprintf(sfstderr, "static ");
45*4887Schin 	if (flags & HASH_VALUE) sfprintf(sfstderr, "value ");
46*4887Schin }
47*4887Schin 
48*4887Schin /*
49*4887Schin  * dump hash table bucket info
50*4887Schin  */
51*4887Schin 
52*4887Schin static void
53*4887Schin dumpbucket(register Hash_table_t* tab, int flags)
54*4887Schin {
55*4887Schin 	register Hash_bucket_t**	sp;
56*4887Schin 	register Hash_bucket_t*		b;
57*4887Schin 	Hash_bucket_t**			sx;
58*4887Schin 	int				n;
59*4887Schin 	unsigned char*			s;
60*4887Schin 
61*4887Schin 	NoP(flags);
62*4887Schin 	sx = tab->table + tab->size;
63*4887Schin 	for (sp = tab->table; sp < sx; sp++)
64*4887Schin 	{
65*4887Schin 		n = 0;
66*4887Schin 		for (b = *sp; b; b = b->next)
67*4887Schin 			if (!(b->hash & HASH_DELETED) && (!(tab->flags & HASH_VALUE) || b->value))
68*4887Schin 				n++;
69*4887Schin 		if (n)
70*4887Schin 		{
71*4887Schin 			sfprintf(sfstderr, "%5d %2d :", sp - tab->table, n);
72*4887Schin 			for (b = *sp; b; b = b->next)
73*4887Schin 				if (!(b->hash & HASH_DELETED) && (!(tab->flags & HASH_VALUE) || b->value))
74*4887Schin 				{
75*4887Schin 					if (n = tab->root->namesize)
76*4887Schin 					{
77*4887Schin 						sfprintf(sfstderr, " 0x");
78*4887Schin 						s = (unsigned char*)hashname(b);
79*4887Schin 						while (n-- > 0)
80*4887Schin 							sfprintf(sfstderr, "%02x", *s++);
81*4887Schin 					}
82*4887Schin 					else sfprintf(sfstderr, " %s", hashname(b));
83*4887Schin 					if (b->hash & HASH_FLAGS)
84*4887Schin 					{
85*4887Schin 						sfprintf(sfstderr, "|");
86*4887Schin 						if (b->hash & HASH_HIDES) sfprintf(sfstderr, "hides|");
87*4887Schin 						if (b->hash & HASH_HIDDEN) sfprintf(sfstderr, "hidden|");
88*4887Schin 						if (b->hash & HASH_KEEP) sfprintf(sfstderr, "keep|");
89*4887Schin 						if (b->hash & HASH_OPAQUED) sfprintf(sfstderr, "opaque|");
90*4887Schin 					}
91*4887Schin 					if (tab->flags & HASH_VALUE) sfprintf(sfstderr, "=0x%08lx", (long)b->value);
92*4887Schin 				}
93*4887Schin 			sfprintf(sfstderr, "\n");
94*4887Schin 		}
95*4887Schin 	}
96*4887Schin 	sfprintf(sfstderr, "\n");
97*4887Schin }
98*4887Schin 
99*4887Schin /*
100*4887Schin  * dump info on a single table
101*4887Schin  */
102*4887Schin 
103*4887Schin static void
104*4887Schin dumptable(register Hash_table_t* tab, register int flags)
105*4887Schin {
106*4887Schin 	Hash_table_t*	scope;
107*4887Schin 	int		level;
108*4887Schin 
109*4887Schin 	sfprintf(sfstderr, "        name:        %s", tab->name ? tab->name : "*no name*");
110*4887Schin 	if (scope = tab->scope)
111*4887Schin 	{
112*4887Schin 		level = 1;
113*4887Schin 		while (scope = scope->scope) level++;
114*4887Schin 		sfprintf(sfstderr, " level %d scope on 0x%08lx", level, (unsigned long)tab->scope);
115*4887Schin 	}
116*4887Schin 	sfprintf(sfstderr, "\n");
117*4887Schin 	sfprintf(sfstderr, "        address:     0x%08lx\n", (unsigned long)tab);
118*4887Schin 	sfprintf(sfstderr, "        flags:       ");
119*4887Schin 	if (tab->frozen) sfprintf(sfstderr, "frozen=%d ", tab->frozen);
120*4887Schin 	dumpflags(tab->flags);
121*4887Schin 	sfprintf(sfstderr, "\n");
122*4887Schin 	sfprintf(sfstderr, "        size:        %d\n", tab->size);
123*4887Schin 	sfprintf(sfstderr, "        buckets:     %d\n", tab->buckets);
124*4887Schin 	sfprintf(sfstderr, "        bucketsize:  %d\n", tab->bucketsize * sizeof(char*));
125*4887Schin 	sfprintf(sfstderr, "\n");
126*4887Schin 	if ((flags | tab->flags) & HASH_BUCKET) dumpbucket(tab, flags);
127*4887Schin }
128*4887Schin 
129*4887Schin /*
130*4887Schin  * dump hash table root info
131*4887Schin  */
132*4887Schin 
133*4887Schin static void
134*4887Schin dumproot(register Hash_root_t* root, register int flags)
135*4887Schin {
136*4887Schin 	register Hash_table_t*	tab;
137*4887Schin 
138*4887Schin 	sfprintf(sfstderr, "    root\n");
139*4887Schin 	sfprintf(sfstderr, "        address:     0x%08lx\n", (unsigned long)root);
140*4887Schin 	sfprintf(sfstderr, "        flags:       ");
141*4887Schin 	dumpflags(root->flags);
142*4887Schin 	if (root->namesize) sfprintf(sfstderr, "namesize=%d ", root->namesize);
143*4887Schin 	if (root->local->alloc) sfprintf(sfstderr, "alloc=0x%08lx ", (unsigned long)root->local->alloc);
144*4887Schin 	if (root->local->compare) sfprintf(sfstderr, "compare=0x%08lx ", (unsigned long)root->local->compare);
145*4887Schin 	if (root->local->free) sfprintf(sfstderr, "free=0x%08lx ", (unsigned long)root->local->free);
146*4887Schin 	if (root->local->hash) sfprintf(sfstderr, "hash=0x%08lx ", (unsigned long)root->local->hash);
147*4887Schin 	if (root->local->region) sfprintf(sfstderr, "region=0x%08lx handle=0x%08lx ", (unsigned long)root->local->region, (unsigned long)root->local->handle);
148*4887Schin 	sfprintf(sfstderr, "\n");
149*4887Schin 	sfprintf(sfstderr, "        meanchain:   %d\n", root->meanchain);
150*4887Schin 	sfprintf(sfstderr, "        accesses:    %d\n", root->accesses);
151*4887Schin 	sfprintf(sfstderr, "        collisions:  %d\n", root->collisions);
152*4887Schin 	sfprintf(sfstderr, "\n");
153*4887Schin 	for (tab = root->references; tab; tab = tab->next)
154*4887Schin 		dumptable(tab, flags);
155*4887Schin }
156*4887Schin 
157*4887Schin /*
158*4887Schin  * dump hash table accounting info
159*4887Schin  * if tab is 0 then dump all tables in hash_info.list
160*4887Schin  * flags are HASH_* flags that specifiy optional dump info
161*4887Schin  */
162*4887Schin 
163*4887Schin void
164*4887Schin hashdump(register Hash_table_t* tab, int flags)
165*4887Schin {
166*4887Schin 	register Hash_root_t*	root;
167*4887Schin 
168*4887Schin 	sfprintf(sfstderr, "\nhash table information:\n\n");
169*4887Schin 	if (tab) dumproot(tab->root, flags);
170*4887Schin 	else for (root = hash_info.list; root; root = root->next)
171*4887Schin 		dumproot(root, flags);
172*4887Schin 	sfsync(sfstderr);
173*4887Schin }
174