[libvirt] [PATCHv4 1/2] Add a new param 'vcpu_time' to virDomainGetCPUStats

Eric Blake eblake at redhat.com
Thu May 17 18:40:24 UTC 2012


On 05/09/2012 02:41 AM, Hu Tao wrote:
> Currently virDomainGetCPUStats gets total cpu usage, which consists
> of:
> 
>   1. vcpu usage: the physical cpu time consumed by virtual cpu(s) of
>      domain
>   2. hypervisor: `total cpu usage' - `vcpu usage'
> 
> The param 'vcpu_time' is for getting vcpu usages.
> ---
>  include/libvirt/libvirt.h.in |    6 ++++++
>  tools/virsh.c                |   14 ++++++++------
>  2 files changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
> index ac5df95..2449cee 100644
> --- a/include/libvirt/libvirt.h.in
> +++ b/include/libvirt/libvirt.h.in
> @@ -1355,6 +1355,12 @@ int                     virDomainGetState       (virDomainPtr domain,
>   */
>  #define VIR_DOMAIN_CPU_STATS_SYSTEMTIME "system_time"
>  
> +/**
> + * VIR_DOMAIN_CPU_STATS_VCPUTIME:
> + * vcpu usage in nanoseconds, as a ullong

Here would be a good place to describe the relation between the two
parameters.


> +++ b/tools/virsh.c
> @@ -5572,6 +5572,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
>      virTypedParameterPtr params = NULL;
>      int i, j, pos, max_id, cpu = -1, show_count = -1, nparams;
>      bool show_total = false, show_per_cpu = false;
> +    unsigned int flags = 0;

We didn't really use flags in this patch, but it doesn't hurt to add it now.

> @@ -5630,7 +5631,8 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
>              for (j = 0; j < nparams; j++) {
>                  pos = i * nparams + j;
>                  vshPrint(ctl, "\t%-12s ", params[pos].field);
> -                if (STREQ(params[pos].field, VIR_DOMAIN_CPU_STATS_CPUTIME) &&
> +                if ((STREQ(params[pos].field, VIR_DOMAIN_CPU_STATS_CPUTIME) ||
> +                     STREQ(params[pos].field, VIR_DOMAIN_CPU_STATS_CPUTIME)) &&

You meant s/CPUTIME/VCPUTIME/ on one of these two STREQ.

ACK with this squashed in:

diff --git i/include/libvirt/libvirt.h.in w/include/libvirt/libvirt.h.in
index 2449cee..a817db8 100644
--- i/include/libvirt/libvirt.h.in
+++ w/include/libvirt/libvirt.h.in
@@ -1339,7 +1339,8 @@ int                     virDomainGetState
(virDomainPtr domain,

 /**
  * VIR_DOMAIN_CPU_STATS_CPUTIME:
- * cpu usage in nanoseconds, as a ullong
+ * cpu usage (sum of both vcpu and hypervisor usage) in nanoseconds,
+ * as a ullong
  */
 #define VIR_DOMAIN_CPU_STATS_CPUTIME "cpu_time"

@@ -1357,7 +1358,8 @@ int                     virDomainGetState
(virDomainPtr domain,

 /**
  * VIR_DOMAIN_CPU_STATS_VCPUTIME:
- * vcpu usage in nanoseconds, as a ullong
+ * vcpu usage in nanoseconds (cpu_time excluding hypervisor time),
+ * as a ullong
  */
 #define VIR_DOMAIN_CPU_STATS_VCPUTIME "vcpu_time"

diff --git i/tools/virsh.c w/tools/virsh.c
index 414c810..46239fa 100644
--- i/tools/virsh.c
+++ w/tools/virsh.c
@@ -5632,7 +5632,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
                 pos = i * nparams + j;
                 vshPrint(ctl, "\t%-12s ", params[pos].field);
                 if ((STREQ(params[pos].field,
VIR_DOMAIN_CPU_STATS_CPUTIME) ||
-                     STREQ(params[pos].field,
VIR_DOMAIN_CPU_STATS_CPUTIME)) &&
+                     STREQ(params[pos].field,
VIR_DOMAIN_CPU_STATS_VCPUTIME)) &&
                     params[j].type == VIR_TYPED_PARAM_ULLONG) {
                     vshPrint(ctl, "%9lld.%09lld seconds\n",
                              params[pos].value.ul / 1000000000,


-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120517/1915e9cc/attachment-0001.sig>


More information about the libvir-list mailing list