1 (* 'top'-like tool for libvirt domains.
2 (C) Copyright 2007-2017 Richard W.M. Jones, Red Hat Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 (* [--stream] mode output functions. *)
27 module C = Libvirt.Connect
28 module D = Libvirt.Domain
30 let append_stream (_, _, _, _, _, node_info, hostname, _) (* setup *)
33 rd_printable_time = printable_time;
34 rd_nr_pcpus = nr_pcpus; rd_total_cpu = total_cpu;
35 rd_totals = totals } (* state *) =
36 (* Header for this iteration *)
37 printf "virt-top time %s Host %s %s %d/%dCPU %dMHz %LdMB \n"
38 printable_time hostname node_info.C.model node_info.C.cpus nr_pcpus
39 node_info.C.mhz (node_info.C.memory /^ 1024L);
40 (* dump domain information one by one *)
41 let rd, wr = if block_in_bytes then "RDBY", "WRBY" else "RDRQ", "WRRQ"
43 printf " ID S %s %s RXBY TXBY %%CPU %%MEM TIME NAME\n" rd wr;
49 | Active {rd_domid = id1 }, Active {rd_domid = id2} ->
51 | Active _, Inactive -> -1
52 | Inactive, Active _ -> 1
53 | Inactive, Inactive -> 0)
55 let cmp (name1, dom1) (name2, dom2) = compare(dom1, dom2) in
58 let dump_domain = fun name rd
60 let state = Screen.show_state rd.rd_info.D.state in
62 if rd.rd_block_rd_reqs = None then " 0"
64 if block_in_bytes then Show.int64_option rd.rd_block_rd_bytes
65 else Show.int64_option rd.rd_block_rd_reqs in
67 if rd.rd_block_wr_reqs = None then " 0"
69 if block_in_bytes then Show.int64_option rd.rd_block_wr_bytes
70 else Show.int64_option rd.rd_block_wr_reqs in
71 let rx_bytes = if rd.rd_net_rx_bytes = None then " 0"
72 else Show.int64_option rd.rd_net_rx_bytes in
73 let tx_bytes = if rd.rd_net_tx_bytes = None then " 0"
74 else Show.int64_option rd.rd_net_tx_bytes in
75 let percent_cpu = Show.percent rd.rd_percent_cpu in
76 let percent_mem = Int64.to_float rd.rd_mem_percent in
77 let percent_mem = Show.percent percent_mem in
78 let time = Show.time rd.rd_info.D.cpu_time in
79 printf "%5d %c %s %s %s %s %s %s %s %s\n"
80 rd.rd_domid state rd_req wr_req rx_bytes tx_bytes
81 percent_cpu percent_mem time name;
86 | name, Active dom -> dump_domain name dom
87 | name, Inactive -> ()