Received: from eggs.gnu.org ([2001:4830:134:3::10]:57469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPGah-0006AL-Rs for qemu-devel@nongnu.org; Mon, 18 Jul 2016 18:00:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bPGad-0005jk-Jd for qemu-devel@nongnu.org; Mon, 18 Jul 2016 18:00:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55006) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bPGad-0005jf-B7 for qemu-devel@nongnu.org; Mon, 18 Jul 2016 18:00:39 -0400 From: Stefan Hajnoczi Date: Mon, 18 Jul 2016 23:00:18 +0100 Message-Id: <1468879219-24500-9-git-send-email-stefanha@redhat.com> In-Reply-To: <1468879219-24500-1-git-send-email-stefanha@redhat.com> References: <1468879219-24500-1-git-send-email-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 8/9] trace: Allow event name pattern in "info trace-events" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , =?UTF-8?q?Llu=C3=ADs=20Vilanova?= , Stefan Hajnoczi From: Llu=C3=ADs Vilanova Homogenizes the command capabilities with QMP. Signed-off-by: Llu=C3=ADs Vilanova Reviewed-by: Eric Blake Reviewed-by: Markus Armbruster Signed-off-by: Stefan Hajnoczi --- hmp-commands-info.hx | 8 +++++--- hmp.h | 1 + monitor.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 7da9e6c..3d07ca6 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -646,10 +646,12 @@ ETEXI =20 { .name =3D "trace-events", - .args_type =3D "", - .params =3D "", - .help =3D "show available trace-events & their state", + .args_type =3D "name:s?", + .params =3D "[name]", + .help =3D "show available trace-events & their state " + "(name: event name pattern)", .mhandler.cmd =3D hmp_info_trace_events, + .command_completion =3D info_trace_events_completion, }, =20 STEXI diff --git a/hmp.h b/hmp.h index f5d9749..0876ec0 100644 --- a/hmp.h +++ b/hmp.h @@ -115,6 +115,7 @@ void set_link_completion(ReadLineState *rs, int nb_ar= gs, const char *str); void netdev_add_completion(ReadLineState *rs, int nb_args, const char *s= tr); void netdev_del_completion(ReadLineState *rs, int nb_args, const char *s= tr); void ringbuf_write_completion(ReadLineState *rs, int nb_args, const char= *str); +void info_trace_events_completion(ReadLineState *rs, int nb_args, const = char *str); void trace_event_completion(ReadLineState *rs, int nb_args, const char *= str); void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str); diff --git a/monitor.c b/monitor.c index d0ff246..ab31725 100644 --- a/monitor.c +++ b/monitor.c @@ -1065,8 +1065,20 @@ static void hmp_info_cpustats(Monitor *mon, const = QDict *qdict) =20 static void hmp_info_trace_events(Monitor *mon, const QDict *qdict) { - TraceEventInfoList *events =3D qmp_trace_event_get_state("*", NULL); + const char *name =3D qdict_get_try_str(qdict, "name"); + TraceEventInfoList *events; TraceEventInfoList *elem; + Error *local_err =3D NULL; + + if (name =3D=3D NULL) { + name =3D "*"; + } + + events =3D qmp_trace_event_get_state(name, &local_err); + if (local_err) { + error_report_err(local_err); + return; + } =20 for (elem =3D events; elem !=3D NULL; elem =3D elem->next) { monitor_printf(mon, "%s : state %u\n", @@ -3296,6 +3308,23 @@ void netdev_del_completion(ReadLineState *rs, int = nb_args, const char *str) } } =20 +void info_trace_events_completion(ReadLineState *rs, int nb_args, const = char *str) +{ + size_t len; + + len =3D strlen(str); + readline_set_completion_index(rs, len); + if (nb_args =3D=3D 2) { + TraceEventID id; + for (id =3D 0; id < trace_event_count(); id++) { + const char *event_name =3D trace_event_get_name(trace_event_= id(id)); + if (!strncmp(str, event_name, len)) { + readline_add_completion(rs, event_name); + } + } + } +} + void trace_event_completion(ReadLineState *rs, int nb_args, const char *= str) { size_t len; --=20 2.7.4