summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2008-01-08 15:14:15 +0000
committerRichard W.M. Jones <rjones@redhat.com>2008-01-08 15:14:15 +0000
commit78211c61c64d314ddcae5386c1bdfde2fd69aab8 (patch)
tree5ac9ca38376cebd064466ff1d81bf485116c08b2
parentc296b68c99f8c22b0c7db1b072a6cd86f9ac3da9 (diff)
downloadvirt-top-78211c61c64d314ddcae5386c1bdfde2fd69aab8.tar.gz
virt-top-78211c61c64d314ddcae5386c1bdfde2fd69aab8.tar.xz
virt-top-78211c61c64d314ddcae5386c1bdfde2fd69aab8.zip
Get node_info just once for each connection.
* vc_connections.ml: Get node_info just once for each connection, which is more efficient. * vc_connections.mli: Tidy up.
-rw-r--r--ChangeLog5
-rw-r--r--virt-ctrl/vc_connections.ml41
-rw-r--r--virt-ctrl/vc_connections.mli4
3 files changed, 37 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 4d8fd69..2dea1a2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2008-01-08 Richard Jones <rjones@redhat.com>
+ Get node_info just once for each connection.
+ * vc_connections.ml: Get node_info just once for each connection,
+ which is more efficient.
+ * vc_connections.mli: Tidy up.
+
Type Vc_domain_ops.dops_callback_fn for clarity.
* virt-ctrl/vc_domain_ops.mli, virt-ctrl/vc_domain_ops.ml,
virt-ctrl/vc_mainwindow.mli: Give a type name to the domain_ops
diff --git a/virt-ctrl/vc_connections.ml b/virt-ctrl/vc_connections.ml
index 5525f5e..7e58aee 100644
--- a/virt-ctrl/vc_connections.ml
+++ b/virt-ctrl/vc_connections.ml
@@ -59,6 +59,12 @@ and inactive = string (* domain's name *)
let last_cpu_time = Hashtbl.create 13
let last_time = ref (Unix.gettimeofday ())
+(* Store the node_info and hostname for each connection, fetched
+ * once just after we connect since these don't normally change.
+ * Hash of connid -> (C.node_info, hostname option, uri)
+ *)
+let static_conn_info = Hashtbl.create 13
+
type columns = string GTree.column * string GTree.column * string GTree.column * string GTree.column * string GTree.column * int GTree.column
let debug_repopulate = true
@@ -97,14 +103,15 @@ let repopulate (tree : GTree.view) (model : GTree.tree_store)
List.iter (
fun conn_id ->
let row = model#append () in
- (* Get the connection name. *)
+ (* Get the connection name, usually the hostname. *)
let name =
- try C.get_hostname (List.assoc conn_id conns)
- with Not_found | Libvirt.Virterror _ ->
- "Conn #" ^ string_of_int conn_id in
+ match Hashtbl.find static_conn_info conn_id with
+ | (_, Some hostname, _) -> hostname
+ | (_, None, _) -> sprintf "Conn #%d" conn_id in
model#set ~row ~column:col_name_id name;
model#set ~row ~column:col_id conn_id;
- (* XXX This doesn't work, why? *)
+ (* Expand the new row. *)
+ (* XXX This doesn't work, why? - Because we haven't create subrows yet.*)
tree#expand_row (model#get_path row)
) added;
@@ -127,8 +134,8 @@ let repopulate (tree : GTree.view) (model : GTree.tree_store)
with Not_found -> assert false (* Should never happen. *) in
try
- (* Node info & number of CPUs available. *)
- let node_info = C.get_node_info conn in
+ (* Number of CPUs available. *)
+ let node_info, _, _ = Hashtbl.find static_conn_info conn_id in
let nr_cpus = C.maxcpus_of_node_info node_info in
(* For this connection, get a current list of active domains (IDs) *)
@@ -314,13 +321,23 @@ let make_treeview ?packing () =
*)
let open_connection () =
let title = "Open connection to hypervisor" in
- let name =
+ let uri =
GToolbox.input_string ~title ~text:"xen:///" ~ok:"Open" "Connection:" in
- match name with
+ match uri with
| None -> ()
- | Some name ->
+ | Some uri ->
(* If this fails, let the exception escape and be printed
* in the global exception handler.
*)
- let conn = C.connect ~name () in
- ignore (add_conn conn)
+ let conn = C.connect ~name:uri () in
+
+ let node_info = C.get_node_info conn in
+ let hostname =
+ try Some (C.get_hostname conn)
+ with
+ | Libvirt.Not_supported "virConnectGetHostname"
+ | Libvirt.Virterror _ -> None in
+
+ (* Add it to our list of connections. *)
+ let conn_id = add_conn conn in
+ Hashtbl.add static_conn_info conn_id (node_info, hostname, uri)
diff --git a/virt-ctrl/vc_connections.mli b/virt-ctrl/vc_connections.mli
index 13c1f20..d3542dc 100644
--- a/virt-ctrl/vc_connections.mli
+++ b/virt-ctrl/vc_connections.mli
@@ -41,7 +41,9 @@ val repopulate : GTree.view -> GTree.tree_store -> columns -> state -> state
(** Create the GtkTreeView. Returns the widget itself, the model,
the list of columns, and the initial state.
*)
-val make_treeview : ?packing:(GObj.widget -> unit) -> unit -> GTree.view * GTree.tree_store * columns * state
+val make_treeview :
+ ?packing:(GObj.widget -> unit) -> unit ->
+ GTree.view * GTree.tree_store * columns * state
(** This callback creates the Connect to hypervisor dialog. *)
val open_connection : unit -> unit