Skip to content

Commit 2acdd38

Browse files
paulbissfacebook-github-bot
authored andcommitted
Write jit profile for debugging when not jumpstarting
Summary: When we get a crash on a host that doesn't jumpstart it would still be valuable to be able to extract a JIT profile to reconstruct the crashing translations. This diff adds a new runtime option (Eval.JitSerializeDebugLocation) to indicate where this extra profile should be written, and changes the serializer to also map in any serialized profiles when not in deserializing mode. Reviewed By: jano Differential Revision: D76632659 fbshipit-source-id: 8a70295e999fdadde75b753e1889291eec9bb974
1 parent 9fd16db commit 2acdd38

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

hphp/doc/configs.specification

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,12 @@ The format can be found in hphp/tools/configs/generate_configs.rs
18271827
translations will be logged, and run_key column will be logged with
18281828
the value of this option.
18291829

1830+
- std::string Jit.SerializeDebugLocation = "/tmp/debugprof.jit", paulbiss
1831+
1832+
If jit profiles are disabled write serialized JIT data to disk for use in the
1833+
event of a crash. While crashing HHVM will map this file into memory so that
1834+
it may be retrieved from the core.
1835+
18301836
- bool Jit.ProfileGuardTypes = false, UNKNOWN
18311837
- uint32_t Jit.FilterLease = 1, UNKNOWN
18321838

hphp/runtime/vm/jit/mcgen-translate.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,29 @@ bool serializeProfDataAndLog() {
311311
return serializeOptProfEnabled() && Cfg::Jit::SerializeOptProfRestart;
312312
}
313313

314+
void debugDumpProfDataAndLog() {
315+
auto const serverMode = Cfg::Server::Mode;
316+
317+
if (Cfg::Jit::SerializeDebugLocation.empty()) return;
318+
319+
if (serverMode) {
320+
Logger::Info("retranslateAll: serializing profile data for debugging");
321+
}
322+
323+
std::string errMsg;
324+
VMWorker([&errMsg] () {
325+
errMsg = serializeProfData(Cfg::Jit::SerializeDebugLocation);
326+
}).run();
327+
328+
if (serverMode) {
329+
if (errMsg.empty()) {
330+
Logger::Info("retranslateAll: serializing done");
331+
} else {
332+
Logger::FError("serializeProfData failed with: {}", errMsg);
333+
}
334+
}
335+
}
336+
314337
/*
315338
* Schedule serialization of optimized code's profile to happen in the future.
316339
*/
@@ -410,6 +433,10 @@ void retranslateAll(bool skipSerialize) {
410433
// serialization of optimized code's profile is also enabled.
411434

412435
if (serialize && !skipSerialize && serializeProfDataAndLog()) return;
436+
if (!skipSerialize && !isJitSerializing() && !isJitDeserializing() &&
437+
Cfg::Repo::Authoritative) {
438+
debugDumpProfDataAndLog();
439+
}
413440

414441
// 5) Generate machine code for all the profiled functions.
415442

hphp/runtime/vm/jit/prof-data-serialize.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,9 @@ rds::Ordering::Item read_rds_ordering_item(ProfDataDeserializer& des) {
869869

870870
void write_rds_ordering(ProfDataSerializer& ser) {
871871
rds::Ordering order;
872-
if (Cfg::Eval::ReorderRDS) order = rds::profiledOrdering();
872+
if (Cfg::Eval::ReorderRDS && isJitSerializing()) {
873+
order = rds::profiledOrdering();
874+
}
873875
write_container(ser, order.persistent, write_rds_ordering_item);
874876
write_container(ser, order.local, write_rds_ordering_item);
875877
write_container(ser, order.normal, write_rds_ordering_item);
@@ -2209,6 +2211,10 @@ std::string serializeProfData(const std::string& filename) {
22092211
s_lastMappers = std::move(ser.getMappers());
22102212
}
22112213

2214+
// If we crash we can recover the current TC state using the profile we just
2215+
// serialized so ensure it gets mapped back into the core.
2216+
s_deserializedFile = filename;
2217+
22122218
return "";
22132219
} catch (std::runtime_error& err) {
22142220
return folly::sformat("Failed to serialize profile data: {}", err.what());

0 commit comments

Comments
 (0)