Skip to content

Commit 226dcd2

Browse files
mariusaemeta-codesync[bot]
authored andcommitted
bootstrap: print bootstrap debugs to stderr by default (#1372)
Summary: Pull Request resolved: #1372 This is very useful to have. Let's keep it until we feel we don't have the need anymore. Also log it to INFO. ghstack-source-id: 313885567 Reviewed By: shayne-fletcher Differential Revision: D83529217 fbshipit-source-id: 8afde3915afba060571e6734ca46e11bf0feea9e
1 parent ca51ac0 commit 226dcd2

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

hyperactor_mesh/src/bootstrap.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,13 @@ impl Bootstrap {
277277
if Debug::is_active() {
278278
let mut buf = Vec::new();
279279
writeln!(&mut buf, "bootstrapping {}:", std::process::id()).unwrap();
280+
#[cfg(unix)]
281+
writeln!(
282+
&mut buf,
283+
"\tparent pid: {}",
284+
std::os::unix::process::parent_id()
285+
)
286+
.unwrap();
280287
writeln!(
281288
&mut buf,
282289
"\tconfig: {}",
@@ -296,6 +303,11 @@ impl Bootstrap {
296303
writeln!(&mut buf, "\t\t{}={}", key, val).unwrap();
297304
}
298305
let _ = Debug.write(&buf);
306+
if let Ok(s) = std::str::from_utf8(&buf) {
307+
tracing::info!("{}", s);
308+
} else {
309+
tracing::info!("{:?}", buf);
310+
}
299311
}
300312

301313
match self {
@@ -1938,22 +1950,38 @@ fn debug_sink() -> &'static Mutex<DebugSink> {
19381950
})
19391951
}
19401952

1953+
/// If true, send `Debug` messages to stderr.
1954+
const DEBUG_TO_STDERR: bool = true;
1955+
19411956
/// A bootstrap specific debug writer. If the file /tmp/monarch-bootstrap-debug.log
19421957
/// exists, then the writer's destination is that file; otherwise it discards all writes.
19431958
struct Debug;
19441959

19451960
impl Debug {
19461961
fn is_active() -> bool {
1947-
debug_sink().lock().unwrap().is_file()
1962+
DEBUG_TO_STDERR || debug_sink().lock().unwrap().is_file()
19481963
}
19491964
}
19501965

19511966
impl Write for Debug {
19521967
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
1953-
debug_sink().lock().unwrap().write(buf)
1968+
let res = debug_sink().lock().unwrap().write(buf);
1969+
if DEBUG_TO_STDERR {
1970+
let n = match res {
1971+
Ok(n) => n,
1972+
Err(_) => buf.len(),
1973+
};
1974+
let _ = io::stderr().write_all(&buf[..n]);
1975+
}
1976+
1977+
res
19541978
}
19551979
fn flush(&mut self) -> io::Result<()> {
1956-
debug_sink().lock().unwrap().flush()
1980+
let res = debug_sink().lock().unwrap().flush();
1981+
if DEBUG_TO_STDERR {
1982+
let _ = io::stderr().flush();
1983+
}
1984+
res
19571985
}
19581986
}
19591987

0 commit comments

Comments
 (0)