2 * Copyright (c) 2018, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE fn in the "hack" directory of this source tree.
10 type pipe_from_server
= Unix.file_descr
12 let make_pipe_from_server fd
= fd
14 let read_from_server fd
=
16 let (readable
, _
, _
) = Unix.select
[fd
] [] [] 0.0 in
20 Some
(Marshal_tools.from_fd_with_preamble fd
)
22 (* If something went wrong here, the system is likely in broken state
23 * (the server died). We'll keep going so that monitor
24 * can resolve this (by restarting the server / exiting itself *)
25 let stack = Printexc.get_backtrace
() in
26 Hh_logger.exc
stack e
;
29 let pipe_to_monitor_ref = ref None
31 let previous_message = ref None
33 let make_pipe_to_monitor fd
= pipe_to_monitor_ref := Some fd
35 let send_to_monitor (msg
: MonitorRpc.server_to_monitor_message
) =
36 match !pipe_to_monitor_ref with
38 (* This function can be invoked in non-server code paths,
39 * when there is no monitor. *)
42 match (msg
, !previous_message) with
43 | (msg
, Some
previous_message) when msg
= previous_message ->
44 (* Avoid sending the same message repeatedly. *)
47 previous_message := Some msg
;
48 let (_
: int) = Marshal_tools.to_fd_with_preamble fd msg
in
52 let send_progress_to_monitor ?
(include_in_logs
= true) fmt
=
54 if include_in_logs
then Hh_logger.log
"%s" s
;
55 send_to_monitor (MonitorRpc.PROGRESS s
)
59 (* The message will look roughly like this:
60 <operation> <done_count>/<total_count> <unit> <percent done> <extra>*)
61 let make_percentage_progress_message
66 ~
(extra
: string option) : string =
73 let percent = 100.0 *. float_of_int done_count
/. float_of_int total_count
in
84 | Some extra
-> main_message ^
" " ^ extra
85 | None
-> main_message
87 let send_percentage_progress_to_monitor
92 ~
(extra
: string option) : unit =
93 send_progress_to_monitor
94 ~include_in_logs
:false
96 (make_percentage_progress_message