[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 05/17] virsh: Add event completer to --enable/--disable args of perf command



Signed-off-by: Lin Ma <lma suse de>
---
 tools/virsh-completer-domain.c | 49 ++++++++++++++++++++++++++++++++++
 tools/virsh-completer-domain.h |  8 ++++++
 tools/virsh-domain.c           |  2 ++
 3 files changed, 59 insertions(+)

diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c
index 4c1261b06b..122a9d5f66 100644
--- a/tools/virsh-completer-domain.c
+++ b/tools/virsh-completer-domain.c
@@ -29,6 +29,7 @@
 #include "virsh.h"
 #include "virstring.h"
 #include "virxml.h"
+#include "conf/domain_conf.h"
 
 char **
 virshDomainNameCompleter(vshControl *ctl,
@@ -338,3 +339,51 @@ virshDomainHostnameSourceCompleter(vshControl *ctl G_GNUC_UNUSED,
 
     return ret;
 }
+
+
+char **
+virshDomainPerfEnableCompleter(vshControl *ctl,
+                              const vshCmd *cmd,
+                              unsigned int flags)
+{
+    size_t i = 0;
+    VIR_AUTOSTRINGLIST events = NULL;
+    const char *event = NULL;
+
+    virCheckFlags(0, NULL);
+
+    if (VIR_ALLOC_N(events, VIR_PERF_EVENT_LAST + 1) < 0)
+        return NULL;
+
+    for (i = 0; i < VIR_PERF_EVENT_LAST; i++)
+        events[i] = g_strdup(virPerfEventTypeToString(i));
+
+    if (vshCommandOptStringQuiet(ctl, cmd, "enable", &event) < 0)
+        return NULL;
+
+    return virshCommaStringListComplete(event, (const char **)events);
+}
+
+
+char **
+virshDomainPerfDisableCompleter(vshControl *ctl,
+                                const vshCmd *cmd,
+                                unsigned int flags)
+{
+    size_t i = 0;
+    VIR_AUTOSTRINGLIST events = NULL;
+    const char *event = NULL;
+
+    virCheckFlags(0, NULL);
+
+    if (VIR_ALLOC_N(events, VIR_PERF_EVENT_LAST + 1) < 0)
+        return NULL;
+
+    for (i = 0; i < VIR_PERF_EVENT_LAST; i++)
+        events[i] = g_strdup(virPerfEventTypeToString(i));
+
+    if (vshCommandOptStringQuiet(ctl, cmd, "disable", &event) < 0)
+        return NULL;
+
+    return virshCommaStringListComplete(event, (const char **)events);
+}
diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h
index b00b05e3bd..e3375c3c65 100644
--- a/tools/virsh-completer-domain.h
+++ b/tools/virsh-completer-domain.h
@@ -62,3 +62,11 @@ virshDomainInterfaceAddrSourceCompleter(vshControl *ctl,
 char ** virshDomainHostnameSourceCompleter(vshControl *ctl,
                                            const vshCmd *cmd,
                                            unsigned int flags);
+
+char ** virshDomainPerfEnableCompleter(vshControl *ctl,
+                                       const vshCmd *cmd,
+                                       unsigned int flags);
+
+char ** virshDomainPerfDisableCompleter(vshControl *ctl,
+                                        const vshCmd *cmd,
+                                        unsigned int flags);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 68600d728a..1ba536466a 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -9333,10 +9333,12 @@ static const vshCmdOptDef opts_perf[] = {
     VIRSH_COMMON_OPT_DOMAIN_FULL(0),
     {.name = "enable",
      .type = VSH_OT_STRING,
+     .completer = virshDomainPerfEnableCompleter,
      .help = N_("perf events which will be enabled")
     },
     {.name = "disable",
      .type = VSH_OT_STRING,
+     .completer = virshDomainPerfDisableCompleter,
      .help = N_("perf events which will be disabled")
     },
     VIRSH_COMMON_OPT_DOMAIN_CONFIG,
-- 
2.26.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]