Skip to content

Commit

Permalink
debug: Tweak logging for unseen headers (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
varungandhi-src authored Apr 17, 2023
1 parent d2d282d commit 7916de6
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions indexer/Driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,10 @@ class Driver {
fullIndex.SerializeToOstream(&outputStream);
}

bool isMultiplyIndexedApproximate(const std::string &relativePath,
AbsolutePathRef shardPath) const {
bool
isMultiplyIndexedApproximate(const std::string &relativePath,
AbsolutePathRef shardPath,
absl::flat_hash_set<uint32_t> &badJobIds) const {
auto multiplyIndexed = this->planner.isMultiplyIndexed(
RootRelativePathRef{relativePath, RootKind::Project});
bool isMultiplyIndexed;
Expand All @@ -719,15 +721,7 @@ class Driver {
if (auto optFileName = shardPath.fileName()) {
if (auto optJobId = ShardPaths::tryParseJobId(*optFileName)) {
auto jobId = optJobId.value();
spdlog::info("the unknown header was encountered when processing "
"the compilation command at index {} in the "
"compilation database",
jobId);
spdlog::info(
"it may be possible to reproduce this issue by subsetting the "
"compilation database using `jq '.[{}:{}]` {} > bad.json` and "
"re-running `scip-clang --compdb-path=bad.json <flags...>`",
jobId, jobId + 1, this->options.compdbPath.asStringRef());
badJobIds.insert(jobId);
}
}
// Be conservative here
Expand Down Expand Up @@ -787,6 +781,8 @@ class Driver {
return true;
};

absl::flat_hash_set<uint32_t> badJobIds{};

scip::IndexBuilder builder{fullIndex};
// TODO: Measure how much time this is taking and parallelize if too slow.
for (auto &paths : this->shardPaths) {
Expand All @@ -796,7 +792,7 @@ class Driver {
}
for (auto &doc : *indexShard.mutable_documents()) {
bool isMultiplyIndexed = this->isMultiplyIndexedApproximate(
doc.relative_path(), paths.docsAndExternals.asRef());
doc.relative_path(), paths.docsAndExternals.asRef(), badJobIds);
builder.addDocument(std::move(doc), isMultiplyIndexed);
}
// See NOTE(ref: precondition-deterministic-ext-symbol-docs); in
Expand All @@ -808,6 +804,21 @@ class Driver {
}
}

if (!badJobIds.empty()) {
std::vector<uint32_t> badJobIdsSorted{badJobIds.begin(), badJobIds.end()};
absl::c_sort(badJobIdsSorted);
spdlog::info("previously unseen headers were encountered when processing"
" the compilation commands at indexes [{}] in the "
"compilation database",
fmt::join(badJobIdsSorted, ","));
spdlog::info(
"it may be possible to reproduce this issue by subsetting the "
"compilation database using `jq '[.[{}]]` {} > bad.json` and "
"re-running `scip-clang --compdb-path=bad.json <flags...>`",
fmt::join(badJobIdsSorted, ","),
this->options.compdbPath.asStringRef());
}

auto symbolToInfoMap = builder.populateSymbolToInfoMap();

for (auto &paths : this->shardPaths) {
Expand Down

0 comments on commit 7916de6

Please sign in to comment.