Skip to content

Commit fbf6c09

Browse files
ricklavoiemeta-codesync[bot]
authored andcommitted
Add support for index dumps in HHBBC distributed mode
Summary: Add support for dumping the index and bytecode (using TRACE=hhbbc_trace:2) in distributed mode. Also remove support for stats collection, as it's never used and needs extra work to support in distributed mode. Reviewed By: sinancepel Differential Revision: D89755530 fbshipit-source-id: 88258f90a3a2bb8639e57b63ec938936dc1504bc
1 parent 6efee0e commit fbf6c09

6 files changed

Lines changed: 145 additions & 646 deletions

File tree

hphp/hhbbc/debug.cpp

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ namespace {
4444
const StaticString s_invoke("__invoke");
4545

4646
template<class Operation>
47-
void with_file(fs::path dir, const php::Unit& u, Operation op) {
47+
void with_file(fs::path dir, const std::string& unitPath, Operation op) {
4848
// Paths for systemlib units start with /, which gets interpreted as
4949
// an absolute path, so strip it.
50-
auto filename = u.filename->data();
50+
auto filename = unitPath.data();
5151
if (filename[0] == '/') ++filename;
5252

5353
auto const file = dir / fs::path(filename);
@@ -196,8 +196,6 @@ void dump_func_state(std::ostream& out,
196196
std::string debug_dump_to() {
197197
if (!Trace::moduleEnabledRelease(Trace::hhbbc_dump, 1)) return "";
198198

199-
trace_time tracer("debug dump");
200-
201199
auto dir = [&]{
202200
if (auto const dumpDir = getenv("HHBBC_DUMP_DIR")) {
203201
return fs::path(dumpDir);
@@ -218,69 +216,79 @@ std::string debug_dump_to() {
218216
return dir.string();
219217
}
220218

221-
void dump_representation(const std::string& dir,
222-
const IIndex& index,
223-
const php::Unit& unit) {
219+
void write_representation_dump(const std::string& dir,
220+
const std::string& unitPath,
221+
const std::string& dump) {
224222
auto const rep_dir = fs::path{dir} / "representation";
225-
with_file(rep_dir, unit, [&] (std::ostream& out) {
226-
out << show(unit, index);
227-
});
223+
with_file(rep_dir, unitPath, [&] (std::ostream& out) { out << dump; });
224+
}
225+
226+
void write_index_dump(const std::string& dir,
227+
const std::string& unitPath,
228+
const std::string& dump) {
229+
auto const rep_dir = fs::path{dir} / "index";
230+
with_file(rep_dir, unitPath, [&] (std::ostream& out) { out << dump; });
231+
}
232+
233+
std::string dump_representation(const IIndex& index,
234+
const php::Unit& unit) {
235+
ContextPusher _{index, Context{ unit.filename, nullptr, nullptr }};
236+
return show(unit, index);
228237
}
229238

230-
void dump_index(const std::string& dir,
231-
const IIndex& index,
232-
const php::Unit& unit) {
239+
std::string dump_index(const IIndex& index, const php::Unit& unit) {
233240
if (!*unit.filename->data()) {
234241
// The native systemlibs: for now just skip.
235-
return;
242+
return "";
236243
}
237244

238-
auto ind_dir = fs::path{dir} / "index";
245+
ContextPusher _{index, Context{ unit.filename, nullptr, nullptr }};
239246

240-
with_file(ind_dir, unit, [&] (std::ostream& out) {
241-
std::vector<const php::Class*> classes;
242-
index.for_each_unit_class(
243-
unit,
244-
[&] (const php::Class& c) { classes.emplace_back(&c); }
245-
);
246-
std::sort(
247-
begin(classes), end(classes),
248-
[] (const php::Class* a, const php::Class* b) {
249-
return string_data_lt_type{}(a->name, b->name);
250-
}
251-
);
252-
253-
for (auto const c : classes) {
254-
dump_class_state(out, index, c);
255-
256-
std::vector<const php::Func*> funcs;
257-
funcs.reserve(c->methods.size());
258-
for (auto const& m : c->methods) {
259-
if (!m) continue;
260-
funcs.emplace_back(m.get());
261-
}
262-
std::sort(
263-
begin(funcs), end(funcs),
264-
[] (const php::Func* a, const php::Func* b) {
265-
return string_data_lt{}(a->name, b->name);
266-
}
267-
);
268-
for (auto const f : funcs) dump_func_state(out, index, *f);
247+
std::vector<const php::Class*> classes;
248+
index.for_each_unit_class(
249+
unit,
250+
[&] (const php::Class& c) { classes.emplace_back(&c); }
251+
);
252+
std::sort(
253+
begin(classes), end(classes),
254+
[] (const php::Class* a, const php::Class* b) {
255+
return string_data_lt_type{}(a->name, b->name);
269256
}
257+
);
258+
259+
std::ostringstream out;
260+
for (auto const c : classes) {
261+
dump_class_state(out, index, c);
270262

271263
std::vector<const php::Func*> funcs;
272-
index.for_each_unit_func(
273-
unit,
274-
[&] (const php::Func& f) { funcs.emplace_back(&f); }
275-
);
264+
funcs.reserve(c->methods.size());
265+
for (auto const& m : c->methods) {
266+
if (!m) continue;
267+
funcs.emplace_back(m.get());
268+
}
276269
std::sort(
277270
begin(funcs), end(funcs),
278271
[] (const php::Func* a, const php::Func* b) {
279272
return string_data_lt{}(a->name, b->name);
280273
}
281274
);
282275
for (auto const f : funcs) dump_func_state(out, index, *f);
283-
});
276+
}
277+
278+
std::vector<const php::Func*> funcs;
279+
index.for_each_unit_func(
280+
unit,
281+
[&] (const php::Func& f) { funcs.emplace_back(&f); }
282+
);
283+
std::sort(
284+
begin(funcs), end(funcs),
285+
[] (const php::Func* a, const php::Func* b) {
286+
return string_data_lt{}(a->name, b->name);
287+
}
288+
);
289+
for (auto const f : funcs) dump_func_state(out, index, *f);
290+
291+
return out.str();
284292
}
285293

286294
//////////////////////////////////////////////////////////////////////

hphp/hhbbc/debug.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace HPHP::HHBBC {
2626

2727
//////////////////////////////////////////////////////////////////////
2828

29+
struct IIndex;
2930
struct ParsedUnit;
3031

3132
//////////////////////////////////////////////////////////////////////
@@ -35,10 +36,16 @@ struct ParsedUnit;
3536
* temporary directory as readable text.
3637
*/
3738
std::string debug_dump_to();
38-
void dump_representation(const std::string& dir,
39-
const IIndex&,
40-
const php::Unit&);
41-
void dump_index(const std::string&, const IIndex&, const php::Unit&);
39+
40+
std::string dump_representation(const IIndex&, const php::Unit&);
41+
std::string dump_index(const IIndex&, const php::Unit&);
42+
43+
void write_representation_dump(const std::string& dir,
44+
const std::string& unitPath,
45+
const std::string& dump);
46+
void write_index_dump(const std::string& dir,
47+
const std::string& unitPath,
48+
const std::string& dump);
4249

4350
/*
4451
* Utilities for printing the state of the program after various

hphp/hhbbc/index.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,8 +2283,9 @@ struct AnalysisInput {
22832283
FSStringToOneT<AnalysisDeps> funcDeps;
22842284
SStringToOneT<AnalysisDeps> unitDeps;
22852285

2286-
// Entities that are starting points for this analysis (have toSchedule=true).
2287-
// These are the entities with changed information that triggered scheduling.
2286+
// Entities that are starting points for this analysis (have
2287+
// toSchedule=true). These are the entities with changed
2288+
// information that triggered scheduling.
22882289
TSStringSet startCls;
22892290
FSStringSet startFunc;
22902291
SStringSet startUnit;
@@ -2295,6 +2296,11 @@ struct AnalysisInput {
22952296
// Index of this bucket in the overall scheduling round
22962297
uint32_t bucketIdx;
22972298

2299+
// Whether to dump the index and/or representation for units
2300+
// during final-pass.
2301+
bool dumpIndex{false};
2302+
bool dumpRep{false};
2303+
22982304
template <typename SerDe> void serde(SerDe& sd) {
22992305
ScopedStringDataIndexer _;
23002306
sd(bundleNames)
@@ -2309,6 +2315,8 @@ struct AnalysisInput {
23092315
(startUnit, string_data_lt{})
23102316
(ifaceSlotMap, string_data_lt_type{})
23112317
(bucketIdx)
2318+
(dumpIndex)
2319+
(dumpRep)
23122320
;
23132321
}
23142322
};

0 commit comments

Comments
 (0)