xref: /titanic_50/usr/src/cmd/truss/htbl.h (revision 726fad2a65f16c200a03969c29cb5c86c2d427db)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_HTBL_H
28 #define	_HTBL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <stdlib.h>
37 
38 typedef struct hentry {
39 	struct hentry *next;		/* next entry in hash chain */
40 	struct hentry *prev;		/* previous entry in hash chain */
41 	char *lib;			/* library name */
42 	char *key;			/* hash key (function name) */
43 	unsigned long count;		/* number of occurances of fn */
44 } hentry_t;
45 
46 typedef struct hashb {
47 	hentry_t *first;		/* first entry in bucket */
48 	mutex_t block;			/* bucket lock */
49 } hashb_t;
50 
51 typedef struct htbl {
52 	unsigned int size;		/* size of tbl in buckets */
53 	hashb_t *tbl;			/* ptr to buckets */
54 } htbl_t;
55 
56 typedef struct hiter {
57 	int bucket;			/* bucket in current iteration */
58 	hentry_t *next;			/* next entry in iteration */
59 	htbl_t *table;			/* ptr to table */
60 } hiter_t;
61 
62 /*
63  * HD_hashntry specifies that the entry written to disk contains information
64  * about function calls and is stored in the hash table.  When read back from
65  * disk this is merged into the parent's hash table
66  *
67  * HD_cts_syscts specifies that the entry written to disk is a struct counts
68  * struct syscount pair.  This contains information about system calls,
69  * signals, and faults.  When read back from disk, the information is added
70  * to the struct count / struct syscount information kept by the parent.
71  */
72 
73 typedef enum hdtype { HD_hashntry, HD_cts_syscts } hdtype_t;
74 
75 typedef struct hdntry {
76 	hdtype_t type;		/* type of entry we've written to disk */
77 	size_t sz_lib;		/* size of library string on disk */
78 	size_t sz_key;		/* size of key string on disk */
79 	unsigned long count;	/* count of occurrances of key */
80 } hdntry_t;
81 
82 
83 extern htbl_t *init_hash(unsigned int);
84 extern void destroy_hash(htbl_t *);
85 extern hiter_t *iterate_hash(htbl_t *);
86 extern hentry_t *iter_next(hiter_t *);
87 extern void iter_free(hiter_t *);
88 extern void add_fcall(htbl_t *, char *, char *, unsigned long);
89 extern size_t elements_in_table(htbl_t *);
90 
91 #ifdef	__cplusplus
92 }
93 #endif
94 
95 #endif	/* _HTBL_H */
96