diff --git a/src/disk.c b/src/disk.c
index f319c9c6da408808b08c80870c4aad72e712ac7c..3b8dbb94f4d71b4519cd434e4da3a9d45bc61275 100644 (file)
--- a/src/disk.c
+++ b/src/disk.c
static diskstats_t *disklist;
/* #endif KERNEL_LINUX */
#elif KERNEL_FREEBSD
-static void *snap_previous;
-static struct timespec tsnap_previous;
static struct gmesh geom_tree;
/* #endif KERNEL_FREEBSD */
ERROR ("geom_stats_open() failed, returned %d", rv);
return (-1);
}
- snap_previous = geom_stats_snapshot_get();
- if (snap_previous == NULL) {
- ERROR ("geom_stats_snapshot_get() failed");
- return (-1);
- }
- geom_stats_snapshot_timestamp(snap_previous, &tsnap_previous);
/* #endif KERNEL_FREEBSD */
#elif HAVE_LIBKSTAT
#elif KERNEL_FREEBSD
int retry, dirty;
- void *snap_present = NULL;
- struct devstat *snap_present_iter, *snap_previous_iter;
- struct timespec tsnap_present;
+ void *snap = NULL;
+ struct devstat *snap_iter;
struct gident *geom_id;
- double timedelta;
- long double ld[11];
const char *disk_name;
- derive_t read_bytes, write_bytes;
- derive_t read_ops, write_ops;
- derive_t read_time, write_time;
+ uint64_t read_bytes, write_bytes;
+ uint64_t read_ops, write_ops;
+ long double read_time, write_time;
for (retry = 0, dirty = 1; retry < 5 && dirty == 1; retry++) {
- if (snap_present != NULL)
- geom_stats_snapshot_free(snap_present);
+ if (snap != NULL)
+ geom_stats_snapshot_free(snap);
/* Get a fresh copy of stats snapshot */
- snap_present = geom_stats_snapshot_get();
- if (snap_present == NULL) {
+ snap = geom_stats_snapshot_get();
+ if (snap == NULL) {
ERROR("disk plugin: geom_stats_snapshot_get() failed.");
return (-1);
}
/* Check if we have dirty read from this snapshot */
dirty = 0;
- geom_stats_snapshot_reset(snap_present);
- while ((snap_present_iter = geom_stats_snapshot_next(snap_present)) != NULL) {
- if (snap_present_iter->id == NULL)
+ geom_stats_snapshot_reset(snap);
+ while ((snap_iter = geom_stats_snapshot_next(snap)) != NULL) {
+ if (snap_iter->id == NULL)
continue;
- geom_id = geom_lookupid(&geom_tree, snap_present_iter->id);
+ geom_id = geom_lookupid(&geom_tree, snap_iter->id);
/* New device? refresh GEOM tree */
if (geom_id == NULL) {
geom_deletetree(&geom_tree);
if (geom_gettree(&geom_tree) != 0) {
ERROR("disk plugin: geom_gettree() failed");
- geom_stats_snapshot_free(snap_present);
+ geom_stats_snapshot_free(snap);
return (-1);
}
- geom_id = geom_lookupid(&geom_tree, snap_present_iter->id);
+ geom_id = geom_lookupid(&geom_tree, snap_iter->id);
}
/*
* This should be rare: the device come right before we take the
continue;
/* Check if this is a dirty read quit for another try */
- if (snap_present_iter->sequence0 != snap_present_iter->sequence1) {
+ if (snap_iter->sequence0 != snap_iter->sequence1) {
dirty = 1;
break;
}
}
}
- /*
- * Now we have a snapshot that is either clean, or still dirty after 5
- * reads.
- */
- geom_stats_snapshot_timestamp(snap_present, &tsnap_present);
- timedelta = tsnap_present.tv_sec - tsnap_previous.tv_sec;
- timedelta += (tsnap_present.tv_nsec - tsnap_previous.tv_nsec) * 1e-9;
- tsnap_previous = tsnap_present;
-
- /* Reset iterators for both snapshots */
- geom_stats_snapshot_reset(snap_present);
- geom_stats_snapshot_reset(snap_previous);
+ /* Reset iterator */
+ geom_stats_snapshot_reset(snap);
for (;;) {
- snap_present_iter = geom_stats_snapshot_next(snap_present);
- snap_previous_iter = geom_stats_snapshot_next(snap_previous);
- if (snap_present_iter == NULL || snap_previous_iter == NULL)
+ snap_iter = geom_stats_snapshot_next(snap);
+ if (snap_iter == NULL)
break;
- if (snap_present_iter->id == NULL)
+ if (snap_iter->id == NULL)
continue;
- geom_id = geom_lookupid(&geom_tree, snap_present_iter->id);
+ geom_id = geom_lookupid(&geom_tree, snap_iter->id);
if (geom_id == NULL)
continue;
if (geom_id->lg_what != ISPROVIDER)
if (((struct gprovider *)(geom_id->lg_ptr))->lg_geom->lg_rank != 1)
continue;
/* Skip dirty reads, if present */
- if (dirty && (snap_present_iter->sequence0 != snap_present_iter->sequence1))
+ if (dirty && (snap_iter->sequence0 != snap_iter->sequence1))
continue;
- devstat_compute_statistics(snap_present_iter, snap_previous_iter, timedelta,
- DSM_TRANSFERS_PER_SECOND, &ld[0],
-
- DSM_TRANSFERS_PER_SECOND_READ, &ld[1],
- DSM_MB_PER_SECOND_READ, &ld[2],
- DSM_MS_PER_TRANSACTION_READ, &ld[3],
-
- DSM_TRANSFERS_PER_SECOND_WRITE, &ld[4],
- DSM_MB_PER_SECOND_WRITE, &ld[5],
- DSM_MS_PER_TRANSACTION_WRITE, &ld[6],
+ devstat_compute_statistics(snap_iter, NULL, 10.0,
+ DSM_TOTAL_TRANSFERS_READ, &read_ops,
+ DSM_TOTAL_BYTES_READ, &read_bytes,
+ DSM_TOTAL_DURATION_READ, &read_time,
- DSM_BUSY_PCT, &ld[7],
+ DSM_TOTAL_TRANSFERS_WRITE, &write_ops,
+ DSM_TOTAL_BYTES_WRITE, &write_bytes,
+ DSM_TOTAL_DURATION_WRITE, &write_time,
- DSM_TRANSFERS_PER_SECOND_FREE, &ld[8],
- DSM_MB_PER_SECOND_FREE, &ld[9],
- DSM_MS_PER_TRANSACTION_FREE, &ld[10],
DSM_NONE);
- *snap_previous_iter = *snap_present_iter;
-
- /* Derive data to be submitted */
- read_ops = (derive_t)ld[1];
- write_ops = (derive_t)ld[4];
- read_bytes = (derive_t)(ld[2] * 1048576LL);
- write_bytes = (derive_t)(ld[5] * 1048576LL);
- read_time = (derive_t)ld[3];
- write_time = (derive_t)ld[6];
disk_name = ((struct gprovider *)geom_id->lg_ptr)->lg_name;
if ((read_bytes != 0) || (write_bytes != 0))
disk_submit(disk_name, "disk_octets",
- read_bytes, write_bytes);
+ (derive_t)read_bytes, (derive_t)write_bytes);
if ((read_ops != 0) || (write_ops != 0))
disk_submit(disk_name, "disk_ops",
- read_ops, write_ops);
+ (derive_t)read_ops, (derive_t)write_ops);
- if ((read_time != 0) || (write_time != 0))
+ if ((read_time != 0) || (write_time != 0)) {
disk_submit (disk_name, "disk_time",
- read_time, write_time);
-
- /* TODO: TRIM statistics collected but not reported. */
+ (derive_t)(read_time*1000), (derive_t)(write_time*1000));
+ }
}
- geom_stats_snapshot_free(snap_present);
+ geom_stats_snapshot_free(snap);
#elif KERNEL_LINUX
FILE *fh;