56 |
|
#include <sys/dkstat.h> |
57 |
|
#include <devstat.h> |
58 |
|
#endif |
59 |
+ |
#ifdef NETBSD |
60 |
+ |
#include <sys/param.h> |
61 |
+ |
#include <sys/sysctl.h> |
62 |
+ |
#include <sys/disk.h> |
63 |
+ |
#endif |
64 |
|
|
65 |
|
#define START_VAL 1 |
66 |
|
|
347 |
|
struct devstat *dev_ptr; |
348 |
|
#endif |
349 |
|
#ifdef NETBSD |
350 |
< |
/* FIXME get_diskio_stats NYI on NetBSD. |
351 |
< |
* See vmstat/dkstats.c in NetBSD source for examples. |
352 |
< |
*/ |
350 |
> |
struct disk_sysctl *stats; |
351 |
> |
int num_disks, i; |
352 |
> |
int mib[3]; |
353 |
> |
size_t size; |
354 |
|
#endif |
355 |
+ |
|
356 |
|
num_diskio=0; |
357 |
+ |
|
358 |
+ |
#ifdef NETBSD |
359 |
+ |
mib[0] = CTL_HW; |
360 |
+ |
mib[1] = HW_DISKSTATS; |
361 |
+ |
mib[2] = sizeof(struct disk_sysctl); |
362 |
+ |
|
363 |
+ |
if (sysctl(mib, 3, NULL, &size, NULL, 0) < 0) { |
364 |
+ |
return NULL; |
365 |
+ |
} |
366 |
+ |
num_disks = size / sizeof(struct disk_sysctl); |
367 |
+ |
|
368 |
+ |
stats = malloc(size); |
369 |
+ |
if (stats == NULL) { |
370 |
+ |
return NULL; |
371 |
+ |
} |
372 |
+ |
|
373 |
+ |
if (sysctl(mib, 3, stats, &size, NULL, 0) < 0) { |
374 |
+ |
return NULL; |
375 |
+ |
} |
376 |
+ |
|
377 |
+ |
for (i = 0; i < num_disks; i++) { |
378 |
+ |
u_int64_t rbytes, wbytes; |
379 |
+ |
|
380 |
+ |
#ifdef HAVE_DK_RBYTES |
381 |
+ |
rbytes = stats[i].dk_rbytes; |
382 |
+ |
wbytes = stats[i].dk_wbytes; |
383 |
+ |
#else |
384 |
+ |
/* Before 1.6.1, NetBSD merged reads and writes. */ |
385 |
+ |
rbytes = wbytes = stats[i].dk_bytes; |
386 |
+ |
#endif |
387 |
+ |
|
388 |
+ |
/* Don't keep stats for disks that have never been used. */ |
389 |
+ |
if (rbytes == 0 && wbytes == 0) { |
390 |
+ |
continue; |
391 |
+ |
} |
392 |
+ |
|
393 |
+ |
diskio_stats = diskio_stat_malloc(num_diskio + 1, |
394 |
+ |
&sizeof_diskio_stats, |
395 |
+ |
diskio_stats); |
396 |
+ |
if (diskio_stats == NULL) { |
397 |
+ |
return NULL; |
398 |
+ |
} |
399 |
+ |
diskio_stats_ptr = diskio_stats + num_diskio; |
400 |
+ |
|
401 |
+ |
diskio_stats_ptr->read_bytes = rbytes; |
402 |
+ |
diskio_stats_ptr->write_bytes = wbytes; |
403 |
+ |
if (diskio_stats_ptr->disk_name != NULL) { |
404 |
+ |
free(diskio_stats_ptr->disk_name); |
405 |
+ |
} |
406 |
+ |
diskio_stats_ptr->disk_name = strdup(stats[i].dk_name); |
407 |
+ |
diskio_stats_ptr->systime = time(NULL); |
408 |
+ |
|
409 |
+ |
num_diskio++; |
410 |
+ |
} |
411 |
+ |
|
412 |
+ |
free(stats); |
413 |
+ |
#endif |
414 |
|
|
415 |
|
#ifdef FREEBSD |
416 |
|
if (!stats_init) { |