xref: /illumos-gate/usr/src/cmd/truss/htbl.h (revision 2a8bcb4e)
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 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 #include <stdlib.h>
35 
36 typedef struct hentry {
37 	struct hentry *next;		/* next entry in hash chain */
38 	struct hentry *prev;		/* previous entry in hash chain */
39 	char *lib;			/* library name */
40 	char *key;			/* hash key (function name) */
41 	unsigned long count;		/* number of occurances of fn */
42 } hentry_t;
43 
44 typedef struct hashb {
45 	hentry_t *first;		/* first entry in bucket */
46 	mutex_t block;			/* bucket lock */
47 } hashb_t;
48 
49 typedef struct htbl {
50 	unsigned int size;		/* size of tbl in buckets */
51 	hashb_t *tbl;			/* ptr to buckets */
52 } htbl_t;
53 
54 typedef struct hiter {
55 	int bucket;			/* bucket in current iteration */
56 	hentry_t *next;			/* next entry in iteration */
57 	htbl_t *table;			/* ptr to table */
58 } hiter_t;
59 
60 /*
61  * HD_hashntry specifies that the entry written to disk contains information
62  * about function calls and is stored in the hash table.  When read back from
63  * disk this is merged into the parent's hash table
64  *
65  * HD_cts_syscts specifies that the entry written to disk is a struct counts
66  * struct syscount pair.  This contains information about system calls,
67  * signals, and faults.  When read back from disk, the information is added
68  * to the struct count / struct syscount information kept by the parent.
69  */
70 
71 typedef enum hdtype { HD_hashntry, HD_cts_syscts } hdtype_t;
72 
73 typedef struct hdntry {
74 	hdtype_t type;		/* type of entry we've written to disk */
75 	size_t sz_lib;		/* size of library string on disk */
76 	size_t sz_key;		/* size of key string on disk */
77 	unsigned long count;	/* count of occurrances of key */
78 } hdntry_t;
79 
80 
81 extern htbl_t *init_hash(unsigned int);
82 extern void destroy_hash(htbl_t *);
83 extern hiter_t *iterate_hash(htbl_t *);
84 extern hentry_t *iter_next(hiter_t *);
85 extern void iter_free(hiter_t *);
86 extern void add_fcall(htbl_t *, char *, char *, unsigned long);
87 extern size_t elements_in_table(htbl_t *);
88 
89 #ifdef	__cplusplus
90 }
91 #endif
92 
93 #endif	/* _HTBL_H */
94