X-Git-Url: http://git.annexia.org/?p=virt-top.git;a=blobdiff_plain;f=virt-top%2Fvirt_top.ml;h=90ceec22fa53be8842af3a6e2bb38caab8a81858;hp=a8c483933f4df3da443a311823639e9c307c14a1;hb=4572fe6a2493a377d696e3f28996c0236e8e8f4d;hpb=46d3772c9a5cf786fa4fbdb2ba29512580101f32 diff --git a/virt-top/virt_top.ml b/virt-top/virt_top.ml index a8c4839..90ceec2 100644 --- a/virt-top/virt_top.ml +++ b/virt-top/virt_top.ml @@ -28,6 +28,8 @@ module C = Libvirt.Connect module D = Libvirt.Domain module N = Libvirt.Network +let rcfile = ".virt-toprc" + (* Hook for XML support (see virt_top_xml.ml). *) let parse_device_xml : (int -> [>`R] D.t -> string list * string list) ref = ref ( @@ -155,6 +157,10 @@ let start_up () = and no_init_file () = init_file := NoInitFile and set_init_file filename = init_file := InitFile filename and set_end_time time = end_time := Some ((!parse_date_time) time) + and display_version () = + printf "virt-top %s ocaml-libvirt %s\n" + Virt_top_version.version Libvirt_version.version; + exit 0 in let argspec = Arg.align [ "-1", Arg.Unit set_pcpu_mode, @@ -197,6 +203,8 @@ let start_up () = " " ^ s_ "Secure (\"kiosk\") mode"; "--script", Arg.Set script_mode, " " ^ s_ "Run from a script (no user interface)"; + "--version", Arg.Unit display_version, + " " ^ s_ "Display version number and exit"; ] in let anon_fun str = raise (Arg.Bad (sprintf (f_ "%s: unknown parameter") str)) in @@ -238,7 +246,7 @@ OPTIONS" in | NoInitFile -> () | DefaultInitFile -> let home = try Sys.getenv "HOME" with Not_found -> "/" in - let filename = home // ".virt-toprc" in + let filename = home // rcfile in try_to_read_init_file filename | InitFile filename -> try_to_read_init_file filename @@ -1179,7 +1187,9 @@ let write_csv_header () = [ "Hostname"; "Time"; "Arch"; "Physical CPUs"; "Count"; "Running"; "Blocked"; "Paused"; "Shutdown"; "Shutoff"; "Crashed"; "Active"; "Inactive"; - "%CPU"; "Total memory (KB)"; "Total guest memory (KB)"; + "%CPU"; + "Total hardware memory (KB)"; + "Total memory (KB)"; "Total guest memory (KB)"; "Total CPU time (ns)" ] @ (* These fields are repeated for each domain: *) [ "Domain ID"; "Domain name"; ] @ @@ -1210,6 +1220,7 @@ let append_csv string_of_int paused; string_of_int shutdown; string_of_int shutoff; string_of_int crashed; string_of_int active; string_of_int inactive; sprintf "%2.1f" percent_cpu; + Int64.to_string node_info.C.memory; Int64.to_string total_memory; Int64.to_string total_domU_memory; Int64.to_string (Int64.of_float total_cpu_time) ] in @@ -1462,7 +1473,7 @@ and write_init_file () = | NoInitFile -> () (* Do nothing if --no-init-file *) | DefaultInitFile -> let home = try Sys.getenv "HOME" with Not_found -> "/" in - let filename = home // ".virt-toprc" in + let filename = home // rcfile in _write_init_file filename | InitFile filename -> _write_init_file filename @@ -1487,7 +1498,7 @@ and _write_init_file filename = let fp = fprintf in let nl () = fp chan "\n" in - let () = fp chan (f_ "# .virt-toprc virt-top configuration file\n") in + let () = fp chan (f_ "# %s virt-top configuration file\n") rcfile in let () = fp chan (f_ "# generated on %s by %s\n") printable_date_time username in nl (); fp chan "display %s\n" (cli_of_display !display_mode); @@ -1502,13 +1513,13 @@ and _write_init_file filename = if !batch_mode = true then fp chan "batch true\n"; if !secure_mode = true then fp chan "secure true\n"; nl (); - let () = fp chan (f_ "# To send debug and error messages to a file, uncomment next line\n") in + output_string chan (s_ "# To send debug and error messages to a file, uncomment next line\n"); fp chan "#debug virt-top.out\n"; nl (); - let () = fp chan (f_ "# Enable CSV output to the named file\n") in + output_string chan (s_ "# Enable CSV output to the named file\n"); fp chan "#csv virt-top.csv\n"; nl (); - let () = fp chan (f_ "# To protect this file from being overwritten, uncomment next line\n") in + output_string chan (s_ "# To protect this file from being overwritten, uncomment next line\n"); fp chan "#overwrite-init-file false\n"; close_out chan; @@ -1540,8 +1551,10 @@ and show_help (_, _, _, _, _, hostname, (* Banner at the top of the screen. *) let banner = - sprintf (f_ "virt-top %s (libvirt %d.%d.%d) by Red Hat") - Libvirt_version.version libvirt_major libvirt_minor libvirt_release in + sprintf (f_ "virt-top %s ocaml-libvirt %s libvirt %d.%d.%d by Red Hat") + Virt_top_version.version + Libvirt_version.version + libvirt_major libvirt_minor libvirt_release in let banner = pad cols banner in attron A.reverse; mvaddstr 0 0 banner;