[PATCH v4 0/3] qemu: add an API for "query-stats" QMP command

Amneesh Singh natto at weirdnatto.in
Thu Aug 18 03:17:17 UTC 2022

QEMU is gaining introspectable statistics which can be queried via the
"query-stats" QMP command. This patchset aims to add an API for the

The returned JSON for "query-stats" is an array of objects containing
their own respective array of statistics.

Patch 1 adds the API for "query-stats" and a function to deserialize the
returned objects into respective hashtables.

Patch 2 adds the "query-stats" to QEMU capabilities.

Patch 3 uses the API to query the halt poll success time and the halt
poll failure time.

v3 -> v4
Some changes based on past reviews by Mr. Martin and me

  - clean up qemuMonitorQueryStatsProviderNew.
  - make relevant checks/changes to support the change above.
  - do NOT return the GPtrArray, instead just return the json object.
    (this helps retain the non-stat info returned which will be
    useful in the future patches).
  - add a function which deserializes value associated with the "stats"
    key in the JSON object (one of the objects returned in the JSON
    array above) into a GHashTable.

  - add a flag to for the capability in tests.

  - use a helper function to make things cleaner.

v2 -> v3
Sorry for the late patchset, I was under the impression I had sent it on
Monday but apparently, I did not.

  - use a single enum for all the statistics.
  - use QEMU_MONITOR_QUERY_STATS_NAME_LAST as the sentinel value for the
    provider constructor.
  - relevant changes to enum values.

  - fix comment spacing

  - better checks

v1 -> v2
I have been tinkering with the v1 patchset and have rewrote the v2
patches a couple of times. I believe the current patchset is still not
perfect and would appreciate some reviews.

I have another patch or two written but they do not make any significant
changes to the current patchset.

  - use virBitmap instead of an array of strings for statistics.
  - add enums for the stat names and add
    qemuMonitorQueryStatsNameTypeToString to switch between the
    "ToString" functions based on the target type.
  - change qemuMonitorQueryStatsProviderNew to a variadic function that
    takes stat enum values with the sentinel value being -1.

  - No changes

  - Add relevant monitor related checks to check if the domain is
  - Acquire and release qemuMonitorObj lock before and after calling
    qemuMonitorQueryStats respectively.
  - Add the check for privileged access.

Relevant QEMU patches can be found here:

This patchset is part of the 2022 GSOC contributor project.

Amneesh Singh (3):
  qemu_monitor: add qemuMonitorQueryStats
  qemu_capabilities: add "query-stats" QMP command to the QEMU
  qemu_driver: use qemuMonitorQueryStats to extract halt poll time

 src/qemu/qemu_capabilities.c                  |   4 +
 src/qemu/qemu_capabilities.h                  |   3 +
 src/qemu/qemu_driver.c                        |  81 +++++++++++-
 src/qemu/qemu_monitor.c                       | 117 ++++++++++++++++++
 src/qemu/qemu_monitor.h                       |  48 +++++++
 src/qemu/qemu_monitor_json.c                  |  91 ++++++++++++++
 src/qemu/qemu_monitor_json.h                  |   6 +
 .../caps_7.1.0.x86_64.xml                     |   1 +
 8 files changed, 345 insertions(+), 6 deletions(-)


More information about the libvir-list mailing list