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

Re: [libvirt] [PATCHv2 1/2] Add a new flag VIR_DOMAIN_CPU_STATS_VCPU to virDomainGetCPUStats



On Wed, May 02, 2012 at 01:43:03PM -0600, Eric Blake wrote:
> On 04/24/2012 03:20 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 flag VIR_DOMAIN_CPU_STATS_VCPU is for getting vcpu usages.
> > ---
> >  include/libvirt/libvirt.h.in |    8 ++++++++
> >  src/libvirt.c                |    9 +++++++--
> >  tools/virsh.c                |   16 +++++++++++-----
> >  3 files changed, 26 insertions(+), 7 deletions(-)
> 
> Question: is it better to make the user call virDomainGetCPUStats twice
> (once for total with flags==0, once for vcpu with flags=VCPU), where
> there is a race between the two calls?  Or should we instead return both
> counts in the same call, by having two separate virTypedParameter stat
> names and no flag?

Slightly off-topic ...

My opinion on this -- and it applies to many libvirt calls -- is that
APIs where you have to call them twice, once to size the result, and a
second time to get the result, are obtuse and hard to use.

In libguestfs I took the approach that all calls return malloc'd
strings, arrays, etc of the right size.  The caller has to free the
data, but that's the lesser of two evils.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org


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