Index: block.c =================================================================== RCS file: /sources/qemu/qemu/block.c,v retrieving revision 1.47 diff -u -r1.47 block.c --- block.c 11 Nov 2007 02:51:16 -0000 1.47 +++ block.c 16 Nov 2007 15:23:44 -0000 @@ -522,8 +522,12 @@ return ret; else if (ret != len) return -EINVAL; - else + else { + bs->rd_bytes += (unsigned) len; + bs->rd_sects += (unsigned) nb_sectors; + bs->rd_ops ++; return 0; + } } else { return drv->bdrv_read(bs, sector_num, buf, nb_sectors); } @@ -554,8 +558,12 @@ return ret; else if (ret != len) return -EIO; - else + else { + bs->wr_bytes += (unsigned) len; + bs->wr_sects += (unsigned) nb_sectors; + bs->wr_ops ++; return 0; + } } else { return drv->bdrv_write(bs, sector_num, buf, nb_sectors); } @@ -903,6 +911,27 @@ 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(sectors)=%" PRIu64 + " wr(sectors)=%" PRIu64 + " rd(operations)=%" PRIu64 + " wr(operations)=%" PRIu64 + "\n", + bs->device_name, + bs->rd_bytes, bs->wr_bytes, + bs->rd_sects, bs->wr_sects, + bs->rd_ops, bs->wr_ops); + } +} #endif void bdrv_get_backing_filename(BlockDriverState *bs, @@ -1065,6 +1094,7 @@ BlockDriverCompletionFunc *cb, void *opaque) { BlockDriver *drv = bs->drv; + BlockDriverAIOCB *ret; if (!drv) return NULL; @@ -1077,7 +1107,16 @@ 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_sects += (unsigned) nb_sectors; + bs->rd_ops ++; + } + + return ret; } BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num, @@ -1085,6 +1124,7 @@ BlockDriverCompletionFunc *cb, void *opaque) { BlockDriver *drv = bs->drv; + BlockDriverAIOCB *ret; if (!drv) return NULL; @@ -1094,7 +1134,16 @@ 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_sects += (unsigned) nb_sectors; + bs->wr_ops ++; + } + + return ret; } void bdrv_aio_cancel(BlockDriverAIOCB *acb) Index: block.h =================================================================== RCS file: /sources/qemu/qemu/block.h,v retrieving revision 1.1 diff -u -r1.1 block.h --- block.h 11 Nov 2007 02:51:16 -0000 1.1 +++ block.h 16 Nov 2007 15:23:44 -0000 @@ -48,6 +48,7 @@ #ifndef QEMU_IMG void bdrv_info(void); +void bdrv_info_stats(void); #endif void bdrv_init(void); Index: block_int.h =================================================================== RCS file: /sources/qemu/qemu/block_int.h,v retrieving revision 1.14 diff -u -r1.14 block_int.h --- block_int.h 11 Nov 2007 02:51:16 -0000 1.14 +++ block_int.h 16 Nov 2007 15:23:44 -0000 @@ -114,6 +114,14 @@ void *sync_aiocb; + /* I/O stats (display with "info blockstats"). */ + uint64_t rd_bytes; + uint64_t wr_bytes; + uint64_t rd_sects; + uint64_t wr_sects; + 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; Index: monitor.c =================================================================== RCS file: /sources/qemu/qemu/monitor.c,v retrieving revision 1.85 diff -u -r1.85 monitor.c --- monitor.c 26 Oct 2007 18:42:57 -0000 1.85 +++ monitor.c 16 Nov 2007 15:23:46 -0000 @@ -249,6 +249,11 @@ 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) { @@ -1321,6 +1326,8 @@ "", "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,