[PATCHv3 1/2] add parameter flags to D.get_cpu_stats()

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

 



---
 examples/get_cpu_stats.ml   |    2 +-
 libvirt/libvirt.ml          |    6 +++++-
 libvirt/libvirt.mli         |    6 +++++-
 libvirt/libvirt_c_oneoffs.c |   21 +++++++++++++++++----
 4 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/examples/get_cpu_stats.ml b/examples/get_cpu_stats.ml
index 79d5c3c..962a2a4 100644
--- a/examples/get_cpu_stats.ml
+++ b/examples/get_cpu_stats.ml
@@ -25,7 +25,7 @@ let () =
 
     let stats =
       let dom = D.lookup_by_name conn domname in
-      D.get_cpu_stats dom nr_pcpus in
+      D.get_cpu_stats dom nr_pcpus [D.None;] in
 
     Array.iteri (
       fun n params ->
diff --git a/libvirt/libvirt.ml b/libvirt/libvirt.ml
index 53c5bb4..de303f7 100644
--- a/libvirt/libvirt.ml
+++ b/libvirt/libvirt.ml
@@ -348,6 +348,10 @@ struct
     | TypedFieldFloat of float | TypedFieldBool of bool
     | TypedFieldString of string
 
+  type get_cpu_stats_flags =
+    | None
+    | Vcpu
+
   type migrate_flag = Live
 
   type memory_flag = Virtual
@@ -417,7 +421,7 @@ struct
   external set_vcpus : [>`W] t -> int -> unit = "ocaml_libvirt_domain_set_vcpus"
   external pin_vcpu : [>`W] t -> int -> string -> unit = "ocaml_libvirt_domain_pin_vcpu"
   external get_vcpus : [>`R] t -> int -> int -> int * vcpu_info array * string = "ocaml_libvirt_domain_get_vcpus"
-  external get_cpu_stats : [>`R] t -> int -> typed_param list array = "ocaml_libvirt_domain_get_cpu_stats"
+  external get_cpu_stats : [>`R] t -> int -> get_cpu_stats_flags list -> typed_param list array = "ocaml_libvirt_domain_get_cpu_stats"
   external get_max_vcpus : [>`R] t -> int = "ocaml_libvirt_domain_get_max_vcpus"
   external attach_device : [>`W] t -> xml -> unit = "ocaml_libvirt_domain_attach_device"
   external detach_device : [>`W] t -> xml -> unit = "ocaml_libvirt_domain_detach_device"
diff --git a/libvirt/libvirt.mli b/libvirt/libvirt.mli
index 0913a63..5a7e536 100644
--- a/libvirt/libvirt.mli
+++ b/libvirt/libvirt.mli
@@ -442,6 +442,10 @@ sig
     | TypedFieldFloat of float | TypedFieldBool of bool
     | TypedFieldString of string
 
+  type get_cpu_stats_flags =
+    | None
+    | Vcpu
+
   type migrate_flag = Live
 
   type memory_flag = Virtual
@@ -559,7 +563,7 @@ sig
 	for a domain.  See the libvirt documentation for details
 	of the array and bitmap returned from this function.
     *)
-  val get_cpu_stats : [>`R] t -> int -> typed_param list array
+  val get_cpu_stats : [>`R] t -> int -> get_cpu_stats_flags list -> typed_param list array
     (** [get_pcpu_stats dom nr_pcpu] returns the physical CPU stats
 	for a domain.  See the libvirt documentation for details.
     *)
diff --git a/libvirt/libvirt_c_oneoffs.c b/libvirt/libvirt_c_oneoffs.c
index 3d42b73..5d1e8b2 100644
--- a/libvirt/libvirt_c_oneoffs.c
+++ b/libvirt/libvirt_c_oneoffs.c
@@ -532,20 +532,33 @@ 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)
 {
 #ifdef HAVE_VIRDOMAINGETCPUSTATS
-  CAMLparam2 (domv, nr_pcpusv);
+  CAMLparam3 (domv, nr_pcpusv, flagsv);
   CAMLlocal5 (cpustats, param_head, param_node, typed_param, typed_param_value);
   CAMLlocal1 (v);
   virDomainPtr dom = Domain_val (domv);
   virConnectPtr conn = Connect_domv (domv);
   int nr_pcpus = Int_val (nr_pcpusv);
+  int flags = 0;
   virTypedParameterPtr params;
   int r, cpu, ncpus, nparams, i, j, pos;
 
+  /* Iterate over the list of flags. */
+  for (; flagsv != Val_int (0); flagsv = Field (flagsv, 1))
+    {
+      switch (Int_val(Field(flagsv, 0))) {
+      case 1: /* Vcpu */
+	flags |= VIR_DOMAIN_CPU_STATS_VCPU;
+	break;
+      default:
+	break;
+      }
+    }
+
   /* get percpu information */
-  NONBLOCKING (nparams = virDomainGetCPUStats(dom, NULL, 0, 0, 1, 0));
+  NONBLOCKING (nparams = virDomainGetCPUStats(dom, NULL, 0, 0, 1, flags));
   CHECK_ERROR (nparams < 0, conn, "virDomainGetCPUStats");
 
   if ((params = malloc(sizeof(*params) * nparams * 128)) == NULL)
@@ -556,7 +569,7 @@ ocaml_libvirt_domain_get_cpu_stats (value domv, value nr_pcpusv)
   while (cpu < nr_pcpus) {
     ncpus = nr_pcpus - cpu > 128 ? 128 : nr_pcpus - cpu;
 
-    NONBLOCKING (r = virDomainGetCPUStats(dom, params, nparams, cpu, ncpus, 0));
+    NONBLOCKING (r = virDomainGetCPUStats(dom, params, nparams, cpu, ncpus, flags));
     CHECK_ERROR (r < 0, conn, "virDomainGetCPUStats");
 
     for (i = 0; i < ncpus; i++) {
-- 
1.7.1

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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]