On Wed, Apr 18, 2012 at 09:18:45AM -0600, Eric Blake wrote:
On 04/18/2012 05:14 AM, Hu Tao wrote:
> ---
> examples/get_cpu_stats.ml | 2 +-
> libvirt/libvirt.ml | 2 +-
> libvirt/libvirt.mli | 2 +-
> libvirt/libvirt_c_oneoffs.c | 9 +++++----
> 4 files changed, 8 insertions(+), 7 deletions(-)
>
> +++ b/libvirt/libvirt_c_oneoffs.c
> @@ -532,20 +532,21 @@ extern int virDomainGetCPUStats (virDomainPtr domain,
> #endif
>
> CAMLprim value
> -ocaml_libvirt_domain_get_cpu_stats (value domv, value nr_pcpusv)
> +ocaml_libvirt_domain_get_cpu_stats (value domv, value nr_pcpusv, value flagsv)
This adds flags support to the per-cpu half of the libvirt API, but you
are still missing ocaml bindings for the portion of the libvirt API that
accesses the domain total stats. Also, I never understood why the
caller has to know how many cpus they are passing in advance - shouldn't
the bindings be smart enough to return an appropriately sized array that
covers all possible cpus without the caller having to pre-specify that
sizing?
For comparison, in the python bindings, we expressed things as:
if (!PyArg_ParseTuple(args, (char *)"OOi:virDomainGetCPUStats",
&pyobj_domain, &totalbool, &flags))
so that a user passes in the domain; a choice of whether they want total
stats (pass true to get a 1-element array back, corresponding to the C
code passing start_cpu of -1), or per-cpu stats (pass fals to get an
n-element array back, with each element mapping to a cpu, and with the
array sized according to all cpus available); and finally a flags parameter.
It's certainly a unusual, and I agree that we should go with the
model used by the Python bindings.
FWIW it's probably because 'nr_pcpus' happens to be available
conveniently as a value in virt-top at the point when 'get_cpu_stats'
is called.
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