This patch collects per-block-device statistics and allows them to be displayed in the monitor through a 'info blockstats' command. It generalises the VMDK-only support for this which was added to KVM's version of QEMU.
Proposed patch: http://lists.gnu.org/archive/html/qemu-devel/2007-11/msg00770.html Accepted into QEMU: http://lists.gnu.org/archive/html/qemu-devel/2007-12/msg00013.htmlThe QEMU patch doesn't quite apply directly because KVM has no file qemu/block.h. Attached is a rebased patch against the current kvm-userspace.
Rich. -- Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/ Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 03798903
diff --git a/qemu/block.c b/qemu/block.c
index 20d2e1c..20296c5 100644
--- a/qemu/block.c
+++ b/qemu/block.c
@@ -518,8 +518,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);
}
@@ -550,8 +553,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);
}
@@ -914,6 +920,25 @@ void bdrv_info(void)
}
}
+/* 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);
+ }
+}
+
+
void bdrv_get_backing_filename(BlockDriverState *bs,
char *filename, int filename_size)
{
@@ -1074,6 +1099,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;
@@ -1086,7 +1112,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,
@@ -1094,6 +1128,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;
@@ -1103,7 +1138,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)
diff --git a/qemu/block_int.h b/qemu/block_int.h
index b034023..d3f9fda 100644
--- a/qemu/block_int.h
+++ b/qemu/block_int.h
@@ -112,6 +112,12 @@ struct BlockDriverState {
void *sync_aiocb;
+ /* I/O stats (display with "info blockstats"). */
+ uint64_t rd_bytes;
+ uint64_t wr_bytes;
+ uint64_t rd_ops;
+ uint64_t wr_ops;
+
/* NOTE: the following infos are only hints for real hardware
drivers. They are not used by the block driver */
int cyls, heads, secs, translation;
diff --git a/qemu/monitor.c b/qemu/monitor.c
index 10e0af9..a7f4490 100644
--- a/qemu/monitor.c
+++ b/qemu/monitor.c
@@ -251,6 +251,11 @@ static void do_info_block(void)
bdrv_info();
}
+static void do_info_blockstats(void)
+{
+ bdrv_info_stats();
+}
+
/* get the current CPU defined by the user */
int mon_set_cpu(int cpu_index)
{
@@ -1389,6 +1394,8 @@ static term_cmd_t info_cmds[] = {
"", "show the network state" },
{ "block", "", do_info_block,
"", "show the block devices" },
+ { "blockstats", "", do_info_blockstats,
+ "", "show block device statistics" },
{ "registers", "", do_info_registers,
"", "show the cpu registers" },
{ "cpus", "", do_info_cpus,
diff --git a/qemu/vl.h b/qemu/vl.h
index 01aeabc..c07a104 100644
--- a/qemu/vl.h
+++ b/qemu/vl.h
@@ -729,6 +729,7 @@ void bdrv_set_change_cb(BlockDriverState *bs,
void (*change_cb)(void *opaque), void *opaque);
void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size);
void bdrv_info(void);
+void bdrv_info_stats(void);
BlockDriverState *bdrv_find(const char *name);
void bdrv_iterate(void (*it)(void *opaque, const char *name), void *opaque);
int bdrv_is_encrypted(BlockDriverState *bs);
smime.p7s
Description: S/MIME Cryptographic Signature
------------------------------------------------------------------------- SF.Net email is sponsored by: The Future of Linux Business White Paper from Novell. From the desktop to the data center, Linux is going mainstream. Let it simplify your IT future. http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________ kvm-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/kvm-devel
