summaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorAlberto Garcia <berto@igalia.com>2015-10-28 17:33:06 +0200
committerKevin Wolf <kwolf@redhat.com>2015-11-12 16:22:46 +0100
commit96e4dedaff9922f87e4ec351d51d3f093198382a (patch)
tree4f13bd41dbde11ddedeb6ce30d0ae0ca11e8ea6e /util
parent979e9b03fc8c85d3b78a14410c64cbb16d348095 (diff)
downloadhqemu-96e4dedaff9922f87e4ec351d51d3f093198382a.zip
hqemu-96e4dedaff9922f87e4ec351d51d3f093198382a.tar.gz
block: Add average I/O queue depth to BlockDeviceTimedStats
This patch adds two new fields to BlockDeviceTimedStats that track the average number of pending read and write requests for a block device. The values are calculated for the period of time defined for that interval. Signed-off-by: Alberto Garcia <berto@igalia.com> Message-id: fd31fef53e2714f2f30d59ed58ca2f67ec9ab926.1446044837.git.berto@igalia.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'util')
-rw-r--r--util/timed-average.c31
1 files changed, 26 insertions, 5 deletions
diff --git a/util/timed-average.c b/util/timed-average.c
index 98a1170..a2dfb48 100644
--- a/util/timed-average.c
+++ b/util/timed-average.c
@@ -120,8 +120,10 @@ void timed_average_init(TimedAverage *ta, QEMUClockType clock_type,
* expiration time if that's the case.
*
* @ta: the TimedAverage structure
+ * @elapsed: if non-NULL, the elapsed time (in ns) within the current
+ * window will be stored here
*/
-static void check_expirations(TimedAverage *ta)
+static void check_expirations(TimedAverage *ta, uint64_t *elapsed)
{
int64_t now = qemu_clock_get_ns(ta->clock_type);
int i;
@@ -143,6 +145,12 @@ static void check_expirations(TimedAverage *ta)
} else {
ta->current = 1;
}
+
+ /* Calculate the elapsed time within the current window */
+ if (elapsed) {
+ int64_t remaining = ta->windows[ta->current].expiration - now;
+ *elapsed = ta->period - remaining;
+ }
}
/* Account a value
@@ -153,7 +161,7 @@ static void check_expirations(TimedAverage *ta)
void timed_average_account(TimedAverage *ta, uint64_t value)
{
int i;
- check_expirations(ta);
+ check_expirations(ta, NULL);
/* Do the accounting in both windows at the same time */
for (i = 0; i < 2; i++) {
@@ -180,7 +188,7 @@ void timed_average_account(TimedAverage *ta, uint64_t value)
uint64_t timed_average_min(TimedAverage *ta)
{
TimedAverageWindow *w;
- check_expirations(ta);
+ check_expirations(ta, NULL);
w = current_window(ta);
return w->min < UINT64_MAX ? w->min : 0;
}
@@ -193,7 +201,7 @@ uint64_t timed_average_min(TimedAverage *ta)
uint64_t timed_average_avg(TimedAverage *ta)
{
TimedAverageWindow *w;
- check_expirations(ta);
+ check_expirations(ta, NULL);
w = current_window(ta);
return w->count > 0 ? w->sum / w->count : 0;
}
@@ -205,6 +213,19 @@ uint64_t timed_average_avg(TimedAverage *ta)
*/
uint64_t timed_average_max(TimedAverage *ta)
{
- check_expirations(ta);
+ check_expirations(ta, NULL);
return current_window(ta)->max;
}
+
+/* Get the sum of all accounted values
+ * @ta: the TimedAverage structure
+ * @elapsed: if non-NULL, the elapsed time (in ns) will be stored here
+ * @ret: the sum of all accounted values
+ */
+uint64_t timed_average_sum(TimedAverage *ta, uint64_t *elapsed)
+{
+ TimedAverageWindow *w;
+ check_expirations(ta, elapsed);
+ w = current_window(ta);
+ return w->sum;
+}
OpenPOWER on IntegriCloud