Merge pull request #14292 from Dentomologist/jitregister_fix_isenabled_when_using_vtune_without_perf

JitRegister: Fix IsEnabled when using VTune without perf
This commit is contained in:
JosJuice
2026-01-19 20:52:15 +01:00
committed by GitHub

View File

@@ -34,17 +34,23 @@ static bool s_is_enabled = false;
void Init(const std::string& perf_dir)
{
#ifdef USE_VTUNE
s_is_enabled = true;
#endif
if (!perf_dir.empty() || getenv("PERF_BUILDID_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");
if (s_perf_map_file.Open(filename, "w"))
{
// Disable buffering in order to avoid missing some mappings
// if the event of a crash:
// in the event of a crash:
std::setvbuf(s_perf_map_file.GetHandle(), nullptr, _IONBF, 0);
s_is_enabled = true;
}
}
}
void Shutdown()
{
@@ -75,7 +81,7 @@ void Register(const void* base_address, u32 code_size, const std::string& symbol
#endif
// Linux perf /tmp/perf-$pid.map:
if (!s_perf_map_file.IsOpen())
if (!s_perf_map_file)
return;
const auto entry = fmt::format("{} {:x} {}\n", fmt::ptr(base_address), code_size, symbol_name);