make check-quests parallel
This commit is contained in:
+34
-4
@@ -3670,7 +3670,12 @@ Action a_print_free_supermap(
|
|||||||
Action a_check_quests(
|
Action a_check_quests(
|
||||||
"check-quests", nullptr,
|
"check-quests", nullptr,
|
||||||
+[](phosg::Arguments& args) {
|
+[](phosg::Arguments& args) {
|
||||||
|
size_t num_threads = args.get<size_t>("threads", 0);
|
||||||
|
bool reassemble_scripts = args.get<bool>("reassemble-scripts");
|
||||||
|
bool reassemble_maps = args.get<bool>("reassemble-maps");
|
||||||
|
|
||||||
check_quest_opcode_definitions();
|
check_quest_opcode_definitions();
|
||||||
|
phosg::log_info_f("Opcode definitions OK");
|
||||||
|
|
||||||
auto s = std::make_shared<ServerState>(get_config_filename(args));
|
auto s = std::make_shared<ServerState>(get_config_filename(args));
|
||||||
s->is_debug = true;
|
s->is_debug = true;
|
||||||
@@ -3680,17 +3685,16 @@ Action a_check_quests(
|
|||||||
s->load_maps();
|
s->load_maps();
|
||||||
s->load_quest_index(true);
|
s->load_quest_index(true);
|
||||||
|
|
||||||
bool reassemble_scripts = args.get<bool>("reassemble-scripts");
|
|
||||||
bool reassemble_maps = args.get<bool>("reassemble-maps");
|
|
||||||
uint64_t script_time = 0, map_time = 0;
|
uint64_t script_time = 0, map_time = 0;
|
||||||
if (reassemble_scripts || reassemble_maps) {
|
if (reassemble_scripts || reassemble_maps) {
|
||||||
for (const auto& [_, q] : s->quest_index->quests_by_number) {
|
std::mutex output_lock;
|
||||||
for (const auto& [_, vq] : q->versions) {
|
auto check_vq = [&](const std::shared_ptr<const VersionedQuest>& vq, size_t) -> void {
|
||||||
if (reassemble_maps) {
|
if (reassemble_maps) {
|
||||||
uint64_t start_time = phosg::now();
|
uint64_t start_time = phosg::now();
|
||||||
auto dat = prs_decompress(*vq->dat_contents);
|
auto dat = prs_decompress(*vq->dat_contents);
|
||||||
auto serialized = vq->map_file->serialize();
|
auto serialized = vq->map_file->serialize();
|
||||||
if (dat != serialized) {
|
if (dat != serialized) {
|
||||||
|
std::lock_guard g(output_lock);
|
||||||
phosg::log_info_f("... DISASSEMBLY:");
|
phosg::log_info_f("... DISASSEMBLY:");
|
||||||
phosg::fwritex(stdout, vq->map_file->disassemble(false, vq->meta.version));
|
phosg::fwritex(stdout, vq->map_file->disassemble(false, vq->meta.version));
|
||||||
phosg::log_info_f("... BINDIFF:");
|
phosg::log_info_f("... BINDIFF:");
|
||||||
@@ -3705,6 +3709,7 @@ Action a_check_quests(
|
|||||||
}
|
}
|
||||||
uint64_t end_time = phosg::now();
|
uint64_t end_time = phosg::now();
|
||||||
map_time += (end_time - start_time);
|
map_time += (end_time - start_time);
|
||||||
|
std::lock_guard g(output_lock);
|
||||||
phosg::log_info_f("... {} {} {} ({}) MAP OK ({})",
|
phosg::log_info_f("... {} {} {} ({}) MAP OK ({})",
|
||||||
phosg::name_for_enum(vq->meta.version),
|
phosg::name_for_enum(vq->meta.version),
|
||||||
name_for_language(vq->meta.language),
|
name_for_language(vq->meta.language),
|
||||||
@@ -3767,6 +3772,7 @@ Action a_check_quests(
|
|||||||
assembled.meta.long_description, vq->meta.long_description));
|
assembled.meta.long_description, vq->meta.long_description));
|
||||||
}
|
}
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
|
std::lock_guard g(output_lock);
|
||||||
phosg::log_error_f("================ DISASSEMBLY:");
|
phosg::log_error_f("================ DISASSEMBLY:");
|
||||||
phosg::fwritex(stderr, disassembled);
|
phosg::fwritex(stderr, disassembled);
|
||||||
phosg::log_error_f("================ REASSEMBLY:");
|
phosg::log_error_f("================ REASSEMBLY:");
|
||||||
@@ -3780,6 +3786,7 @@ Action a_check_quests(
|
|||||||
}
|
}
|
||||||
uint64_t end_time = phosg::now();
|
uint64_t end_time = phosg::now();
|
||||||
script_time += (end_time - start_time);
|
script_time += (end_time - start_time);
|
||||||
|
std::lock_guard g(output_lock);
|
||||||
phosg::log_info_f("... {} {} {} ({}) SCRIPT OK ({})",
|
phosg::log_info_f("... {} {} {} ({}) SCRIPT OK ({})",
|
||||||
phosg::name_for_enum(vq->meta.version),
|
phosg::name_for_enum(vq->meta.version),
|
||||||
name_for_language(vq->meta.language),
|
name_for_language(vq->meta.language),
|
||||||
@@ -3787,8 +3794,31 @@ Action a_check_quests(
|
|||||||
vq->meta.name,
|
vq->meta.name,
|
||||||
phosg::format_duration(end_time - start_time));
|
phosg::format_duration(end_time - start_time));
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (num_threads == 1) {
|
||||||
|
for (const auto& [_, q] : s->quest_index->quests_by_number) {
|
||||||
|
for (const auto& [_, vq] : q->versions) {
|
||||||
|
check_vq(vq, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
std::vector<std::shared_ptr<const VersionedQuest>> all_vqs;
|
||||||
|
for (const auto& [_, q] : s->quest_index->quests_by_number) {
|
||||||
|
for (const auto& [_, vq] : q->versions) {
|
||||||
|
all_vqs.emplace_back(vq);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort them in decreasing order of bin file size, so the slowest ones are run first (this packs the work
|
||||||
|
// into the threads' timelines more efficiently)
|
||||||
|
std::sort(all_vqs.begin(), all_vqs.end(), [](const std::shared_ptr<const VersionedQuest>& a, const std::shared_ptr<const VersionedQuest>& b) -> bool {
|
||||||
|
return a->bin_contents->size() > b->bin_contents->size();
|
||||||
|
});
|
||||||
|
|
||||||
|
phosg::parallel_range(all_vqs, check_vq, num_threads);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (script_time > 0) {
|
if (script_time > 0) {
|
||||||
phosg::log_info_f("... SCRIPT CHECKS: {}", phosg::format_duration(script_time));
|
phosg::log_info_f("... SCRIPT CHECKS: {}", phosg::format_duration(script_time));
|
||||||
|
|||||||
Reference in New Issue
Block a user