Collecting block device statistics, by Richard W.M. Jones.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3760 c046a42c-6fe2-441c-8c8c-71466251a162
This commit is contained in:
parent
e4bcb14c79
commit
a36e69ddfe
50
block.c
50
block.c
@ -521,8 +521,11 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num,
|
|||||||
return ret;
|
return ret;
|
||||||
else if (ret != len)
|
else if (ret != len)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
else
|
else {
|
||||||
|
bs->rd_bytes += (unsigned) len;
|
||||||
|
bs->rd_ops ++;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return drv->bdrv_read(bs, sector_num, buf, nb_sectors);
|
return drv->bdrv_read(bs, sector_num, buf, nb_sectors);
|
||||||
}
|
}
|
||||||
@ -553,8 +556,11 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num,
|
|||||||
return ret;
|
return ret;
|
||||||
else if (ret != len)
|
else if (ret != len)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
else
|
else {
|
||||||
|
bs->wr_bytes += (unsigned) len;
|
||||||
|
bs->wr_ops ++;
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return drv->bdrv_write(bs, sector_num, buf, nb_sectors);
|
return drv->bdrv_write(bs, sector_num, buf, nb_sectors);
|
||||||
}
|
}
|
||||||
@ -902,6 +908,24 @@ void bdrv_info(void)
|
|||||||
term_printf("\n");
|
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_operations=%" PRIu64
|
||||||
|
" wr_operations=%" PRIu64
|
||||||
|
"\n",
|
||||||
|
bs->device_name,
|
||||||
|
bs->rd_bytes, bs->wr_bytes,
|
||||||
|
bs->rd_ops, bs->wr_ops);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void bdrv_get_backing_filename(BlockDriverState *bs,
|
void bdrv_get_backing_filename(BlockDriverState *bs,
|
||||||
@ -1064,6 +1088,7 @@ BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, int64_t sector_num,
|
|||||||
BlockDriverCompletionFunc *cb, void *opaque)
|
BlockDriverCompletionFunc *cb, void *opaque)
|
||||||
{
|
{
|
||||||
BlockDriver *drv = bs->drv;
|
BlockDriver *drv = bs->drv;
|
||||||
|
BlockDriverAIOCB *ret;
|
||||||
|
|
||||||
if (!drv)
|
if (!drv)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1076,7 +1101,15 @@ BlockDriverAIOCB *bdrv_aio_read(BlockDriverState *bs, int64_t sector_num,
|
|||||||
buf += 512;
|
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,
|
BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
|
||||||
@ -1084,6 +1117,7 @@ BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
|
|||||||
BlockDriverCompletionFunc *cb, void *opaque)
|
BlockDriverCompletionFunc *cb, void *opaque)
|
||||||
{
|
{
|
||||||
BlockDriver *drv = bs->drv;
|
BlockDriver *drv = bs->drv;
|
||||||
|
BlockDriverAIOCB *ret;
|
||||||
|
|
||||||
if (!drv)
|
if (!drv)
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1093,7 +1127,15 @@ BlockDriverAIOCB *bdrv_aio_write(BlockDriverState *bs, int64_t sector_num,
|
|||||||
memcpy(bs->boot_sector_data, buf, 512);
|
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)
|
void bdrv_aio_cancel(BlockDriverAIOCB *acb)
|
||||||
|
1
block.h
1
block.h
@ -47,6 +47,7 @@ typedef struct QEMUSnapshotInfo {
|
|||||||
|
|
||||||
#ifndef QEMU_IMG
|
#ifndef QEMU_IMG
|
||||||
void bdrv_info(void);
|
void bdrv_info(void);
|
||||||
|
void bdrv_info_stats(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void bdrv_init(void);
|
void bdrv_init(void);
|
||||||
|
@ -114,6 +114,12 @@ struct BlockDriverState {
|
|||||||
|
|
||||||
void *sync_aiocb;
|
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
|
/* NOTE: the following infos are only hints for real hardware
|
||||||
drivers. They are not used by the block driver */
|
drivers. They are not used by the block driver */
|
||||||
int cyls, heads, secs, translation;
|
int cyls, heads, secs, translation;
|
||||||
|
@ -255,6 +255,11 @@ static void do_info_block(void)
|
|||||||
bdrv_info();
|
bdrv_info();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void do_info_blockstats(void)
|
||||||
|
{
|
||||||
|
bdrv_info_stats();
|
||||||
|
}
|
||||||
|
|
||||||
/* get the current CPU defined by the user */
|
/* get the current CPU defined by the user */
|
||||||
static int mon_set_cpu(int cpu_index)
|
static int mon_set_cpu(int cpu_index)
|
||||||
{
|
{
|
||||||
@ -1327,6 +1332,8 @@ static term_cmd_t info_cmds[] = {
|
|||||||
"", "show the network state" },
|
"", "show the network state" },
|
||||||
{ "block", "", do_info_block,
|
{ "block", "", do_info_block,
|
||||||
"", "show the block devices" },
|
"", "show the block devices" },
|
||||||
|
{ "blockstats", "", do_info_blockstats,
|
||||||
|
"", "show block device statistics" },
|
||||||
{ "registers", "", do_info_registers,
|
{ "registers", "", do_info_registers,
|
||||||
"", "show the cpu registers" },
|
"", "show the cpu registers" },
|
||||||
{ "cpus", "", do_info_cpus,
|
{ "cpus", "", do_info_cpus,
|
||||||
|
Loading…
Reference in New Issue
Block a user