block: Add idle_time_ns to BlockDeviceStats
This patch adds the new field 'idle_time_ns' to the BlockDeviceStats structure, indicating the time that has passed since the previous I/O operation. It also adds the block_acct_idle_time_ns() call, to ensure that all references to the clock type used for accounting are in the same place. This will later allow us to use a different clock for iotests. Signed-off-by: Alberto Garcia <berto@igalia.com> Message-id: 7d8cfcf931453e1a2443e6626e8c1edc347c7c8a.1446044837.git.berto@igalia.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
bd797fc15b
commit
cb38fffbc9
|
@ -40,12 +40,15 @@ void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie,
|
||||||
|
|
||||||
void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie)
|
void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie)
|
||||||
{
|
{
|
||||||
|
int64_t time_ns = qemu_clock_get_ns(clock_type);
|
||||||
|
int64_t latency_ns = time_ns - cookie->start_time_ns;
|
||||||
|
|
||||||
assert(cookie->type < BLOCK_MAX_IOTYPE);
|
assert(cookie->type < BLOCK_MAX_IOTYPE);
|
||||||
|
|
||||||
stats->nr_bytes[cookie->type] += cookie->bytes;
|
stats->nr_bytes[cookie->type] += cookie->bytes;
|
||||||
stats->nr_ops[cookie->type]++;
|
stats->nr_ops[cookie->type]++;
|
||||||
stats->total_time_ns[cookie->type] +=
|
stats->total_time_ns[cookie->type] += latency_ns;
|
||||||
qemu_clock_get_ns(clock_type) - cookie->start_time_ns;
|
stats->last_access_time_ns = time_ns;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,3 +58,8 @@ void block_acct_merge_done(BlockAcctStats *stats, enum BlockAcctType type,
|
||||||
assert(type < BLOCK_MAX_IOTYPE);
|
assert(type < BLOCK_MAX_IOTYPE);
|
||||||
stats->merged[type] += num_requests;
|
stats->merged[type] += num_requests;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t block_acct_idle_time_ns(BlockAcctStats *stats)
|
||||||
|
{
|
||||||
|
return qemu_clock_get_ns(clock_type) - stats->last_access_time_ns;
|
||||||
|
}
|
||||||
|
|
|
@ -357,6 +357,11 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs,
|
||||||
s->stats->wr_total_time_ns = stats->total_time_ns[BLOCK_ACCT_WRITE];
|
s->stats->wr_total_time_ns = stats->total_time_ns[BLOCK_ACCT_WRITE];
|
||||||
s->stats->rd_total_time_ns = stats->total_time_ns[BLOCK_ACCT_READ];
|
s->stats->rd_total_time_ns = stats->total_time_ns[BLOCK_ACCT_READ];
|
||||||
s->stats->flush_total_time_ns = stats->total_time_ns[BLOCK_ACCT_FLUSH];
|
s->stats->flush_total_time_ns = stats->total_time_ns[BLOCK_ACCT_FLUSH];
|
||||||
|
|
||||||
|
s->stats->has_idle_time_ns = stats->last_access_time_ns > 0;
|
||||||
|
if (s->stats->has_idle_time_ns) {
|
||||||
|
s->stats->idle_time_ns = block_acct_idle_time_ns(stats);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s->stats->wr_highest_offset = bs->wr_highest_offset;
|
s->stats->wr_highest_offset = bs->wr_highest_offset;
|
||||||
|
|
4
hmp.c
4
hmp.c
|
@ -522,6 +522,7 @@ void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
|
||||||
" flush_total_time_ns=%" PRId64
|
" flush_total_time_ns=%" PRId64
|
||||||
" rd_merged=%" PRId64
|
" rd_merged=%" PRId64
|
||||||
" wr_merged=%" PRId64
|
" wr_merged=%" PRId64
|
||||||
|
" idle_time_ns=%" PRId64
|
||||||
"\n",
|
"\n",
|
||||||
stats->value->stats->rd_bytes,
|
stats->value->stats->rd_bytes,
|
||||||
stats->value->stats->wr_bytes,
|
stats->value->stats->wr_bytes,
|
||||||
|
@ -532,7 +533,8 @@ void hmp_info_blockstats(Monitor *mon, const QDict *qdict)
|
||||||
stats->value->stats->rd_total_time_ns,
|
stats->value->stats->rd_total_time_ns,
|
||||||
stats->value->stats->flush_total_time_ns,
|
stats->value->stats->flush_total_time_ns,
|
||||||
stats->value->stats->rd_merged,
|
stats->value->stats->rd_merged,
|
||||||
stats->value->stats->wr_merged);
|
stats->value->stats->wr_merged,
|
||||||
|
stats->value->stats->idle_time_ns);
|
||||||
}
|
}
|
||||||
|
|
||||||
qapi_free_BlockStatsList(stats_list);
|
qapi_free_BlockStatsList(stats_list);
|
||||||
|
|
|
@ -40,6 +40,7 @@ typedef struct BlockAcctStats {
|
||||||
uint64_t nr_ops[BLOCK_MAX_IOTYPE];
|
uint64_t nr_ops[BLOCK_MAX_IOTYPE];
|
||||||
uint64_t total_time_ns[BLOCK_MAX_IOTYPE];
|
uint64_t total_time_ns[BLOCK_MAX_IOTYPE];
|
||||||
uint64_t merged[BLOCK_MAX_IOTYPE];
|
uint64_t merged[BLOCK_MAX_IOTYPE];
|
||||||
|
int64_t last_access_time_ns;
|
||||||
} BlockAcctStats;
|
} BlockAcctStats;
|
||||||
|
|
||||||
typedef struct BlockAcctCookie {
|
typedef struct BlockAcctCookie {
|
||||||
|
@ -53,5 +54,6 @@ void block_acct_start(BlockAcctStats *stats, BlockAcctCookie *cookie,
|
||||||
void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie);
|
void block_acct_done(BlockAcctStats *stats, BlockAcctCookie *cookie);
|
||||||
void block_acct_merge_done(BlockAcctStats *stats, enum BlockAcctType type,
|
void block_acct_merge_done(BlockAcctStats *stats, enum BlockAcctType type,
|
||||||
int num_requests);
|
int num_requests);
|
||||||
|
int64_t block_acct_idle_time_ns(BlockAcctStats *stats);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -448,6 +448,10 @@
|
||||||
# @wr_merged: Number of write requests that have been merged into another
|
# @wr_merged: Number of write requests that have been merged into another
|
||||||
# request (Since 2.3).
|
# request (Since 2.3).
|
||||||
#
|
#
|
||||||
|
# @idle_time_ns: #optional Time since the last I/O operation, in
|
||||||
|
# nanoseconds. If the field is absent it means that
|
||||||
|
# there haven't been any operations yet (Since 2.5).
|
||||||
|
#
|
||||||
# Since: 0.14.0
|
# Since: 0.14.0
|
||||||
##
|
##
|
||||||
{ 'struct': 'BlockDeviceStats',
|
{ 'struct': 'BlockDeviceStats',
|
||||||
|
@ -455,7 +459,7 @@
|
||||||
'wr_operations': 'int', 'flush_operations': 'int',
|
'wr_operations': 'int', 'flush_operations': 'int',
|
||||||
'flush_total_time_ns': 'int', 'wr_total_time_ns': 'int',
|
'flush_total_time_ns': 'int', 'wr_total_time_ns': 'int',
|
||||||
'rd_total_time_ns': 'int', 'wr_highest_offset': 'int',
|
'rd_total_time_ns': 'int', 'wr_highest_offset': 'int',
|
||||||
'rd_merged': 'int', 'wr_merged': 'int' } }
|
'rd_merged': 'int', 'wr_merged': 'int', '*idle_time_ns': 'int' } }
|
||||||
|
|
||||||
##
|
##
|
||||||
# @BlockStats:
|
# @BlockStats:
|
||||||
|
|
|
@ -2583,6 +2583,10 @@ Each json-object contain the following:
|
||||||
another request (json-int)
|
another request (json-int)
|
||||||
- "wr_merged": number of write requests that have been merged into
|
- "wr_merged": number of write requests that have been merged into
|
||||||
another request (json-int)
|
another request (json-int)
|
||||||
|
- "idle_time_ns": time since the last I/O operation, in
|
||||||
|
nanoseconds. If the field is absent it means
|
||||||
|
that there haven't been any operations yet
|
||||||
|
(json-int, optional)
|
||||||
- "parent": Contains recursively the statistics of the underlying
|
- "parent": Contains recursively the statistics of the underlying
|
||||||
protocol (e.g. the host file for a qcow2 image). If there is
|
protocol (e.g. the host file for a qcow2 image). If there is
|
||||||
no underlying protocol, this field is omitted
|
no underlying protocol, this field is omitted
|
||||||
|
@ -2607,7 +2611,8 @@ Example:
|
||||||
"flush_total_times_ns":49653
|
"flush_total_times_ns":49653
|
||||||
"flush_operations":61,
|
"flush_operations":61,
|
||||||
"rd_merged":0,
|
"rd_merged":0,
|
||||||
"wr_merged":0
|
"wr_merged":0,
|
||||||
|
"idle_time_ns":2953431879
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"stats":{
|
"stats":{
|
||||||
|
@ -2621,7 +2626,8 @@ Example:
|
||||||
"rd_total_times_ns":3465673657
|
"rd_total_times_ns":3465673657
|
||||||
"flush_total_times_ns":49653,
|
"flush_total_times_ns":49653,
|
||||||
"rd_merged":0,
|
"rd_merged":0,
|
||||||
"wr_merged":0
|
"wr_merged":0,
|
||||||
|
"idle_time_ns":2953431879
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue