440859be7d9768c3694e409e4a79d5db46f85781
[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   (* _info fields includes the number considering --block_in_bytes option *)
52   rd_block_rd_info : int64 option;      (* Block device read info for user *)
53   rd_block_wr_info : int64 option;      (* Block device read info for user *)
54
55   rd_net_rx_bytes : int64 option;       (* Number of bytes received. *)
56   rd_net_tx_bytes : int64 option;       (* Number of bytes transmitted. *)
57 }
58
59 type stats = {
60   rd_doms : (string * rd_domain) list;  (* List of domains. *)
61   rd_time : float;
62   rd_printable_time : string;
63   rd_nr_pcpus : int;
64   rd_total_cpu : float;
65   rd_total_cpu_per_pcpu : float;
66   rd_totals : (int * int * int * int * int * int * int * int * int * float *
67                  int64 * int64);
68 }
69
70 type pcpu_stats = {
71   rd_pcpu_doms : (int * string * int *
72                   Libvirt.Domain.vcpu_info array * int64 array array *
73                   int64 array array * string * int) list;
74   rd_pcpu_pcpus : int64 array array array;
75   rd_pcpu_pcpus_cpu_time : float array
76 }
77
78 val collect : Types.setup -> bool -> stats
79 (** Collect statistics. *)
80
81 val collect_pcpu : stats -> pcpu_stats
82 (** Used in PCPUDisplay mode only, this returns extra per-PCPU stats. *)
83
84 val clear_pcpu_display_data : unit -> unit
85 (** Clear the cache of pcpu_usages used by PCPUDisplay display_mode
86     when we switch back to TaskDisplay mode. *)