9ad3dcb42b0c93d5e24d99710d7819b6754af259
[virt-top.git] / src / collect.mli
1 (* 'top'-like tool for libvirt domains.
2    (C) Copyright 2007-2017 Richard W.M. Jones, Red Hat Inc.
3    http://libvirt.org/
4
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.
9
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.
14
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.
18 *)
19
20 (* Hook for [Opt_xml] to override (if present). *)
21 val parse_device_xml :
22   (int -> [ `R ] Libvirt.Domain.t -> string list * string list) ref
23
24 (* Intermediate "domain + stats" structure that we use to collect
25  * everything we know about a domain within the collect function.
26  *)
27 type rd_domain = Inactive | Active of rd_active
28 and rd_active = {
29   rd_domid : int;                       (* Domain ID. *)
30   rd_dom : [`R] Libvirt.Domain.t;       (* Domain object. *)
31   rd_info : Libvirt.Domain.info;        (* Domain CPU info now. *)
32   rd_block_stats : (string * Libvirt.Domain.block_stats) list;
33                                         (* Domain block stats now. *)
34   rd_interface_stats : (string * Libvirt.Domain.interface_stats) list;
35                                         (* Domain net stats now. *)
36   rd_prev_info : Libvirt.Domain.info option; (* Domain CPU info previously. *)
37   rd_prev_block_stats : (string * Libvirt.Domain.block_stats) list;
38                                         (* Domain block stats prev. *)
39   rd_prev_interface_stats : (string * Libvirt.Domain.interface_stats) list;
40                                         (* Domain interface stats prev. *)
41   (* The following are since the last slice, or 0 if cannot be calculated: *)
42   rd_cpu_time : float;                  (* CPU time used in nanoseconds. *)
43   rd_percent_cpu : float;               (* CPU time as percent of total. *)
44   rd_mem_bytes : int64;                 (* Memory usage in bytes *)
45   rd_mem_percent: int64;                (* Memory usage as percent of total *)
46   (* The following are since the last slice, or None if cannot be calc'd: *)
47   rd_block_rd_reqs : int64 option;      (* Number of block device read rqs. *)
48   rd_block_wr_reqs : int64 option;      (* Number of block device write rqs. *)
49   rd_block_rd_bytes : int64 option;     (* Number of bytes block device read *)
50   rd_block_wr_bytes : int64 option;     (* Number of bytes block device write *)
51   rd_net_rx_bytes : int64 option;       (* Number of bytes received. *)
52   rd_net_tx_bytes : int64 option;       (* Number of bytes transmitted. *)
53 }
54
55 type stats = {
56   rd_doms : (string * rd_domain) list;  (* List of domains. *)
57   rd_time : float;
58   rd_printable_time : string;
59   rd_nr_pcpus : int;
60   rd_total_cpu : float;
61   rd_total_cpu_per_pcpu : float;
62   rd_totals : (int * int * int * int * int * int * int * int * int * float *
63                  int64 * int64);
64 }
65
66 type pcpu_stats = {
67   rd_pcpu_doms : (int * string * int *
68                   Libvirt.Domain.vcpu_info array * int64 array array *
69                   int64 array array * string * int) list;
70   rd_pcpu_pcpus : int64 array array array;
71   rd_pcpu_pcpus_cpu_time : float array
72 }
73
74 val collect : Types.setup -> stats
75 (** Collect statistics. *)
76
77 val collect_pcpu : stats -> pcpu_stats
78 (** Used in PCPUDisplay mode only, this returns extra per-PCPU stats. *)
79
80 val clear_pcpu_display_data : unit -> unit
81 (** Clear the cache of pcpu_usages used by PCPUDisplay display_mode
82     when we switch back to TaskDisplay mode. *)