trace-events: Add hmp completion
authorDr. David Alan Gilbert <dgilbert@redhat.com>
Fri, 14 Aug 2015 10:27:43 +0000 (11:27 +0100)
committerStefan Hajnoczi <stefanha@redhat.com>
Thu, 3 Sep 2015 14:46:10 +0000 (15:46 +0100)
Add completion for the trace event names in the hmp trace-event
command.

Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Message-id: 1439548063-18410-1-git-send-email-dgilbert@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
hmp-commands.hx
hmp.h
monitor.c

index d3b7932ff6331fa95ba8127c98bf527773d6cc7e..94d2c391a93ad1670bb62b00f1091b326d0327af 100644 (file)
@@ -271,6 +271,7 @@ ETEXI
         .params     = "name on|off",
         .help       = "changes status of a specific trace event",
         .mhandler.cmd = hmp_trace_event,
+        .command_completion = trace_event_completion,
     },
 
 STEXI
diff --git a/hmp.h b/hmp.h
index 0cf4f2a3d1a3166d32b245fe11f993013ef3904a..b8f5d336427868cef3d8c9c595e7ab1269ff17ae 100644 (file)
--- a/hmp.h
+++ b/hmp.h
@@ -113,6 +113,7 @@ void set_link_completion(ReadLineState *rs, int nb_args, const char *str);
 void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void ringbuf_write_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);
 void migrate_set_capability_completion(ReadLineState *rs, int nb_args,
index fc32f12eef1b727b380ca02579511cb074063b53..b4324478685506c50cf293225018d05a092d7536 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -4429,6 +4429,26 @@ void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str)
     }
 }
 
+void trace_event_completion(ReadLineState *rs, int nb_args, const char *str)
+{
+    size_t len;
+
+    len = strlen(str);
+    readline_set_completion_index(rs, len);
+    if (nb_args == 2) {
+        TraceEventID id;
+        for (id = 0; id < trace_event_count(); id++) {
+            const char *event_name = trace_event_get_name(trace_event_id(id));
+            if (!strncmp(str, event_name, len)) {
+                readline_add_completion(rs, event_name);
+            }
+        }
+    } else if (nb_args == 3) {
+        add_completion_option(rs, str, "on");
+        add_completion_option(rs, str, "off");
+    }
+}
+
 void watchdog_action_completion(ReadLineState *rs, int nb_args, const char *str)
 {
     int i;