xref: /freebsd/lib/libdevstat/devstat.h (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1997, 1998 Kenneth D. Merry.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * $FreeBSD$
31  */
32 
33 #ifndef _DEVSTAT_H
34 #define _DEVSTAT_H
35 #include <sys/cdefs.h>
36 #include <sys/devicestat.h>
37 #include <sys/resource.h>
38 
39 #include <kvm.h>
40 
41 /*
42  * Bumped every time we change the userland API.  Hopefully this doesn't
43  * happen very often!  This should be bumped every time we have to
44  * increment SHLIB_MAJOR in the libdevstat Makefile (for non-backwards
45  * compatible API changes) and should also be bumped every time we make
46  * backwards-compatible API changes, so application writers have a way to
47  * determine when a particular feature is available.
48  */
49 #define	DEVSTAT_USER_API_VER	6
50 
51 #define DEVSTAT_ERRBUF_SIZE  2048 /* size of the devstat library error string */
52 
53 extern char devstat_errbuf[];
54 
55 typedef enum {
56 	DEVSTAT_MATCH_NONE	= 0x00,
57 	DEVSTAT_MATCH_TYPE	= 0x01,
58 	DEVSTAT_MATCH_IF	= 0x02,
59 	DEVSTAT_MATCH_PASS	= 0x04
60 } devstat_match_flags;
61 
62 typedef enum {
63 	DSM_NONE,
64 	DSM_TOTAL_BYTES,
65 	DSM_TOTAL_BYTES_READ,
66 	DSM_TOTAL_BYTES_WRITE,
67 	DSM_TOTAL_TRANSFERS,
68 	DSM_TOTAL_TRANSFERS_READ,
69 	DSM_TOTAL_TRANSFERS_WRITE,
70 	DSM_TOTAL_TRANSFERS_OTHER,
71 	DSM_TOTAL_BLOCKS,
72 	DSM_TOTAL_BLOCKS_READ,
73 	DSM_TOTAL_BLOCKS_WRITE,
74 	DSM_KB_PER_TRANSFER,
75 	DSM_KB_PER_TRANSFER_READ,
76 	DSM_KB_PER_TRANSFER_WRITE,
77 	DSM_TRANSFERS_PER_SECOND,
78 	DSM_TRANSFERS_PER_SECOND_READ,
79 	DSM_TRANSFERS_PER_SECOND_WRITE,
80 	DSM_TRANSFERS_PER_SECOND_OTHER,
81 	DSM_MB_PER_SECOND,
82 	DSM_MB_PER_SECOND_READ,
83 	DSM_MB_PER_SECOND_WRITE,
84 	DSM_BLOCKS_PER_SECOND,
85 	DSM_BLOCKS_PER_SECOND_READ,
86 	DSM_BLOCKS_PER_SECOND_WRITE,
87 	DSM_MS_PER_TRANSACTION,
88 	DSM_MS_PER_TRANSACTION_READ,
89 	DSM_MS_PER_TRANSACTION_WRITE,
90 	DSM_SKIP,
91 	DSM_TOTAL_BYTES_FREE,
92 	DSM_TOTAL_TRANSFERS_FREE,
93 	DSM_TOTAL_BLOCKS_FREE,
94 	DSM_KB_PER_TRANSFER_FREE,
95 	DSM_MB_PER_SECOND_FREE,
96 	DSM_TRANSFERS_PER_SECOND_FREE,
97 	DSM_BLOCKS_PER_SECOND_FREE,
98 	DSM_MS_PER_TRANSACTION_OTHER,
99 	DSM_MS_PER_TRANSACTION_FREE,
100 	DSM_BUSY_PCT,
101 	DSM_QUEUE_LENGTH,
102 	DSM_TOTAL_DURATION,
103 	DSM_TOTAL_DURATION_READ,
104 	DSM_TOTAL_DURATION_WRITE,
105 	DSM_TOTAL_DURATION_FREE,
106 	DSM_TOTAL_DURATION_OTHER,
107 	DSM_TOTAL_BUSY_TIME,
108 	DSM_MAX
109 } devstat_metric;
110 
111 struct devstat_match {
112 	devstat_match_flags	match_fields;
113 	devstat_type_flags	device_type;
114 	int			num_match_categories;
115 };
116 
117 struct devstat_match_table {
118 	const char *		match_str;
119 	devstat_type_flags	type;
120 	devstat_match_flags	match_field;
121 };
122 
123 struct device_selection {
124 	u_int32_t	device_number;
125 	char		device_name[DEVSTAT_NAME_LEN];
126 	int		unit_number;
127 	int		selected;
128 	u_int64_t	bytes;
129 	int		position;
130 };
131 
132 struct devinfo {
133 	struct devstat	*devices;
134 	u_int8_t	*mem_ptr;
135 	long		generation;
136 	int		numdevs;
137 };
138 
139 struct statinfo {
140 	long		cp_time[CPUSTATES];
141 	long		tk_nin;
142 	long		tk_nout;
143 	struct devinfo	*dinfo;
144 	long double 	snap_time;
145 };
146 
147 typedef enum {
148 	DS_SELECT_ADD,
149 	DS_SELECT_ONLY,
150 	DS_SELECT_REMOVE,
151 	DS_SELECT_ADDONLY
152 } devstat_select_mode;
153 
154 __BEGIN_DECLS
155 
156 int devstat_getnumdevs(kvm_t *kd);
157 long devstat_getgeneration(kvm_t *kd);
158 int devstat_getversion(kvm_t *kd);
159 int devstat_checkversion(kvm_t *kd);
160 int devstat_getdevs(kvm_t *kd, struct statinfo *stats);
161 int devstat_selectdevs(struct device_selection **dev_select, int *num_selected,
162 		       int *num_selections, long *select_generation,
163 		       long current_generation, struct devstat *devices,
164 		       int numdevs, struct devstat_match *matches,
165 		       int num_matches, char **dev_selections,
166 		       int num_dev_selections, devstat_select_mode select_mode,
167 		       int maxshowdevs, int perf_select);
168 int devstat_buildmatch(char *match_str, struct devstat_match **matches,
169 		       int *num_matches);
170 int devstat_compute_statistics(struct devstat *current,
171 			       struct devstat *previous,
172 			       long double etime, ...);
173 long double devstat_compute_etime(struct bintime *cur_time,
174 				  struct bintime *prev_time);
175 __END_DECLS
176 
177 #endif /* _DEVSTAT_H  */
178