Deleted Added
full compact
devstat.c (112293) devstat.c (112373)
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

--- 13 unchanged lines hidden (view full) ---

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
29#include <sys/cdefs.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

--- 13 unchanged lines hidden (view full) ---

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
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/lib/libdevstat/devstat.c 112293 2003-03-15 22:22:11Z phk $");
30__FBSDID("$FreeBSD: head/lib/libdevstat/devstat.c 112373 2003-03-18 09:57:54Z phk $");
31
32#include <sys/types.h>
33#include <sys/sysctl.h>
34#include <sys/errno.h>
35#include <sys/resource.h>
36#include <sys/queue.h>
37
38#include <ctype.h>

--- 45 unchanged lines hidden (view full) ---

84struct devstat_args {
85 devstat_metric metric;
86 devstat_arg_type argtype;
87} devstat_arg_list[] = {
88 { DSM_NONE, DEVSTAT_ARG_NOTYPE },
89 { DSM_TOTAL_BYTES, DEVSTAT_ARG_UINT64 },
90 { DSM_TOTAL_BYTES_READ, DEVSTAT_ARG_UINT64 },
91 { DSM_TOTAL_BYTES_WRITE, DEVSTAT_ARG_UINT64 },
31
32#include <sys/types.h>
33#include <sys/sysctl.h>
34#include <sys/errno.h>
35#include <sys/resource.h>
36#include <sys/queue.h>
37
38#include <ctype.h>

--- 45 unchanged lines hidden (view full) ---

84struct devstat_args {
85 devstat_metric metric;
86 devstat_arg_type argtype;
87} devstat_arg_list[] = {
88 { DSM_NONE, DEVSTAT_ARG_NOTYPE },
89 { DSM_TOTAL_BYTES, DEVSTAT_ARG_UINT64 },
90 { DSM_TOTAL_BYTES_READ, DEVSTAT_ARG_UINT64 },
91 { DSM_TOTAL_BYTES_WRITE, DEVSTAT_ARG_UINT64 },
92 { DSM_TOTAL_BYTES_FREE, DEVSTAT_ARG_UINT64 },
92 { DSM_TOTAL_TRANSFERS, DEVSTAT_ARG_UINT64 },
93 { DSM_TOTAL_TRANSFERS, DEVSTAT_ARG_UINT64 },
94 { DSM_TOTAL_TRANSFERS_OTHER, DEVSTAT_ARG_UINT64 },
93 { DSM_TOTAL_TRANSFERS_READ, DEVSTAT_ARG_UINT64 },
94 { DSM_TOTAL_TRANSFERS_WRITE, DEVSTAT_ARG_UINT64 },
95 { DSM_TOTAL_TRANSFERS_READ, DEVSTAT_ARG_UINT64 },
96 { DSM_TOTAL_TRANSFERS_WRITE, DEVSTAT_ARG_UINT64 },
95 { DSM_TOTAL_TRANSFERS_OTHER, DEVSTAT_ARG_UINT64 },
97 { DSM_TOTAL_TRANSFERS_FREE, DEVSTAT_ARG_UINT64 },
96 { DSM_TOTAL_BLOCKS, DEVSTAT_ARG_UINT64 },
97 { DSM_TOTAL_BLOCKS_READ, DEVSTAT_ARG_UINT64 },
98 { DSM_TOTAL_BLOCKS_WRITE, DEVSTAT_ARG_UINT64 },
98 { DSM_TOTAL_BLOCKS, DEVSTAT_ARG_UINT64 },
99 { DSM_TOTAL_BLOCKS_READ, DEVSTAT_ARG_UINT64 },
100 { DSM_TOTAL_BLOCKS_WRITE, DEVSTAT_ARG_UINT64 },
101 { DSM_TOTAL_BLOCKS_FREE, DEVSTAT_ARG_UINT64 },
99 { DSM_KB_PER_TRANSFER, DEVSTAT_ARG_LD },
100 { DSM_KB_PER_TRANSFER_READ, DEVSTAT_ARG_LD },
101 { DSM_KB_PER_TRANSFER_WRITE, DEVSTAT_ARG_LD },
102 { DSM_KB_PER_TRANSFER, DEVSTAT_ARG_LD },
103 { DSM_KB_PER_TRANSFER_READ, DEVSTAT_ARG_LD },
104 { DSM_KB_PER_TRANSFER_WRITE, DEVSTAT_ARG_LD },
105 { DSM_KB_PER_TRANSFER_FREE, DEVSTAT_ARG_LD },
102 { DSM_TRANSFERS_PER_SECOND, DEVSTAT_ARG_LD },
103 { DSM_TRANSFERS_PER_SECOND_READ, DEVSTAT_ARG_LD },
104 { DSM_TRANSFERS_PER_SECOND_WRITE, DEVSTAT_ARG_LD },
106 { DSM_TRANSFERS_PER_SECOND, DEVSTAT_ARG_LD },
107 { DSM_TRANSFERS_PER_SECOND_READ, DEVSTAT_ARG_LD },
108 { DSM_TRANSFERS_PER_SECOND_WRITE, DEVSTAT_ARG_LD },
109 { DSM_TRANSFERS_PER_SECOND_FREE, DEVSTAT_ARG_LD },
105 { DSM_TRANSFERS_PER_SECOND_OTHER, DEVSTAT_ARG_LD },
106 { DSM_MB_PER_SECOND, DEVSTAT_ARG_LD },
107 { DSM_MB_PER_SECOND_READ, DEVSTAT_ARG_LD },
108 { DSM_MB_PER_SECOND_WRITE, DEVSTAT_ARG_LD },
110 { DSM_TRANSFERS_PER_SECOND_OTHER, DEVSTAT_ARG_LD },
111 { DSM_MB_PER_SECOND, DEVSTAT_ARG_LD },
112 { DSM_MB_PER_SECOND_READ, DEVSTAT_ARG_LD },
113 { DSM_MB_PER_SECOND_WRITE, DEVSTAT_ARG_LD },
114 { DSM_MB_PER_SECOND_FREE, DEVSTAT_ARG_LD },
109 { DSM_BLOCKS_PER_SECOND, DEVSTAT_ARG_LD },
110 { DSM_BLOCKS_PER_SECOND_READ, DEVSTAT_ARG_LD },
111 { DSM_BLOCKS_PER_SECOND_WRITE, DEVSTAT_ARG_LD },
115 { DSM_BLOCKS_PER_SECOND, DEVSTAT_ARG_LD },
116 { DSM_BLOCKS_PER_SECOND_READ, DEVSTAT_ARG_LD },
117 { DSM_BLOCKS_PER_SECOND_WRITE, DEVSTAT_ARG_LD },
118 { DSM_BLOCKS_PER_SECOND_FREE, DEVSTAT_ARG_LD },
112 { DSM_MS_PER_TRANSACTION, DEVSTAT_ARG_LD },
113 { DSM_MS_PER_TRANSACTION_READ, DEVSTAT_ARG_LD },
114 { DSM_MS_PER_TRANSACTION_WRITE, DEVSTAT_ARG_LD },
119 { DSM_MS_PER_TRANSACTION, DEVSTAT_ARG_LD },
120 { DSM_MS_PER_TRANSACTION_READ, DEVSTAT_ARG_LD },
121 { DSM_MS_PER_TRANSACTION_WRITE, DEVSTAT_ARG_LD },
122 { DSM_MS_PER_TRANSACTION_FREE, DEVSTAT_ARG_LD },
123 { DSM_MS_PER_TRANSACTION_OTHER, DEVSTAT_ARG_LD },
124 { DSM_BUSY_PCT, DEVSTAT_ARG_LD },
125 { DSM_QUEUE_LENGTH, DEVSTAT_ARG_UINT64 },
115 { DSM_SKIP, DEVSTAT_ARG_SKIP }
116};
117
118static const char *namelist[] = {
119#define X_NUMDEVS 0
120 "_devstat_num_devs",
121#define X_GENERATION 1
122 "_devstat_generation",

--- 234 unchanged lines hidden (view full) ---

357 /*
358 * Request all of the devices. We only really allow for one
359 * ENOMEM failure. It would, of course, be possible to just go
360 * in a loop and keep reallocing the device structure until we
361 * don't get ENOMEM back. I'm not sure it's worth it, though.
362 * If devices are being added to the system that quickly, maybe
363 * the user can just wait until all devices are added.
364 */
126 { DSM_SKIP, DEVSTAT_ARG_SKIP }
127};
128
129static const char *namelist[] = {
130#define X_NUMDEVS 0
131 "_devstat_num_devs",
132#define X_GENERATION 1
133 "_devstat_generation",

--- 234 unchanged lines hidden (view full) ---

368 /*
369 * Request all of the devices. We only really allow for one
370 * ENOMEM failure. It would, of course, be possible to just go
371 * in a loop and keep reallocing the device structure until we
372 * don't get ENOMEM back. I'm not sure it's worth it, though.
373 * If devices are being added to the system that quickly, maybe
374 * the user can just wait until all devices are added.
375 */
365 if ((error = sysctlbyname("kern.devstat.all", dinfo->mem_ptr,
366 &dssize, NULL, 0)) == -1) {
376 for (;;) {
377 error = sysctlbyname("kern.devstat.all",
378 dinfo->mem_ptr,
379 &dssize, NULL, 0);
380 if (error != -1 || errno != EBUSY)
381 break;
382 }
383 if (error == -1) {
367 /*
368 * If we get ENOMEM back, that means that there are
369 * more devices now, so we need to allocate more
370 * space for the device array.
371 */
372 if (errno == ENOMEM) {
373 /*
374 * No need to set the error string here,

--- 781 unchanged lines hidden (view full) ---

1156 etime += cur_time->frac * BINTIME_SCALE;
1157 if (prev_time != NULL) {
1158 etime -= prev_time->sec;
1159 etime -= prev_time->frac * BINTIME_SCALE;
1160 }
1161 return(etime);
1162}
1163
384 /*
385 * If we get ENOMEM back, that means that there are
386 * more devices now, so we need to allocate more
387 * space for the device array.
388 */
389 if (errno == ENOMEM) {
390 /*
391 * No need to set the error string here,

--- 781 unchanged lines hidden (view full) ---

1173 etime += cur_time->frac * BINTIME_SCALE;
1174 if (prev_time != NULL) {
1175 etime -= prev_time->sec;
1176 etime -= prev_time->frac * BINTIME_SCALE;
1177 }
1178 return(etime);
1179}
1180
1181#define DELTA(field, index) \
1182 (current->field[(index)] - (previous ? previous->field[(index)] : 0))
1183
1184#define DELTA_T(field) \
1185 devstat_compute_etime(&current->field, \
1186 (previous ? &previous->field : NULL))
1187
1164int
1165devstat_compute_statistics(struct devstat *current, struct devstat *previous,
1166 long double etime, ...)
1167{
1168 const char *func_name = "devstat_compute_statistics";
1188int
1189devstat_compute_statistics(struct devstat *current, struct devstat *previous,
1190 long double etime, ...)
1191{
1192 const char *func_name = "devstat_compute_statistics";
1169 u_int64_t totalbytes, totalbytesread, totalbyteswrite;
1193 u_int64_t totalbytes, totalbytesread, totalbyteswrite, totalbytesfree;
1170 u_int64_t totaltransfers, totaltransfersread, totaltransferswrite;
1171 u_int64_t totaltransfersother, totalblocks, totalblocksread;
1194 u_int64_t totaltransfers, totaltransfersread, totaltransferswrite;
1195 u_int64_t totaltransfersother, totalblocks, totalblocksread;
1172 u_int64_t totalblockswrite;
1196 u_int64_t totalblockswrite, totaltransfersfree, totalblocksfree;
1173 va_list ap;
1174 devstat_metric metric;
1175 u_int64_t *destu64;
1176 long double *destld;
1197 va_list ap;
1198 devstat_metric metric;
1199 u_int64_t *destu64;
1200 long double *destld;
1177 int retval;
1201 int retval, i;
1178
1179 retval = 0;
1180
1181 /*
1182 * current is the only mandatory field.
1183 */
1184 if (current == NULL) {
1185 snprintf(devstat_errbuf, sizeof(devstat_errbuf),
1186 "%s: current stats structure was NULL", func_name);
1187 return(-1);
1188 }
1189
1202
1203 retval = 0;
1204
1205 /*
1206 * current is the only mandatory field.
1207 */
1208 if (current == NULL) {
1209 snprintf(devstat_errbuf, sizeof(devstat_errbuf),
1210 "%s: current stats structure was NULL", func_name);
1211 return(-1);
1212 }
1213
1190 totalbytesread = current->bytes[DEVSTAT_READ] -
1191 ((previous) ? previous->bytes[DEVSTAT_READ] : 0);
1192 totalbyteswrite = current->bytes[DEVSTAT_WRITE] -
1193 ((previous) ? previous->bytes[DEVSTAT_WRITE] : 0);
1214 totalbytesread = DELTA(bytes, DEVSTAT_READ);
1215 totalbyteswrite = DELTA(bytes, DEVSTAT_WRITE);
1216 totalbytesfree = DELTA(bytes, DEVSTAT_FREE);
1217 totalbytes = totalbytesread + totalbyteswrite + totalbytesfree;
1194
1218
1195 totalbytes = totalbytesread + totalbyteswrite;
1196
1197 totaltransfersread = current->operations[DEVSTAT_READ] -
1198 ((previous) ? previous->operations[DEVSTAT_READ] : 0);
1199
1200 totaltransferswrite = current->operations[DEVSTAT_WRITE] -
1201 ((previous) ? previous->operations[DEVSTAT_WRITE] : 0);
1202
1203 totaltransfersother = current->operations[DEVSTAT_NO_DATA] -
1204 ((previous) ? previous->operations[DEVSTAT_NO_DATA] : 0);
1205
1219 totaltransfersread = DELTA(operations, DEVSTAT_READ);
1220 totaltransferswrite = DELTA(operations, DEVSTAT_WRITE);
1221 totaltransfersother = DELTA(operations, DEVSTAT_NO_DATA);
1222 totaltransfersfree = DELTA(operations, DEVSTAT_FREE);
1206 totaltransfers = totaltransfersread + totaltransferswrite +
1223 totaltransfers = totaltransfersread + totaltransferswrite +
1207 totaltransfersother;
1224 totaltransfersother + totaltransfersfree;
1208
1209 totalblocks = totalbytes;
1210 totalblocksread = totalbytesread;
1211 totalblockswrite = totalbyteswrite;
1225
1226 totalblocks = totalbytes;
1227 totalblocksread = totalbytesread;
1228 totalblockswrite = totalbyteswrite;
1229 totalblocksfree = totalbytesfree;
1212
1213 if (current->block_size > 0) {
1214 totalblocks /= current->block_size;
1215 totalblocksread /= current->block_size;
1216 totalblockswrite /= current->block_size;
1230
1231 if (current->block_size > 0) {
1232 totalblocks /= current->block_size;
1233 totalblocksread /= current->block_size;
1234 totalblockswrite /= current->block_size;
1235 totalblocksfree /= current->block_size;
1217 } else {
1218 totalblocks /= 512;
1219 totalblocksread /= 512;
1220 totalblockswrite /= 512;
1236 } else {
1237 totalblocks /= 512;
1238 totalblocksread /= 512;
1239 totalblockswrite /= 512;
1240 totalblocksfree /= 512;
1221 }
1222
1223 va_start(ap, etime);
1224
1225 while ((metric = (devstat_metric)va_arg(ap, devstat_metric)) != 0) {
1226
1227 if (metric == DSM_NONE)
1228 break;

--- 30 unchanged lines hidden (view full) ---

1259 *destu64 = totalbytes;
1260 break;
1261 case DSM_TOTAL_BYTES_READ:
1262 *destu64 = totalbytesread;
1263 break;
1264 case DSM_TOTAL_BYTES_WRITE:
1265 *destu64 = totalbyteswrite;
1266 break;
1241 }
1242
1243 va_start(ap, etime);
1244
1245 while ((metric = (devstat_metric)va_arg(ap, devstat_metric)) != 0) {
1246
1247 if (metric == DSM_NONE)
1248 break;

--- 30 unchanged lines hidden (view full) ---

1279 *destu64 = totalbytes;
1280 break;
1281 case DSM_TOTAL_BYTES_READ:
1282 *destu64 = totalbytesread;
1283 break;
1284 case DSM_TOTAL_BYTES_WRITE:
1285 *destu64 = totalbyteswrite;
1286 break;
1287 case DSM_TOTAL_BYTES_FREE:
1288 *destu64 = totalbytesfree;
1289 break;
1267 case DSM_TOTAL_TRANSFERS:
1268 *destu64 = totaltransfers;
1269 break;
1270 case DSM_TOTAL_TRANSFERS_READ:
1271 *destu64 = totaltransfersread;
1272 break;
1273 case DSM_TOTAL_TRANSFERS_WRITE:
1274 *destu64 = totaltransferswrite;
1275 break;
1290 case DSM_TOTAL_TRANSFERS:
1291 *destu64 = totaltransfers;
1292 break;
1293 case DSM_TOTAL_TRANSFERS_READ:
1294 *destu64 = totaltransfersread;
1295 break;
1296 case DSM_TOTAL_TRANSFERS_WRITE:
1297 *destu64 = totaltransferswrite;
1298 break;
1299 case DSM_TOTAL_TRANSFERS_FREE:
1300 *destu64 = totaltransfersfree;
1301 break;
1276 case DSM_TOTAL_TRANSFERS_OTHER:
1277 *destu64 = totaltransfersother;
1278 break;
1279 case DSM_TOTAL_BLOCKS:
1280 *destu64 = totalblocks;
1281 break;
1282 case DSM_TOTAL_BLOCKS_READ:
1283 *destu64 = totalblocksread;
1284 break;
1285 case DSM_TOTAL_BLOCKS_WRITE:
1286 *destu64 = totalblockswrite;
1287 break;
1302 case DSM_TOTAL_TRANSFERS_OTHER:
1303 *destu64 = totaltransfersother;
1304 break;
1305 case DSM_TOTAL_BLOCKS:
1306 *destu64 = totalblocks;
1307 break;
1308 case DSM_TOTAL_BLOCKS_READ:
1309 *destu64 = totalblocksread;
1310 break;
1311 case DSM_TOTAL_BLOCKS_WRITE:
1312 *destu64 = totalblockswrite;
1313 break;
1314 case DSM_TOTAL_BLOCKS_FREE:
1315 *destu64 = totalblocksfree;
1316 break;
1288 case DSM_KB_PER_TRANSFER:
1289 *destld = totalbytes;
1290 *destld /= 1024;
1291 if (totaltransfers > 0)
1292 *destld /= totaltransfers;
1293 else
1294 *destld = 0.0;
1295 break;

--- 8 unchanged lines hidden (view full) ---

1304 case DSM_KB_PER_TRANSFER_WRITE:
1305 *destld = totalbyteswrite;
1306 *destld /= 1024;
1307 if (totaltransferswrite > 0)
1308 *destld /= totaltransferswrite;
1309 else
1310 *destld = 0.0;
1311 break;
1317 case DSM_KB_PER_TRANSFER:
1318 *destld = totalbytes;
1319 *destld /= 1024;
1320 if (totaltransfers > 0)
1321 *destld /= totaltransfers;
1322 else
1323 *destld = 0.0;
1324 break;

--- 8 unchanged lines hidden (view full) ---

1333 case DSM_KB_PER_TRANSFER_WRITE:
1334 *destld = totalbyteswrite;
1335 *destld /= 1024;
1336 if (totaltransferswrite > 0)
1337 *destld /= totaltransferswrite;
1338 else
1339 *destld = 0.0;
1340 break;
1341 case DSM_KB_PER_TRANSFER_FREE:
1342 *destld = totalbytesfree;
1343 *destld /= 1024;
1344 if (totaltransfersfree > 0)
1345 *destld /= totaltransfersfree;
1346 else
1347 *destld = 0.0;
1348 break;
1312 case DSM_TRANSFERS_PER_SECOND:
1313 if (etime > 0.0) {
1314 *destld = totaltransfers;
1315 *destld /= etime;
1316 } else
1317 *destld = 0.0;
1318 break;
1319 case DSM_TRANSFERS_PER_SECOND_READ:

--- 5 unchanged lines hidden (view full) ---

1325 break;
1326 case DSM_TRANSFERS_PER_SECOND_WRITE:
1327 if (etime > 0.0) {
1328 *destld = totaltransferswrite;
1329 *destld /= etime;
1330 } else
1331 *destld = 0.0;
1332 break;
1349 case DSM_TRANSFERS_PER_SECOND:
1350 if (etime > 0.0) {
1351 *destld = totaltransfers;
1352 *destld /= etime;
1353 } else
1354 *destld = 0.0;
1355 break;
1356 case DSM_TRANSFERS_PER_SECOND_READ:

--- 5 unchanged lines hidden (view full) ---

1362 break;
1363 case DSM_TRANSFERS_PER_SECOND_WRITE:
1364 if (etime > 0.0) {
1365 *destld = totaltransferswrite;
1366 *destld /= etime;
1367 } else
1368 *destld = 0.0;
1369 break;
1370 case DSM_TRANSFERS_PER_SECOND_FREE:
1371 if (etime > 0.0) {
1372 *destld = totaltransfersfree;
1373 *destld /= etime;
1374 } else
1375 *destld = 0.0;
1376 break;
1333 case DSM_TRANSFERS_PER_SECOND_OTHER:
1334 if (etime > 0.0) {
1335 *destld = totaltransfersother;
1336 *destld /= etime;
1337 } else
1338 *destld = 0.0;
1339 break;
1340 case DSM_MB_PER_SECOND:

--- 15 unchanged lines hidden (view full) ---

1356 case DSM_MB_PER_SECOND_WRITE:
1357 *destld = totalbyteswrite;
1358 *destld /= 1024 * 1024;
1359 if (etime > 0.0)
1360 *destld /= etime;
1361 else
1362 *destld = 0.0;
1363 break;
1377 case DSM_TRANSFERS_PER_SECOND_OTHER:
1378 if (etime > 0.0) {
1379 *destld = totaltransfersother;
1380 *destld /= etime;
1381 } else
1382 *destld = 0.0;
1383 break;
1384 case DSM_MB_PER_SECOND:

--- 15 unchanged lines hidden (view full) ---

1400 case DSM_MB_PER_SECOND_WRITE:
1401 *destld = totalbyteswrite;
1402 *destld /= 1024 * 1024;
1403 if (etime > 0.0)
1404 *destld /= etime;
1405 else
1406 *destld = 0.0;
1407 break;
1408 case DSM_MB_PER_SECOND_FREE:
1409 *destld = totalbytesfree;
1410 *destld /= 1024 * 1024;
1411 if (etime > 0.0)
1412 *destld /= etime;
1413 else
1414 *destld = 0.0;
1415 break;
1364 case DSM_BLOCKS_PER_SECOND:
1365 *destld = totalblocks;
1366 if (etime > 0.0)
1367 *destld /= etime;
1368 else
1369 *destld = 0.0;
1370 break;
1371 case DSM_BLOCKS_PER_SECOND_READ:

--- 5 unchanged lines hidden (view full) ---

1377 break;
1378 case DSM_BLOCKS_PER_SECOND_WRITE:
1379 *destld = totalblockswrite;
1380 if (etime > 0.0)
1381 *destld /= etime;
1382 else
1383 *destld = 0.0;
1384 break;
1416 case DSM_BLOCKS_PER_SECOND:
1417 *destld = totalblocks;
1418 if (etime > 0.0)
1419 *destld /= etime;
1420 else
1421 *destld = 0.0;
1422 break;
1423 case DSM_BLOCKS_PER_SECOND_READ:

--- 5 unchanged lines hidden (view full) ---

1429 break;
1430 case DSM_BLOCKS_PER_SECOND_WRITE:
1431 *destld = totalblockswrite;
1432 if (etime > 0.0)
1433 *destld /= etime;
1434 else
1435 *destld = 0.0;
1436 break;
1437 case DSM_BLOCKS_PER_SECOND_FREE:
1438 *destld = totalblocksfree;
1439 if (etime > 0.0)
1440 *destld /= etime;
1441 else
1442 *destld = 0.0;
1443 break;
1385 /*
1386 * This calculation is somewhat bogus. It simply divides
1387 * the elapsed time by the total number of transactions
1388 * completed. While that does give the caller a good
1389 * picture of the average rate of transaction completion,
1390 * it doesn't necessarily give the caller a good view of
1391 * how long transactions took to complete on average.
1392 * Those two numbers will be different for a device that

--- 4 unchanged lines hidden (view full) ---

1397 * time per transaction would be to compute and store the
1398 * time on a per-transaction basis. That currently isn't
1399 * done in the kernel, and would only be desireable if it
1400 * could be implemented in a somewhat non-intrusive and high
1401 * performance way.
1402 */
1403 case DSM_MS_PER_TRANSACTION:
1404 if (totaltransfers > 0) {
1444 /*
1445 * This calculation is somewhat bogus. It simply divides
1446 * the elapsed time by the total number of transactions
1447 * completed. While that does give the caller a good
1448 * picture of the average rate of transaction completion,
1449 * it doesn't necessarily give the caller a good view of
1450 * how long transactions took to complete on average.
1451 * Those two numbers will be different for a device that

--- 4 unchanged lines hidden (view full) ---

1456 * time per transaction would be to compute and store the
1457 * time on a per-transaction basis. That currently isn't
1458 * done in the kernel, and would only be desireable if it
1459 * could be implemented in a somewhat non-intrusive and high
1460 * performance way.
1461 */
1462 case DSM_MS_PER_TRANSACTION:
1463 if (totaltransfers > 0) {
1405 *destld = etime;
1464 *destld = 0;
1465 for (i = 0; i < DEVSTAT_N_TRANS_FLAGS; i++)
1466 *destld += DELTA_T(duration[i]);
1406 *destld /= totaltransfers;
1407 *destld *= 1000;
1408 } else
1409 *destld = 0.0;
1410 break;
1411 /*
1412 * As above, these next two really only give the average
1413 * rate of completion for read and write transactions, not
1414 * the average time the transaction took to complete.
1415 */
1416 case DSM_MS_PER_TRANSACTION_READ:
1417 if (totaltransfersread > 0) {
1467 *destld /= totaltransfers;
1468 *destld *= 1000;
1469 } else
1470 *destld = 0.0;
1471 break;
1472 /*
1473 * As above, these next two really only give the average
1474 * rate of completion for read and write transactions, not
1475 * the average time the transaction took to complete.
1476 */
1477 case DSM_MS_PER_TRANSACTION_READ:
1478 if (totaltransfersread > 0) {
1418 *destld = etime;
1479 *destld = DELTA_T(duration[DEVSTAT_READ]);
1419 *destld /= totaltransfersread;
1420 *destld *= 1000;
1421 } else
1422 *destld = 0.0;
1423 break;
1424 case DSM_MS_PER_TRANSACTION_WRITE:
1425 if (totaltransferswrite > 0) {
1480 *destld /= totaltransfersread;
1481 *destld *= 1000;
1482 } else
1483 *destld = 0.0;
1484 break;
1485 case DSM_MS_PER_TRANSACTION_WRITE:
1486 if (totaltransferswrite > 0) {
1426 *destld = etime;
1487 *destld = DELTA_T(duration[DEVSTAT_WRITE]);
1427 *destld /= totaltransferswrite;
1428 *destld *= 1000;
1429 } else
1430 *destld = 0.0;
1431 break;
1488 *destld /= totaltransferswrite;
1489 *destld *= 1000;
1490 } else
1491 *destld = 0.0;
1492 break;
1493 case DSM_MS_PER_TRANSACTION_FREE:
1494 if (totaltransfersfree > 0) {
1495 *destld = DELTA_T(duration[DEVSTAT_FREE]);
1496 *destld /= totaltransfersfree;
1497 *destld *= 1000;
1498 } else
1499 *destld = 0.0;
1500 break;
1501 case DSM_MS_PER_TRANSACTION_OTHER:
1502 if (totaltransfersother > 0) {
1503 *destld = DELTA_T(duration[DEVSTAT_NO_DATA]);
1504 *destld /= totaltransfersother;
1505 *destld *= 1000;
1506 } else
1507 *destld = 0.0;
1508 break;
1509 case DSM_BUSY_PCT:
1510 *destld = DELTA_T(busy_time);
1511 if (*destld < 0)
1512 *destld = 0;
1513 *destld /= etime;
1514 *destld *= 100;
1515 break;
1516 case DSM_QUEUE_LENGTH:
1517 *destu64 = current->start_count - current->end_count;
1518 break;
1519/*
1520 * XXX: comment out the default block to see if any case's are missing.
1521 */
1522#if 1
1432 default:
1433 /*
1434 * This shouldn't happen, since we should have
1435 * caught any out of range metrics at the top of
1436 * the loop.
1437 */
1438 snprintf(devstat_errbuf, sizeof(devstat_errbuf),
1439 "%s: unknown metric %d", func_name, metric);
1440 retval = -1;
1441 goto bailout;
1442 break; /* NOTREACHED */
1523 default:
1524 /*
1525 * This shouldn't happen, since we should have
1526 * caught any out of range metrics at the top of
1527 * the loop.
1528 */
1529 snprintf(devstat_errbuf, sizeof(devstat_errbuf),
1530 "%s: unknown metric %d", func_name, metric);
1531 retval = -1;
1532 goto bailout;
1533 break; /* NOTREACHED */
1534#endif
1443 }
1444 }
1445
1446bailout:
1447
1448 va_end(ap);
1449 return(retval);
1450}

--- 89 unchanged lines hidden ---
1535 }
1536 }
1537
1538bailout:
1539
1540 va_end(ap);
1541 return(retval);
1542}

--- 89 unchanged lines hidden ---