Re: [libvirt] [PATCH v2 7/8] virsh: implement new command to support perf

2015-12-13 Thread Ren, Qiaowei


> -Original Message-
> From: Daniel P. Berrange [mailto:berra...@redhat.com]
> Sent: Tuesday, December 8, 2015 7:07 PM
> To: Ren, Qiaowei
> Cc: libvir-list@redhat.com; Jiri Denemark
> Subject: Re: [PATCH v2 7/8] virsh: implement new command to support perf
> 
> On Mon, Dec 07, 2015 at 03:53:58PM +0800, Qiaowei Ren wrote:
> > This patch add new perf command to enable/disable perf event for a
> > guest domain.
> >
> > Signed-off-by: Qiaowei Ren 
> > ---
> >  tools/virsh-domain.c | 125
> +++
> >  tools/virsh.pod  |  18 
> >  2 files changed, 143 insertions(+)
> >
> > diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index
> > b7e7606..a47ef9f 100644
> > --- a/tools/virsh-domain.c
> > +++ b/tools/virsh-domain.c
> > @@ -,6 +,125 @@ cmdMemtune(vshControl *ctl, const vshCmd
> *cmd)
> > }
> >
> >  /*
> > + * "perf" command
> > + */
> > +static const vshCmdInfo info_perf[] = {
> > +{.name = "help",
> > +.data = N_("Get or set perf event")
> > +},
> > +{.name = "desc",
> > +.data = N_("Get or set the current perf events for a guest"
> > +   " domain.\n"
> > +   "To get the perf events list use following command: 
> > \n\n"
> > +   "virsh # perf ")
> > +},
> > +{.name = NULL}
> > +};
> > +
> > +static const vshCmdOptDef opts_perf[] = {
> > +{.name = "domain",
> > + .type = VSH_OT_DATA,
> > + .flags = VSH_OFLAG_REQ,
> > + .help = N_("domain name, id or uuid")
> > +},
> > +{.name = "cmt",
> > + .type = VSH_OT_INT,
> > + .help = N_("CMT event, as integer (default 0, disable)")
> > +},
> 
> Imagine we add many more perf events - we don't want to be adding args to
> virsh for each one. Instead of --cmt, we should have '--event cmt'
> 
> 

Ok. I guess that this command will be the following style:

virsh perf  --enable  --disable <>

For instance: virsh perf guest01 --enable cmt

Daniel, do you think this is OK?

Thanks,
Qiaowei

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v2 7/8] virsh: implement new command to support perf

2015-12-09 Thread Daniel P. Berrange
On Wed, Dec 09, 2015 at 01:28:22PM +, Ren, Qiaowei wrote:
> 
> 
> > -Original Message-
> > From: Daniel P. Berrange [mailto:berra...@redhat.com]
> > Sent: Tuesday, December 8, 2015 7:07 PM
> > To: Ren, Qiaowei
> > Cc: libvir-list@redhat.com; Jiri Denemark
> > Subject: Re: [PATCH v2 7/8] virsh: implement new command to support perf
> > 
> > On Mon, Dec 07, 2015 at 03:53:58PM +0800, Qiaowei Ren wrote:
> > > This patch add new perf command to enable/disable perf event for a
> > > guest domain.
> > >
> > > Signed-off-by: Qiaowei Ren 
> > > ---
> > >  tools/virsh-domain.c | 125
> > +++
> > >  tools/virsh.pod  |  18 
> > >  2 files changed, 143 insertions(+)
> > >
> > > diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index
> > > b7e7606..a47ef9f 100644
> > > --- a/tools/virsh-domain.c
> > > +++ b/tools/virsh-domain.c
> > > @@ -,6 +,125 @@ cmdMemtune(vshControl *ctl, const vshCmd
> > *cmd)
> > > }
> > >
> > >  /*
> > > + * "perf" command
> > > + */
> > > +static const vshCmdInfo info_perf[] = {
> > > +{.name = "help",
> > > +.data = N_("Get or set perf event")
> > > +},
> > > +{.name = "desc",
> > > +.data = N_("Get or set the current perf events for a guest"
> > > +   " domain.\n"
> > > +   "To get the perf events list use following 
> > > command: \n\n"
> > > +   "virsh # perf ")
> > > +},
> > > +{.name = NULL}
> > > +};
> > > +
> > > +static const vshCmdOptDef opts_perf[] = {
> > > +{.name = "domain",
> > > + .type = VSH_OT_DATA,
> > > + .flags = VSH_OFLAG_REQ,
> > > + .help = N_("domain name, id or uuid")
> > > +},
> > > +{.name = "cmt",
> > > + .type = VSH_OT_INT,
> > > + .help = N_("CMT event, as integer (default 0, disable)")
> > > +},
> > 
> > Imagine we add many more perf events - we don't want to be adding args to
> > virsh for each one. Instead of --cmt, we should have '--event cmt'
> > 
> > 
> 
> Ok. I guess that this command will be the following style:
> 
> virsh perf  --enable  --disable <>
> 
> For instance: virsh perf guest01 --enable cmt
> 
> Daniel, do you think this is OK?

Yep, that's good

Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v2 7/8] virsh: implement new command to support perf

