fix(cli): detect the core count on systems without /proc/cpuinfo
The default job limit read /proc/cpuinfo and silently fell back to four anywhere that file is absent, so macOS and the BSDs ran at a fraction of the available parallelism. Falls back to getconf _NPROCESSORS_ONLN before the constant.
This commit is contained in:
1 file changed
+22
-8
+22
-8
@@ -34,15 +34,29 @@ let usage =
|
|||||||
" --no-color plain output";
|
" --no-color plain output";
|
||||||
]
|
]
|
||||||
|
|
||||||
let cores () =
|
let cores_from_cpuinfo () =
|
||||||
match Fs.read "/proc/cpuinfo" with
|
match Fs.read "/proc/cpuinfo" with
|
||||||
| exception Sys_error _ -> 4
|
| exception Sys_error _ -> None
|
||||||
| s ->
|
| s -> (
|
||||||
max 1
|
match
|
||||||
(List.length
|
List.length
|
||||||
(List.filter
|
(List.filter
|
||||||
(fun l -> String.length l >= 9 && String.sub l 0 9 = "processor")
|
(fun l -> String.length l >= 9 && String.sub l 0 9 = "processor")
|
||||||
(String.split_on_char '\n' s)))
|
(String.split_on_char '\n' s))
|
||||||
|
with
|
||||||
|
| 0 -> None
|
||||||
|
| n -> Some n)
|
||||||
|
|
||||||
|
let cores_from_getconf () =
|
||||||
|
match Exec.capture [| "getconf"; "_NPROCESSORS_ONLN" |] with
|
||||||
|
| 0, out -> int_of_string_opt (String.trim out)
|
||||||
|
| _ -> None
|
||||||
|
| exception _ -> None
|
||||||
|
|
||||||
|
let cores () =
|
||||||
|
match cores_from_cpuinfo () with
|
||||||
|
| Some n -> n
|
||||||
|
| None -> ( match cores_from_getconf () with Some n when n > 0 -> n | _ -> 4)
|
||||||
|
|
||||||
let duration s = if s >= 1.0 then Printf.sprintf "%.2f s" s else Printf.sprintf "%.0f ms" (s *. 1000.0)
|
let duration s = if s >= 1.0 then Printf.sprintf "%.2f s" s else Printf.sprintf "%.0f ms" (s *. 1000.0)
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user