[PATCH 1/1 V3] ocaml-libvirt: and virDomainGetPcpusUsage() API to ocaml-libvirt

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

 



Acked-by: "Richard W.M. Jones" <rjones@xxxxxxxxxx>
Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
---
 libvirt/libvirt.ml          |    1 +
 libvirt/libvirt.mli         |    4 ++++
 libvirt/libvirt_c_oneoffs.c |   25 +++++++++++++++++++++++++
 3 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/libvirt/libvirt.ml b/libvirt/libvirt.ml
index fc29264..a8720a9 100644
--- a/libvirt/libvirt.ml
+++ b/libvirt/libvirt.ml
@@ -419,6 +419,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_pcpu_usages : [>`R] t -> int -> int64 array = "ocaml_libvirt_domain_get_pcpu_usages"
   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 7bda889..63bf830 100644
--- a/libvirt/libvirt.mli
+++ b/libvirt/libvirt.mli
@@ -586,6 +586,10 @@ sig
 	for a domain.  See the libvirt documentation for details
 	of the array and bitmap returned from this function.
     *)
+  val get_pcpu_usages : [>`R] t -> int -> int64 array
+    (** [get_pcpu_usages dom nr_pcpu] returns the physical CPU usages
+	for a domain.  See the libvirt documentation for details.
+    *)
   val get_max_vcpus : [>`R] t -> int
     (** Returns the maximum number of vCPUs supported for this domain. *)
   val attach_device : [>`W] t -> xml -> unit
diff --git a/libvirt/libvirt_c_oneoffs.c b/libvirt/libvirt_c_oneoffs.c
index d87dd21..68d5ecc 100644
--- a/libvirt/libvirt_c_oneoffs.c
+++ b/libvirt/libvirt_c_oneoffs.c
@@ -604,6 +604,31 @@ ocaml_libvirt_domain_get_vcpus (value domv, value maxinfov, value maplenv)
   CAMLreturn (rv);
 }
 
+CAMLprim value
+ocaml_libvirt_domain_get_pcpu_usages (value domv, value nr_pcpusv)
+{
+  CAMLparam2 (domv, nr_pcpusv);
+  CAMLlocal1 (usagev);
+  virDomainPtr dom = Domain_val (domv);
+  virConnectPtr conn = Connect_domv (domv);
+  int nr_pcpus = Int_val (nr_pcpusv);
+  unsigned long long pcpu_usages[nr_pcpus];
+  int r, i;
+
+  memset (pcpu_usages, 0, sizeof(pcpu_usages[0]) * nr_pcpus);
+
+  NONBLOCKING (r = virDomainGetPcpusUsage (dom, pcpu_usages, &nr_pcpus, 0));
+  CHECK_ERROR (r == -1, conn, "virDomainGetPcpusUsage");
+
+  /* Copy the pcpu_usages. */
+  usagev = caml_alloc (nr_pcpus, 0);
+  for (i = 0; i < nr_pcpus; ++i) {
+    Store_field (usagev, i, caml_copy_int64 ((int64_t)pcpu_usages[i]));
+  }
+
+  CAMLreturn (usagev);
+}
+
 #ifdef HAVE_WEAK_SYMBOLS
 #ifdef HAVE_VIRDOMAINMIGRATE
 extern virDomainPtr virDomainMigrate (virDomainPtr domain, virConnectPtr dconn,
-- 
1.7.4.4

--
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]