This patchset adds QEMU support for querying fd-based KVM statistics. This allows the user to analyze the behavior of the VM without access to debugfs.
However, instead of adding an ad hoc command, the new QMP entry point can be extended in the future to more statistics provider than KVM (for example TCG, tap, or the block layer) and to more objects than the VM and vCPUS (for example network interfaces or block devices). Because the statistics exposed by KVM are not known at compile time, the kernel interface also comes with an introspectable schema. This schema is exposed by the query-stats-schemas QMP command. Patches 1 and 2 add the basic support, respectively the QMP command and the KVM producer. Patches 3 to 6 add a basic HMP implementation. The first of the two adds a basic filtering mechanism to the QMP command, which is then used by HMP (which only shows vCPU statistics for the currently selected guest CPU; this is consistent with other HMP commands and does not flood the user with an overwhelming amount of output). The remaining patches add more filtering, respectively by provider and by the name of a statistic. The v4->v5 delta mostly restructures the implementation to hve sensible results if the same providers is specified many times in the same query-stats invocation. v4->v5: - all: wrap long lines - patch 1: fix indentation of "Note" - patch 2: use QAPI_LIST_PREPEND and error_setg_errno - patches 4/5: new - patch 6: reorganize printing of units to use prefixes instead of long names ("ns", not "nanoseconds") - patches 1/3/7/9: filtering reimplemented to improve behavior if the same provider occurs many times in the same query-stats invocation. Before, all filters were evaluated first, and the callback was then run if there was a match. Now, each filter is evaluated separately. - patch 9: do not drop names from prototypes Mark Kanda (3): qmp: Support for querying stats kvm: Support for querying fd-based stats hmp: add basic "info stats" implementation Paolo Bonzini (7): qmp: add filtering of statistics by target vCPU cutils: fix case for "kilo" and "kibi" cutils: add functions for IEC and SI prefixes qmp: add filtering of statistics by provider hmp: add filtering of statistics by provider qmp: add filtering of statistics by name hmp: add filtering of statistics by name accel/kvm/kvm-all.c | 408 +++++++++++++++++++++++++++++++++++++++ hmp-commands-info.hx | 14 ++ include/monitor/hmp.h | 1 + include/monitor/stats.h | 45 +++++ include/qemu/cutils.h | 18 ++ monitor/hmp-cmds.c | 232 ++++++++++++++++++++++ monitor/qmp-cmds.c | 155 +++++++++++++++ qapi/meson.build | 1 + qapi/qapi-schema.json | 1 + qapi/stats.json | 249 ++++++++++++++++++++++++ tests/unit/test-cutils.c | 52 +++++ util/cutils.c | 36 +++- 12 files changed, 1202 insertions(+), 10 deletions(-) create mode 100644 include/monitor/stats.h create mode 100644 qapi/stats.json -- 2.36.1