'info blockstats' to collect block device statistics
I wonder if KVM would be interested in taking my QEMU patch to support block device statistics.
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.html
The 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.
Signature · 4 lines
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
qemu/block.c +47 -4
@@ -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)
qemu/block_int.h +6 -0
@@ -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;
qemu/monitor.c +7 -0
@@ -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,
qemu/vl.h +1 -0
@@ -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);
-------------------------------------------------------------------------
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
Quoted 11 lines · Richard W.M. Jones
I wonder if KVM would be interested in taking my QEMU patch to support block device statistics.
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
Quoted 9 lines
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.
we will do merge with qemu cvs soon (i hope) and it probably will be the best way to apply your patch
-------------------------------------------------------------------------
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