aboutsummaryrefslogtreecommitdiff
path: root/block.c
diff options
context:
space:
mode:
authorths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2007-12-02 05:18:19 +0000
committerths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>2007-12-02 05:18:19 +0000
commita36e69ddfe8452211bcf3ed94716c60bce5ccd8c (patch)
tree3d39dc151f5488c21f9e7635aa889e7420aea5c7 /block.c
parente4bcb14c79fb63a35aef3eb39e02c16c19b8b28d (diff)
Collecting block device statistics, by Richard W.M. Jones.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3760 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'block.c')
-rw-r--r--block.c50
1 files changed, 46 insertions, 4 deletions
diff --git a/block.c b/block.c
index ca8d8c1e8a..3cb3cc22dc 100644
--- a/block.c
+++ b/block.c
@@ -521,8 +521,11 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num,
return ret;
else if (ret != len)
return -EINVAL;
- else
+ else {
+ bs->rd_bytes += (unsigned) len;
+ bs->rd_ops ++;
return 0;
+ }
} else {
return drv->bdrv_read(bs, sector_num, buf, nb_sectors);
}
@@ -553,8 +556,11 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num,
return ret;
else if (ret != len)
return -EIO;
- else
+ else {
+ bs->wr_bytes += (unsigned) len;
+ bs->wr_ops ++;
return 0;
+ }
} else {
return drv->bdrv_write(bs, sector_num, buf, nb_sectors);
}
@@ -902,6 +908,24 @@ void bdrv_info(void)
term_printf("\n");
}
}
+
+/* The "info blockstats" command. */
+void bdrv_info_stats (void)
+{
+ BlockDriverState *bs;
+
+ for (bs = bdrv_first; bs != NULL; bs = bs->next) {
+ term_printf ("%s:"
+ " rd_bytes=%" PRIu64
+ " wr_bytes=%" PRIu64
+ " rd_operations=%" PRIu64
+ " wr_operations=%" PRIu64
+ "\n",
+ bs->device_name,
+ bs->rd_bytes, bs->wr_bytes,
+ bs->rd_ops, bs->wr_ops);
+ }
+}
#endif
void bdrv_get_backing_filename(BlockDriverState *bs,
@@ -1064,6 +1088,7 @@ BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, int64_t sector_num,
BlockDriverCompletionFunc *cb, void *opaque)
{
BlockDriver *drv = bs->drv;
+ BlockDriverAIOCB *ret;
if (!drv)
return NULL;
@@ -1076,7 +1101,15 @@ BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, int64_t sector_num,
buf += 512;
}
- return drv->bdrv_aio_read(bs, sector_num, buf, nb_sectors, cb, opaque);
+ ret = drv->bdrv_aio_read(bs, sector_num, buf, nb_sectors, cb, opaque);
+
+ if (ret) {
+ /* Update stats even though technically transfer has not happened. */
+ bs->rd_bytes += (unsigned) nb_sectors * SECTOR_SIZE;
+ bs->rd_ops ++;
+ }
+
+ return ret;
}
BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
@@ -1084,6 +1117,7 @@ BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
BlockDriverCompletionFunc *cb, void *opaque)
{
BlockDriver *drv = bs->drv;
+ BlockDriverAIOCB *ret;
if (!drv)
return NULL;
@@ -1093,7 +1127,15 @@ BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
memcpy(bs->boot_sector_data, buf, 512);
}
- return drv->bdrv_aio_write(bs, sector_num, buf, nb_sectors, cb, opaque);
+ ret = drv->bdrv_aio_write(bs, sector_num, buf, nb_sectors, cb, opaque);
+
+ if (ret) {
+ /* Update stats even though technically transfer has not happened. */
+ bs->wr_bytes += (unsigned) nb_sectors * SECTOR_SIZE;
+ bs->wr_ops ++;
+ }
+
+ return ret;
}
void bdrv_aio_cancel(BlockDriverAIOCB *acb)