summaryrefslogtreecommitdiffstats
path: root/lib/libdevstat/devstat.h
blob: ec638c15fed6df1df9734582c160fba5ab34c1c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*
 * Copyright (c) 1997, 1998 Kenneth D. Merry.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $FreeBSD$
 */

#ifndef _DEVSTAT_H
#define _DEVSTAT_H
#include <sys/cdefs.h>
#include <sys/devicestat.h>

#include <kvm.h>

#define DEVSTAT_ERRBUF_SIZE  2048 /* size of the devstat library error string */

extern char devstat_errbuf[];

typedef enum {
	DEVSTAT_MATCH_NONE	= 0x00,
	DEVSTAT_MATCH_TYPE	= 0x01,
	DEVSTAT_MATCH_IF	= 0x02,
	DEVSTAT_MATCH_PASS	= 0x04
} devstat_match_flags;

typedef enum {
	DSM_NONE,
	DSM_TOTAL_BYTES,
	DSM_TOTAL_BYTES_READ,
	DSM_TOTAL_BYTES_WRITE,
	DSM_TOTAL_TRANSFERS,
	DSM_TOTAL_TRANSFERS_READ,
	DSM_TOTAL_TRANSFERS_WRITE,
	DSM_TOTAL_TRANSFERS_OTHER,
	DSM_TOTAL_BLOCKS,
	DSM_TOTAL_BLOCKS_READ,
	DSM_TOTAL_BLOCKS_WRITE,
	DSM_KB_PER_TRANSFER,
	DSM_KB_PER_TRANSFER_READ,
	DSM_KB_PER_TRANSFER_WRITE,
	DSM_TRANSFERS_PER_SECOND,
	DSM_TRANSFERS_PER_SECOND_READ,
	DSM_TRANSFERS_PER_SECOND_WRITE,
	DSM_TRANSFERS_PER_SECOND_OTHER,
	DSM_MB_PER_SECOND,
	DSM_MB_PER_SECOND_READ,
	DSM_MB_PER_SECOND_WRITE,
	DSM_BLOCKS_PER_SECOND,
	DSM_BLOCKS_PER_SECOND_READ,
	DSM_BLOCKS_PER_SECOND_WRITE,
	DSM_MS_PER_TRANSACTION,
	DSM_MS_PER_TRANSACTION_READ,
	DSM_MS_PER_TRANSACTION_WRITE,
	DSM_MAX
} devstat_metric;

struct devstat_match {
	devstat_match_flags	match_fields;
	devstat_type_flags	device_type;
	int			num_match_categories;
};

struct devstat_match_table {
	char 			*match_str;
	devstat_type_flags	type;
	devstat_match_flags	match_field;
};

struct device_selection {
	u_int32_t	device_number;
	char		device_name[DEVSTAT_NAME_LEN];
	int		unit_number;
	int		selected;
	u_int64_t	bytes;
	int		position;
};

struct devinfo {
	struct devstat	*devices;
	u_int8_t	*mem_ptr;
	long		generation;
	int		numdevs;
};

struct statinfo {
	long		cp_time[CPUSTATES];
	long		tk_nin;
	long		tk_nout;
	struct devinfo	*dinfo;
	struct timeval	busy_time;
};

typedef enum {
	DS_SELECT_ADD,
	DS_SELECT_ONLY,
	DS_SELECT_REMOVE,
	DS_SELECT_ADDONLY
} devstat_select_mode;

__BEGIN_DECLS
/* Legacy interfaces. */
int getnumdevs(void);
long getgeneration(void);
int getversion(void);
int checkversion(void);
int getdevs(struct statinfo *stats);
int selectdevs(struct device_selection **dev_select, int *num_selected,
	       int *num_selections, long *select_generation, 
	       long current_generation, struct devstat *devices, int numdevs,
	       struct devstat_match *matches, int num_matches,
	       char **dev_selections, int num_dev_selections,
	       devstat_select_mode select_mode, int maxshowdevs,
	       int perf_select);
int buildmatch(char *match_str, struct devstat_match **matches,
	       int *num_matches);
int compute_stats(struct devstat *current, struct devstat *previous,
		  long double etime, u_int64_t *total_bytes,
		  u_int64_t *total_transfers, u_int64_t *total_blocks,
		  long double *kb_per_transfer,
		  long double *transfers_per_second, long double *mb_per_second,
		  long double *blocks_per_second,
		  long double *ms_per_transaction);
long double compute_etime(struct timeval cur_time, struct timeval prev_time);

/* New interfaces. */
int devstat_getnumdevs(kvm_t *kd);
long devstat_getgeneration(kvm_t *kd);
int devstat_getversion(kvm_t *kd);
int devstat_checkversion(kvm_t *kd);
int devstat_getdevs(kvm_t *kd, struct statinfo *stats);
int devstat_selectdevs(struct device_selection **dev_select, int *num_selected,
		       int *num_selections, long *select_generation, 
		       long current_generation, struct devstat *devices,
		       int numdevs, struct devstat_match *matches,
		       int num_matches, char **dev_selections,
		       int num_dev_selections, devstat_select_mode select_mode,
		       int maxshowdevs, int perf_select);
int devstat_buildmatch(char *match_str, struct devstat_match **matches,
		       int *num_matches);
int devstat_compute_statistics(struct devstat *current,
			       struct devstat *previous,
			       long double etime, ...);
long double devstat_compute_etime(struct timeval cur_time,
				  struct timeval prev_time);
__END_DECLS

#endif /* _DEVSTAT_H  */
OpenPOWER on IntegriCloud