Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dump hardware details for Linux #6903

Merged
merged 3 commits into from
Dec 2, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion src/lib/coda_lib/conf_dir.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 (header :: output) )
in
Some (Option.value_exn linux_info :: 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:
Expand Down