JitRegister: Check Open return code

If the call to `Open` a perf map fails don't set `s_is_enabled` (though
it could already be true if you're also using VTUNE) and don't call
`std::setvbuf` with a null stream.

Also fix a typo in a comment (`if` -> `in`)
This commit is contained in:
Dentomologist
2026-01-18 14:36:51 -08:00
parent 7490dea278
commit f4b88af71e

View File

@@ -42,11 +42,13 @@ void Init(const std::string& perf_dir)
{
const std::string dir = perf_dir.empty() ? "/tmp" : perf_dir;
const std::string filename = fmt::format("{}/perf-{}.map", dir, getpid());
s_perf_map_file.Open(filename, "w");
// Disable buffering in order to avoid missing some mappings
// if the event of a crash:
std::setvbuf(s_perf_map_file.GetHandle(), nullptr, _IONBF, 0);
s_is_enabled = true;
if (s_perf_map_file.Open(filename, "w"))
{
// Disable buffering in order to avoid missing some mappings
// in the event of a crash:
std::setvbuf(s_perf_map_file.GetHandle(), nullptr, _IONBF, 0);
s_is_enabled = true;
}
}
}