From: "Richard W.M. Jones" <rjones@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Collecting block device statistics
Date: Fri, 16 Nov 2007 15:29:48 +0000 [thread overview]
Message-ID: <473DB76C.8050109@redhat.com> (raw)
[-- 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 --]
next reply other threads:[~2007-11-16 15:31 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-16 15:29 Richard W.M. Jones [this message]
2007-11-16 18:46 ` [Qemu-devel] [PATCH] Collecting block device statistics Daniel P. Berrange
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=473DB76C.8050109@redhat.com \
--to=rjones@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).