vmm_stats: allow vmmapi to fail (and report nothing), more convenient for linux code path

This commit is contained in:
Hannes Mehnert 2018-03-24 23:39:16 +01:00
parent 51d1dc63dc
commit 66df394d36
2 changed files with 25 additions and 23 deletions

View file

@ -69,15 +69,15 @@ let fill_descr ctx =
match !descr with match !descr with
| [] -> | [] ->
begin match wrap vmmapi_statnames ctx with begin match wrap vmmapi_statnames ctx with
| None -> Error (`Msg "vmmapi_statnames failed, shouldn't happen") | None ->
Logs.err (fun m -> m "vmmapi_statnames failed, shouldn't happen") ;
()
| Some d -> | Some d ->
Logs.info (fun m -> m "descr are %a" Fmt.(list ~sep:(unit ",@ ") string) d) ; Logs.info (fun m -> m "descr are %a" Fmt.(list ~sep:(unit ",@ ") string) d) ;
descr := d ; descr := d
Ok ()
end end
| ds -> | ds ->
Logs.info (fun m -> m "descr are already %a" Fmt.(list ~sep:(unit ",@ ") string) ds) ; Logs.info (fun m -> m "descr are already %a" Fmt.(list ~sep:(unit ",@ ") string) ds)
Ok ()
let add_pid t pid nics = let add_pid t pid nics =
let name = "ukvm" ^ string_of_int pid in let name = "ukvm" ^ string_of_int pid in
@ -85,9 +85,7 @@ let add_pid t pid nics =
| None, _ -> Error (`Msg "sysctl ifcount failed") | None, _ -> Error (`Msg "sysctl ifcount failed")
| _, None -> Error (`Msg "vmmapi_open failed") | _, None -> Error (`Msg "vmmapi_open failed")
| Some max_nic, Some vmctx -> | Some max_nic, Some vmctx ->
match fill_descr vmctx with fill_descr vmctx ;
| Error e -> Error e
| Ok () ->
let rec go cnt acc id = let rec go cnt acc id =
if id > 0 && cnt > 0 then if id > 0 && cnt > 0 then
match wrap sysctl_ifdata id with match wrap sysctl_ifdata id with
@ -105,7 +103,11 @@ let stats t pid =
try try
let _, nics = IM.find pid t.pid_nic let _, nics = IM.find pid t.pid_nic
and ru = IM.find pid t.pid_rusage and ru = IM.find pid t.pid_rusage
and vmm = IM.find pid t.pid_vmmapi and vmm =
try IM.find pid t.pid_vmmapi with
| Not_found ->
Logs.err (fun m -> m "failed to find vmm stats for %d" pid);
[]
in in
match match
List.fold_left (fun acc nic -> List.fold_left (fun acc nic ->

View file

@ -213,12 +213,12 @@ CAMLprim value vmmanage_sysctl_ifdata (value num) {
CAMLprim value vmmanage_vmmapi_open (value name) { CAMLprim value vmmanage_vmmapi_open (value name) {
CAMLparam1(name); CAMLparam1(name);
uerror("vmmapi_open", Nothing); CAMLreturn(Val_int(0));
} }
CAMLprim value vmmanage_vmmapi_close (value name) { CAMLprim value vmmanage_vmmapi_close (value name) {
CAMLparam1(name); CAMLparam1(name);
uerror("vmmapi_close", Nothing); CAMLreturn(Val_unit);
} }
CAMLprim value vmmanage_vmmapi_stats (value name) { CAMLprim value vmmanage_vmmapi_stats (value name) {