virt-top
----------------------------------------------------------------------
-Copyright (C) 2007-2016 Richard W.M. Jones, Red Hat Inc.
+Copyright (C) 2007-2021 Richard W.M. Jones, Red Hat Inc.
http://et.redhat.com/~rjones/virt-top/
http://libvirt.org/ocaml/
http://libvirt.org/
OCaml >= 3.11.0
ocaml-libvirt >= 0.6.1.1 (for virDomainGetCPUStats support)
-OCaml extlib
OCaml curses
Optional:
AC_MSG_ERROR([Cannot find required OCaml package 'unix'])
fi
-AC_CHECK_OCAML_PKG(extlib)
-if test "x$OCAML_PKG_extlib" = "xno"; then
- AC_MSG_ERROR([Cannot find required OCaml package 'extlib'])
-fi
-
AC_CHECK_OCAML_PKG(libvirt)
if test "x$OCAML_PKG_libvirt" = "xno"; then
AC_MSG_ERROR([Cannot find required OCaml package 'libvirt'])
collect.cmi : \
types.cmi
csv_output.cmo : \
+ utils.cmi \
collect.cmi \
csv_output.cmi
csv_output.cmx : \
+ utils.cmx \
collect.cmx \
csv_output.cmi
csv_output.cmi : \
version.ml \
virt-top.pod
-OCAMLPACKAGES = -package unix,extlib,curses,str,libvirt
+OCAMLPACKAGES = -package unix,curses,str,libvirt
if HAVE_PKG_GETTEXT
OCAMLPACKAGES += -package gettext-stub
module D = Libvirt.Domain
open Printf
-open ExtList
open Utils
open Types
(* CSV output functions. *)
open Printf
-open ExtList
+open Utils
open Collect
module C = Libvirt.Connect
let cmp (_, { rd_domid = rd_domid1 }) (_, { rd_domid = rd_domid2 }) =
compare rd_domid1 rd_domid2
in
- let doms = List.sort ~cmp doms in
+ let doms = List.sort cmp doms in
- let string_of_int64_option = Option.map_default Int64.to_string "" in
+ let string_of_int64_option = map_default Int64.to_string "" in
let domain_fields = List.map (
fun (domname, rd) ->
open CalendarLib
open Printf
-open ExtString
open Opt_gettext.Gettext ;;
Top.parse_date_time :=
fun time ->
let cal : Calendar.t =
- if String.starts_with time "+" then ( (* +something *)
+ (* time is "+something" *)
+ let is_plus =
+ let n = String.length time in
+ n >= 1 && time.[0] = '+'
+ in
+ if is_plus then (
let period = String.sub time 1 (String.length time - 1) in
let period =
if String.contains period ':' then ( (* +HH:MM:SS *)
This file contains all code which requires xml-light.
*)
-open ExtList
-
open Opt_gettext.Gettext
module C = Libvirt.Connect
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*)
-open ExtList
open Curses
open Printf
if r <> 0 then r
else compare name1 name2
in
- List.sort ~cmp doms in
+ List.sort cmp doms in
(* Print domains. *)
attron A.reverse;
if r <> 0 then r
else compare (dev1, name1) (dev2, name2)
in
- List.sort ~cmp devs in
+ List.sort cmp devs in
(* Print the header for network devices. *)
attron A.reverse;
if r <> 0 then r
else compare (dev1, name1) (dev2, name2)
in
- List.sort ~cmp devs in
+ List.sort cmp devs in
(* Print the header for block devices. *)
attron A.reverse;
(* Time to grab another historical %CPU for the list? *)
if time >= !historical_cpu_last_time +. float historical_cpu_delay
then (
- historical_cpu := percent_cpu :: List.take 10 !historical_cpu;
+ historical_cpu := percent_cpu :: list_take 10 !historical_cpu;
historical_cpu_last_time := time
);
(* [--stream] mode output functions. *)
open Printf
-open ExtList
open Utils
open Collect
| Inactive, Inactive -> 0)
in
let cmp (name1, dom1) (name2, dom2) = compare(dom1, dom2) in
- List.sort ~cmp doms in
+ List.sort cmp doms in
(*Print domains *)
let dump_domain = fun name rd
-> begin
*)
open Printf
-open ExtList
open Curses
open Opt_gettext.Gettext
let trim ?(test = isspace) str =
trimr (triml str)
+(* Split string on the first instance of 'sep' character. *)
+let split str sep =
+ try
+ let i = String.index str sep in
+ String.sub str 0 i, String.sub str (i+1) (String.length str - 1)
+ with
+ Not_found -> str, ""
+
(* Read a configuration file as a list of (key, value) pairs.
* If the config file is missing this returns an empty list.
*)
(* Convert to key, value pairs. *)
List.map (
fun (lineno, line) ->
- let key, value = ExtString.String.split line " " in
+ let key, value = split line ' ' in
lineno, trim key, trim value
) lines
else (* if n < width then *) str ^ String.make (width-n) ' '
)
+(* Take up to n elements of xs, if available. *)
+let rec list_take n xs =
+ if n <= 0 then []
+ else (
+ match xs with
+ | [] -> []
+ | x :: xs -> x :: list_take (n-1) xs
+ )
+
+let map_default f def = function
+ | None -> def
+ | Some v -> f v
+
module Show = struct
(* Show a percentage in 4 chars. *)
let percent percent =
(* Pad or truncate a string to a fixed width. *)
val pad : int -> string -> string
+(* Take up to n elements of xs, if available. *)
+val list_take : int -> 'a list -> 'a list
+
+(* Apply function f to [Some v], return default for [None] *)
+val map_default : ('a -> 'b) -> 'b -> 'a option -> 'b
+
(* Int64 operators for convenience. *)
val (+^) : int64 -> int64 -> int64
val (-^) : int64 -> int64 -> int64