From: Peter Krempa <[email protected]> Add QMP monitor code for setting up latency histogram configuration.
Signed-off-by: Peter Krempa <[email protected]> --- src/qemu/qemu_monitor.c | 21 +++++++++++++ src/qemu/qemu_monitor.h | 9 ++++++ src/qemu/qemu_monitor_json.c | 60 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 9 ++++++ tests/qemumonitorjsontest.c | 9 ++++++ 5 files changed, 108 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index cdd08004fb..3d7477c01c 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4612,3 +4612,24 @@ qemuMonitorBlockdevSetActive(qemuMonitor *mon, return qemuMonitorJSONBlockdevSetActive(mon, nodename, active); } + + +int +qemuMonitorBlockLatencyHistogramSet(qemuMonitor *mon, + const char *id, + unsigned int *boundaries, + unsigned int *boundaries_read, + unsigned int *boundaries_write, + unsigned int *boundaries_zone, + unsigned int *boundaries_flush) +{ + QEMU_CHECK_MONITOR(mon); + VIR_DEBUG("id='%s'", id); + + return qemuMonitorJSONBlockLatencyHistogramSet(mon, id, + boundaries, + boundaries_read, + boundaries_write, + boundaries_zone, + boundaries_flush); +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index fb4fe2bc76..128b0fa2ce 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1984,3 +1984,12 @@ int qemuMonitorBlockdevSetActive(qemuMonitor *mon, const char *nodename, bool active); + +int +qemuMonitorBlockLatencyHistogramSet(qemuMonitor *mon, + const char *id, + unsigned int *boundaries, + unsigned int *boundaries_read, + unsigned int *boundaries_write, + unsigned int *boundaries_zone, + unsigned int *boundaries_flush); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 5736546ec2..8c930ca1bb 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -9113,3 +9113,63 @@ qemuMonitorJSONBlockdevSetActive(qemuMonitor *mon, return qemuMonitorJSONCheckError(cmd, reply); } + + +static virJSONValue * +qemuMonitorJSONBlockLatencyHistogramBoundary(unsigned int *bound) +{ + g_autoptr(virJSONValue) ret = virJSONValueNewArray(); + + if (!bound) + return NULL; + + for (; *bound > 0; bound++) { + g_autoptr(virJSONValue) val = virJSONValueNewNumberUint(*bound); + + /* the only error is if the first argument is not an array */ + ignore_value(virJSONValueArrayAppend(ret, &val)); + } + + return g_steal_pointer(&ret); +} + + +int +qemuMonitorJSONBlockLatencyHistogramSet(qemuMonitor *mon, + const char *id, + unsigned int *boundaries, + unsigned int *boundaries_read, + unsigned int *boundaries_write, + unsigned int *boundaries_zone, + unsigned int *boundaries_flush) +{ + g_autoptr(virJSONValue) cmd = NULL; + g_autoptr(virJSONValue) reply = NULL; + + g_autoptr(virJSONValue) bound = NULL; + g_autoptr(virJSONValue) bound_read = NULL; + g_autoptr(virJSONValue) bound_write = NULL; + g_autoptr(virJSONValue) bound_zone = NULL; + g_autoptr(virJSONValue) bound_flush = NULL; + + bound = qemuMonitorJSONBlockLatencyHistogramBoundary(boundaries); + bound_read = qemuMonitorJSONBlockLatencyHistogramBoundary(boundaries_read); + bound_write = qemuMonitorJSONBlockLatencyHistogramBoundary(boundaries_write); + bound_zone = qemuMonitorJSONBlockLatencyHistogramBoundary(boundaries_zone); + bound_flush = qemuMonitorJSONBlockLatencyHistogramBoundary(boundaries_flush); + + if (!(cmd = qemuMonitorJSONMakeCommand("block-latency-histogram-set", + "s:id", id, + "A:boundaries", &bound, + "A:boundaries-read", &bound_read, + "A:boundaries-write", &bound_write, + "A:boundaries-zap", &bound_zone, + "A:boundaries-flush", &bound_flush, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + return -1; + + return qemuMonitorJSONCheckError(cmd, reply); +} diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index db9160eb68..b418f70048 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -815,3 +815,12 @@ int qemuMonitorJSONBlockdevSetActive(qemuMonitor *mon, const char *nodename, bool active); + +int +qemuMonitorJSONBlockLatencyHistogramSet(qemuMonitor *mon, + const char *id, + unsigned int *boundaries, + unsigned int *boundaries_read, + unsigned int *boundaries_write, + unsigned int *boundaries_zone, + unsigned int *boundaries_flush); diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index bfe81739a7..1c1aaaa586 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1130,6 +1130,14 @@ GEN_TEST_FUNC(qemuMonitorJSONSetAction, GEN_TEST_FUNC(qemuMonitorJSONSetLaunchSecurityState, "sev_secret_header", "sev_secret", 0, true) +unsigned int testHistogramBoundaries[] = {10, 30, 50, 0}; +GEN_TEST_FUNC(qemuMonitorJSONBlockLatencyHistogramSet, "devid", + testHistogramBoundaries, + testHistogramBoundaries, + testHistogramBoundaries, + testHistogramBoundaries, + testHistogramBoundaries) + static int testQemuMonitorJSONqemuMonitorJSONNBDServerStart(const void *opaque) { @@ -2958,6 +2966,7 @@ mymain(void) DO_TEST_GEN(qemuMonitorJSONBlockJobCancel); DO_TEST_GEN(qemuMonitorJSONSetAction); DO_TEST_GEN(qemuMonitorJSONSetLaunchSecurityState); + DO_TEST_GEN(qemuMonitorJSONBlockLatencyHistogramSet); DO_TEST(qemuMonitorJSONGetBalloonInfo); DO_TEST(qemuMonitorJSONGetBlockInfo); DO_TEST(qemuMonitorJSONGetAllBlockStatsInfo); -- 2.52.0
