[virt-tools-list] [PATCH 2/3] virt-top : stream mode core

KAMEZAWA Hiroyuki kamezawa.hiroyu at jp.fujitsu.com
Thu Jan 27 04:26:41 UTC 2011


Show per domain details in stream mode.

[root at bluextal virt-top-1.0.4]# ./virt-top/virt-top --stream -d 1 -n 5
virt-top time  09:57:36 Host bluextal x86_64 8/8CPU 1999MHz 24033MB
   ID S RDRQ WRRQ RXBY TXBY %CPU %MEM   TIME    NAME
    5 R    0    0    0    0  0.0 34.0 491:00.89 RHEL6
virt-top time  09:57:37 Host bluextal x86_64 8/8CPU 1999MHz 24033MB
   ID S RDRQ WRRQ RXBY TXBY %CPU %MEM   TIME    NAME
    5 R    0    3   52    0  0.7 34.0 491:00.95 RHEL6

Considering parsing this output by some other script language,
the 1st information of RDRQ/WRRQ/RXBY/TXBY/ is filled with "0"

Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu at jp.fujitsu.com>
---
 virt-top/virt_top.ml |   49 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 46 insertions(+), 3 deletions(-)

Index: virt-top-1.0.5/virt-top/virt_top.ml
===================================================================
--- virt-top-1.0.5.orig/virt-top/virt_top.ml
+++ virt-top-1.0.5/virt-top/virt_top.ml
@@ -1277,10 +1277,53 @@ let dump_stdout
      nr_pcpus, total_cpu, _,
      totals,
      _) (* state *) =
-
-   printf "Time %s Host %s %s %d/%dCPU %dMHz %LdMB \n%!"
+   (* Header for this iteration *)
+   printf "virt-top time  %s Host %s %s %d/%dCPU %dMHz %LdMB \n"
      printable_time hostname node_info.C.model node_info.C.cpus nr_pcpus
-     node_info.C.mhz (node_info.C.memory /^ 1024L) ;;
+     node_info.C.mhz (node_info.C.memory /^ 1024L);
+   (* dump domain information one by one *)
+   printf "   ID S RDRQ WRRQ RXBY TXBY %%CPU %%MEM   TIME    NAME\n";
+   (* sort by ID *)
+   let doms =
+     let compare =
+       (function
+        | Active {rd_domid = id1 }, Active {rd_domid = id2} ->
+          compare id1 id2
+        | Active _, Inactive -> -1
+        | Inactive, Active _ -> 1
+        | Inactive, Inactive -> 0)
+      in
+      let cmp  (name1, dom1) (name2, dom2) = compare(dom1, dom2) in
+      List.sort ~cmp doms in
+      (*Print domains *)
+      let dump_domain = fun name rd
+      -> begin
+         let state = show_state rd.rd_info.D.state in
+         let rd_req = if rd.rd_block_rd_reqs = None then "   0"
+                      else Show.int64_option rd.rd_block_rd_reqs in
+         let wr_req = if rd.rd_block_wr_reqs = None then "   0"
+                      else Show.int64_option rd.rd_block_wr_reqs in
+         let rx_bytes = if rd.rd_net_rx_bytes = None then "   0"
+                      else Show.int64_option rd.rd_net_rx_bytes in
+         let tx_bytes = if rd.rd_net_tx_bytes = None then "   0"
+                      else Show.int64_option rd.rd_net_tx_bytes in
+         let percent_cpu = Show.percent rd.rd_percent_cpu in
+         let percent_mem =
+         100L *^ rd.rd_info.D.memory /^ node_info.C.memory in
+         let percent_mem = Int64.to_float percent_mem in
+         let percent_mem = Show.percent percent_mem in
+         let time = Show.time rd.rd_info.D.cpu_time in
+         printf "%5d %c %s %s %s %s %s %s %s %s\n"
+               rd.rd_domid state rd_req wr_req rx_bytes tx_bytes
+               percent_cpu percent_mem time name;
+         end
+      in
+      List.iter (
+        function
+        | name, Active dom -> dump_domain name dom
+        | name, Inactive -> ()
+      ) doms;
+     flush stdout;;
 
 (* Main loop. *)
 let rec main_loop ((_, batch_mode, script_mode, csv_enabled, stream_mode, _, _, _)




More information about the virt-tools-list mailing list