We are going to add a possibility to trace some qmp commands by user selection. For now add a new field to QmpCommand structure and two functions to manipulate with it.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@virtuozzo.com> --- include/qapi/qmp/dispatch.h | 14 ++++++++++++++ qapi/qmp-registry.c | 27 +++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/qapi/qmp/dispatch.h b/include/qapi/qmp/dispatch.h index 075203dc67..5d0df2f984 100644 --- a/include/qapi/qmp/dispatch.h +++ b/include/qapi/qmp/dispatch.h @@ -38,6 +38,7 @@ typedef struct QmpCommand QTAILQ_ENTRY(QmpCommand) node; bool enabled; const char *disable_reason; + bool tracing; } QmpCommand; typedef QTAILQ_HEAD(QmpCommandList, QmpCommand) QmpCommandList; @@ -64,4 +65,17 @@ typedef void (*qmp_cmd_callback_fn)(const QmpCommand *cmd, void *opaque); void qmp_for_each_command(const QmpCommandList *cmds, qmp_cmd_callback_fn fn, void *opaque); +/* + * Enable or disable tracing for commands matching the pattern. + * Pattern matching is handled by g_pattern_match_simple(). + */ +void qmp_commands_set_tracing(QmpCommandList *cmds, const char *pattern, + bool enable); + +/* + * Return true if tracing is enabled for any command matching the pattern. + * If pattern is NULL, return true if tracing is enabled for any command. + */ +bool qmp_commands_is_tracing_enabled(QmpCommandList *cmds, const char *pattern); + #endif diff --git a/qapi/qmp-registry.c b/qapi/qmp-registry.c index f78c064aae..56e761857b 100644 --- a/qapi/qmp-registry.c +++ b/qapi/qmp-registry.c @@ -67,6 +67,33 @@ void qmp_enable_command(QmpCommandList *cmds, const char *name) qmp_toggle_command(cmds, name, true, NULL); } +void qmp_commands_set_tracing(QmpCommandList *cmds, const char *pattern, + bool enable) +{ + QmpCommand *cmd; + + QTAILQ_FOREACH(cmd, cmds, node) { + if (g_pattern_match_simple(pattern, cmd->name)) { + cmd->tracing = true; + } + } +} + +bool qmp_commands_is_tracing_enabled(QmpCommandList *cmds, const char *pattern) +{ + QmpCommand *cmd; + + QTAILQ_FOREACH(cmd, cmds, node) { + if (cmd->tracing && + (!pattern || g_pattern_match_simple(pattern, cmd->name))) + { + return true; + } + } + + return false; +} + bool qmp_command_is_enabled(const QmpCommand *cmd) { return cmd->enabled; -- 2.29.2