From bf53d65dd089f3608ee5a08f63f9739e9bbe54d4 Mon Sep 17 00:00:00 2001 From: Paul Steckler Date: Tue, 1 Dec 2020 16:47:06 -0800 Subject: [PATCH 1/2] Dump hardware details for Linux --- src/lib/coda_lib/conf_dir.ml | 56 +++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/src/lib/coda_lib/conf_dir.ml b/src/lib/coda_lib/conf_dir.ml index 3133f19df72..098ec09aa48 100644 --- a/src/lib/coda_lib/conf_dir.ml +++ b/src/lib/coda_lib/conf_dir.ml @@ -107,7 +107,61 @@ let export_logs_to_tar ?basename ~conf_dir = Core.Sys.ls_dir conf_dir |> List.filter ~f:(String.is_substring ~substring:".log") in - let files = "coda.version" :: log_files in + let%bind.Deferred.Let_syntax linux_info = + if String.equal Sys.os_type "Unix" then + match%map.Deferred.Let_syntax + Process.run ~prog:"uname" ~args:["-a"] () + with + | Ok s when String.is_prefix s ~prefix:"Linux" -> + Some s + | _ -> + None + else Deferred.return None + in + let%bind.Deferred.Let_syntax hw_info_opt = + if Option.is_some linux_info then + let open Deferred.Let_syntax in + let linux_hw_progs = ["lscpu"; "lsgpu"; "lsmem"; "lsblk"] in + let%map outputs = + Deferred.List.map linux_hw_progs ~f:(fun prog -> + let header = sprintf "*** Output from '%s' ***\n" prog in + let%bind output = + (* no args, otherwise might not be consistent across Linuxes *) + match%map Process.run_lines ~prog ~args:[] () with + | Ok lines -> + lines + | Error err -> + [sprintf "Error: %s" (Error.to_string_hum err)] + in + return (Option.value_exn linux_info :: header :: output) ) + in + Some (List.concat outputs) + else (* TODO: Mac, other Unixes *) + Deferred.return None + in + let%bind.Deferred.Let_syntax hw_file_opt = + if Option.is_some hw_info_opt then + let open Async in + let hw_info = "hardware.info" in + let hw_info_file = conf_dir ^/ hw_info in + match%map + Monitor.try_with ~extract_exn:true (fun () -> + Writer.with_file ~exclusive:true hw_info_file ~f:(fun writer -> + Deferred.List.map (Option.value_exn hw_info_opt) + ~f:(fun line -> return (Writer.write_line writer line)) ) ) + with + | Ok _units -> + Some hw_info + | Error _exn -> + (* carry on, despite the error *) + None + else Deferred.return None + in + let base_files = "coda.version" :: log_files in + let files = + Option.value_map hw_file_opt ~default:base_files ~f:(fun hw_file -> + hw_file :: base_files ) + in let%map _result = Process.run ~prog:"tar" ~args: From 43a62c8b3396f18a6c36dcd07142a009bfe45d4c Mon Sep 17 00:00:00 2001 From: Paul Steckler Date: Tue, 1 Dec 2020 17:08:59 -0800 Subject: [PATCH 2/2] one uname output --- src/lib/coda_lib/conf_dir.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/coda_lib/conf_dir.ml b/src/lib/coda_lib/conf_dir.ml index 098ec09aa48..3b906c4f0f5 100644 --- a/src/lib/coda_lib/conf_dir.ml +++ b/src/lib/coda_lib/conf_dir.ml @@ -133,9 +133,9 @@ let export_logs_to_tar ?basename ~conf_dir = | Error err -> [sprintf "Error: %s" (Error.to_string_hum err)] in - return (Option.value_exn linux_info :: header :: output) ) + return (header :: output) ) in - Some (List.concat outputs) + Some (Option.value_exn linux_info :: List.concat outputs) else (* TODO: Mac, other Unixes *) Deferred.return None in