2015-12-08 Thread Daniel P. Berrange
On Mon, Dec 07, 2015 at 03:53:58PM +0800, Qiaowei Ren wrote:
> This patch add new perf command to enable/disable perf event
> for a guest domain.
> 
> Signed-off-by: Qiaowei Ren 
> ---
>  tools/virsh-domain.c | 125 
> +++
>  tools/virsh.pod  |  18 
>  2 files changed, 143 insertions(+)
> 
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index b7e7606..a47ef9f 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -,6 +,125 @@ cmdMemtune(vshControl *ctl, const vshCmd *cmd)
>  }
>  
>  /*
> + * "perf" command
> + */
> +static const vshCmdInfo info_perf[] = {
> +{.name = "help",
> +.data = N_("Get or set perf event")
> +},
> +{.name = "desc",
> +.data = N_("Get or set the current perf events for a guest"
> +   " domain.\n"
> +   "To get the perf events list use following command: 
> \n\n"
> +   "virsh # perf ")
> +},
> +{.name = NULL}
> +};
> +
> +static const vshCmdOptDef opts_perf[] = {
> +{.name = "domain",
> + .type = VSH_OT_DATA,
> + .flags = VSH_OFLAG_REQ,
> + .help = N_("domain name, id or uuid")
> +},
> +{.name = "cmt",
> + .type = VSH_OT_INT,
> + .help = N_("CMT event, as integer (default 0, disable)")
> +},

Imagine we add many more perf events - we don't want to be adding
args to virsh for each one. Instead of --cmt, we should have
'--event cmt'


Regards,
Daniel
-- 
|: http://berrange.com  -o-http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org  -o- http://virt-manager.org :|
|: http://autobuild.org   -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org   -o-   http://live.gnome.org/gtk-vnc :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 7/8] virsh: implement new command to support perf

2015-12-07 Thread Qiaowei Ren
This patch add new perf command to enable/disable perf event
for a guest domain.

Signed-off-by: Qiaowei Ren 
---
 tools/virsh-domain.c | 125 +++
 tools/virsh.pod  |  18 
 2 files changed, 143 insertions(+)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index b7e7606..a47ef9f 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -,6 +,125 @@ cmdMemtune(vshControl *ctl, const vshCmd *cmd)
 }
 
 /*
+ * "perf" command
+ */
+static const vshCmdInfo info_perf[] = {
+{.name = "help",
+.data = N_("Get or set perf event")
+},
+{.name = "desc",
+.data = N_("Get or set the current perf events for a guest"
+   " domain.\n"
+   "To get the perf events list use following command: 
\n\n"
+   "virsh # perf ")
+},
+{.name = NULL}
+};
+
+static const vshCmdOptDef opts_perf[] = {
+{.name = "domain",
+ .type = VSH_OT_DATA,
+ .flags = VSH_OFLAG_REQ,
+ .help = N_("domain name, id or uuid")
+},
+{.name = "cmt",
+ .type = VSH_OT_INT,
+ .help = N_("CMT event, as integer (default 0, disable)")
+},
+{.name = NULL}
+};
+
+static int
+virshPerfGetEventEnabled(vshControl *ctl, const vshCmd *cmd,
+ const char *name, bool *value)
+{
+int ret, tmp;
+const char *str;
+char *end;
+
+ret = vshCommandOptString(ctl, cmd, name, &str);
+if (ret <= 0)
+return ret;
+if (virStrToLong_i(str, &end, 0, &tmp) < 0)
+return -1;
+if (tmp == 1) {
+*value = true;
+ret = 1;
+} else if (tmp == 0) {
+*value = false;
+ret = 1;
+} else {
+ret = -1;
+}
+
+return ret;
+}
+
+static bool
+cmdPerf(vshControl *ctl, const vshCmd *cmd)
+{
+virDomainPtr dom;
+bool tmpVal;
+int nparams = 0;
+int maxparams = 0;
+int rc;
+size_t i;
+virTypedParameterPtr params = NULL;
+bool ret = false;
+
+if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
+return false;
+
+#define PARSE_PERF_PARAM(NAME, FIELD)   \
+if ((rc = virshPerfGetEventEnabled(ctl, cmd, NAME, &tmpVal)) < 0) { \
+vshError(ctl, _("Unable to parse boolean parameter %s"), NAME); \
+goto cleanup;   \
+}   \
+if (rc == 1) {  \
+if (virTypedParamsAddBoolean(¶ms, &nparams, &maxparams, \
+ FIELD, tmpVal) < 0)\
+goto save_error;\
+}   \
+
+
+PARSE_PERF_PARAM("cmt", VIR_PERF_PARAM_CMT);
+
+#undef PARSE_PERF_PARAM
+
+if (nparams == 0) {
+if (virDomainGetPerfEvents(dom, ¶ms, &nparams) != 0) {
+vshError(ctl, "%s", _("Unable to get perf events"));
+goto cleanup;
+}
+for (i = 0; i < nparams; i++) {
+if (params[i].type == VIR_TYPED_PARAM_BOOLEAN &&
+params[i].value.b) {
+vshPrint(ctl, "%-15s: %s\n", params[i].field, _("enabled"));
+} else {
+vshPrint(ctl, "%-15s: %s\n", params[i].field, _("disabled"));
+}
+}
+} else {
+if (virDomainSetPerfEvents(dom, params, nparams) != 0)
+goto error;
+}
+
+ret = true;
+
+ cleanup:
+virTypedParamsFree(params, nparams);
+virDomainFree(dom);
+return ret;
+
+ save_error:
+vshSaveLibvirtError();
+ error:
+vshError(ctl, "%s", _("Unable to enable/disable perf events"));
+goto cleanup;
+}
+
+
+/*
  * "numatune" command
  */
 static const vshCmdInfo info_numatune[] = {
@@ -13406,6 +13525,12 @@ const vshCmdDef domManagementCmds[] = {
  .info = info_memtune,
  .flags = 0
 },
+{.name = "perf",
+ .handler = cmdPerf,
+ .opts = opts_perf,
+ .info = info_perf,
+ .flags = 0
+},
 {.name = "metadata",
  .handler = cmdMetadata,
  .opts = opts_metadata,
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 21ae4a3..6ddf360 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2113,6 +2113,24 @@ The guaranteed minimum memory allocation for the guest.
 
 Specifying -1 as a value for these limits is interpreted as unlimited.
 
+=item B I [I<--cmt> B]
+
+Get the current perf events setting or enable/disable specific perf
+event for a guest domain.
+
+Perf is a performance analyzing tool in Linux, and it can instrument
+CPU performance counters, tracepoints, kprobes, and uprobes (dynamic
+tracing). Perf supports a list of measurable events, and can measure
+events coming from different sources. For instance, some event are
+pure kernel counters, in t