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