* [Qemu-devel] [PATCH] Collecting block device statistics
@ 2007-11-16 15:29 Richard W.M. Jones
2007-11-16 18:46 ` Daniel P. Berrange
0 siblings, 1 reply; 2+ messages in thread
From: Richard W.M. Jones @ 2007-11-16 15:29 UTC (permalink / raw)
To: qemu-devel
[-- Attachment #1.1: Type: text/plain, Size: 855 bytes --]
Hi,
I was looking for a way to collect information on the amount of data
being written and read from block devices. The attached patch adds a
few counters to the BlockDriverState structure to collect this
information, and a new "info blockstats" monitor command to display it.
This screenshot shows it in action:
http://www.annexia.org/tmp/Screenshot-QEMU.png
This is the sort of feature I'd really like to see merged into qemu
because it will let us enhance libvirt to centrally collect these stats
from qemu instances.
Any comments or feedback about this are most welcome.
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
[-- Attachment #1.2: qemu-blockstats.patch --]
[-- Type: text/x-patch, Size: 4898 bytes --]
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,
[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/x-pkcs7-signature, Size: 3237 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] Collecting block device statistics
2007-11-16 15:29 [Qemu-devel] [PATCH] Collecting block device statistics Richard W.M. Jones
@ 2007-11-16 18:46 ` Daniel P. Berrange
0 siblings, 0 replies; 2+ messages in thread
From: Daniel P. Berrange @ 2007-11-16 18:46 UTC (permalink / raw)
To: qemu-devel
On Fri, Nov 16, 2007 at 03:29:48PM +0000, Richard W.M. Jones wrote:
> Hi,
>
> I was looking for a way to collect information on the amount of data
> being written and read from block devices. The attached patch adds a
> few counters to the BlockDriverState structure to collect this
> information, and a new "info blockstats" monitor command to display it.
>
> This screenshot shows it in action:
>
> http://www.annexia.org/tmp/Screenshot-QEMU.png
>
> This is the sort of feature I'd really like to see merged into qemu
> because it will let us enhance libvirt to centrally collect these stats
> from qemu instances.
It looks good to me - this would be a very useful feature addition.
Regards,
Dan.
--
|=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=|
|=- Perl modules: http://search.cpan.org/~danberr/ -=|
|=- Projects: http://freshmeat.net/~danielpb/ -=|
|=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=|
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-11-16 18:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-16 15:29 [Qemu-devel] [PATCH] Collecting block device statistics Richard W.M. Jones
2007-11-16 18:46 ` Daniel P. Berrange
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).