]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - lib/libdevstat/devstat.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / lib / libdevstat / devstat.h
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$
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 /*
39  * Bumped every time we change the userland API.  Hopefully this doesn't
40  * happen very often!  This should be bumped every time we have to
41  * increment SHLIB_MAJOR in the libdevstat Makefile (for non-backwards
42  * compatible API changes) and should also be bumped every time we make
43  * backwards-compatible API changes, so application writers have a way to 
44  * determine when a particular feature is available.
45  */
46 #define DEVSTAT_USER_API_VER    6
47
48 #define DEVSTAT_ERRBUF_SIZE  2048 /* size of the devstat library error string */
49
50 extern char devstat_errbuf[];
51
52 typedef enum {
53         DEVSTAT_MATCH_NONE      = 0x00,
54         DEVSTAT_MATCH_TYPE      = 0x01,
55         DEVSTAT_MATCH_IF        = 0x02,
56         DEVSTAT_MATCH_PASS      = 0x04
57 } devstat_match_flags;
58
59 typedef enum {
60         DSM_NONE,
61         DSM_TOTAL_BYTES,
62         DSM_TOTAL_BYTES_READ,
63         DSM_TOTAL_BYTES_WRITE,
64         DSM_TOTAL_TRANSFERS,
65         DSM_TOTAL_TRANSFERS_READ,
66         DSM_TOTAL_TRANSFERS_WRITE,
67         DSM_TOTAL_TRANSFERS_OTHER,
68         DSM_TOTAL_BLOCKS,
69         DSM_TOTAL_BLOCKS_READ,
70         DSM_TOTAL_BLOCKS_WRITE,
71         DSM_KB_PER_TRANSFER,
72         DSM_KB_PER_TRANSFER_READ,
73         DSM_KB_PER_TRANSFER_WRITE,
74         DSM_TRANSFERS_PER_SECOND,
75         DSM_TRANSFERS_PER_SECOND_READ,
76         DSM_TRANSFERS_PER_SECOND_WRITE,
77         DSM_TRANSFERS_PER_SECOND_OTHER,
78         DSM_MB_PER_SECOND,
79         DSM_MB_PER_SECOND_READ,
80         DSM_MB_PER_SECOND_WRITE,
81         DSM_BLOCKS_PER_SECOND,
82         DSM_BLOCKS_PER_SECOND_READ,
83         DSM_BLOCKS_PER_SECOND_WRITE,
84         DSM_MS_PER_TRANSACTION,
85         DSM_MS_PER_TRANSACTION_READ,
86         DSM_MS_PER_TRANSACTION_WRITE,
87         DSM_SKIP,
88         DSM_TOTAL_BYTES_FREE,
89         DSM_TOTAL_TRANSFERS_FREE,
90         DSM_TOTAL_BLOCKS_FREE,
91         DSM_KB_PER_TRANSFER_FREE,
92         DSM_MB_PER_SECOND_FREE,
93         DSM_TRANSFERS_PER_SECOND_FREE,
94         DSM_BLOCKS_PER_SECOND_FREE,
95         DSM_MS_PER_TRANSACTION_OTHER,
96         DSM_MS_PER_TRANSACTION_FREE,
97         DSM_BUSY_PCT,
98         DSM_QUEUE_LENGTH,
99         DSM_MAX
100 } devstat_metric;
101
102 struct devstat_match {
103         devstat_match_flags     match_fields;
104         devstat_type_flags      device_type;
105         int                     num_match_categories;
106 };
107
108 struct devstat_match_table {
109         const char *            match_str;
110         devstat_type_flags      type;
111         devstat_match_flags     match_field;
112 };
113
114 struct device_selection {
115         u_int32_t       device_number;
116         char            device_name[DEVSTAT_NAME_LEN];
117         int             unit_number;
118         int             selected;
119         u_int64_t       bytes;
120         int             position;
121 };
122
123 struct devinfo {
124         struct devstat  *devices;
125         u_int8_t        *mem_ptr;
126         long            generation;
127         int             numdevs;
128 };
129
130 struct statinfo {
131         long            cp_time[CPUSTATES];
132         long            tk_nin;
133         long            tk_nout;
134         struct devinfo  *dinfo;
135         long double     snap_time;
136 };
137
138 typedef enum {
139         DS_SELECT_ADD,
140         DS_SELECT_ONLY,
141         DS_SELECT_REMOVE,
142         DS_SELECT_ADDONLY
143 } devstat_select_mode;
144
145 __BEGIN_DECLS
146
147 int devstat_getnumdevs(kvm_t *kd);
148 long devstat_getgeneration(kvm_t *kd);
149 int devstat_getversion(kvm_t *kd);
150 int devstat_checkversion(kvm_t *kd);
151 int devstat_getdevs(kvm_t *kd, struct statinfo *stats);
152 int devstat_selectdevs(struct device_selection **dev_select, int *num_selected,
153                        int *num_selections, long *select_generation, 
154                        long current_generation, struct devstat *devices,
155                        int numdevs, struct devstat_match *matches,
156                        int num_matches, char **dev_selections,
157                        int num_dev_selections, devstat_select_mode select_mode,
158                        int maxshowdevs, int perf_select);
159 int devstat_buildmatch(char *match_str, struct devstat_match **matches,
160                        int *num_matches);
161 int devstat_compute_statistics(struct devstat *current,
162                                struct devstat *previous,
163                                long double etime, ...);
164 long double devstat_compute_etime(struct bintime *cur_time,
165                                   struct bintime *prev_time);
166 __END_DECLS
167
168 #endif /* _DEVSTAT_H  */