Skip to content

Commit 48387ee

Browse files
committed
[Dependency Scanning] Keep track of how many filesystem module lookups the dependency scanner performs on a given scan
1 parent 25d32fc commit 48387ee

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

include/swift/AST/DiagnosticsCommon.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ WARNING(warn_scanner_deserialize_failed, none,
218218
REMARK(remark_reuse_cache, none,
219219
"Re-using serialized module scanning dependency cache from: '%0'.", (StringRef))
220220

221+
REMARK(remark_scanner_uncached_lookups, none,
222+
"Module Dependency Scanner queries executed: '%0'.", (unsigned))
223+
221224
REMARK(remark_save_cache, none,
222225
"Serializing module scanning dependency cache to: '%0'.", (StringRef))
223226

include/swift/DependencyScan/ModuleDependencyScanner.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class ModuleDependencyScanner {
9595
getNamedSwiftModuleDependencyInfo(StringRef moduleName,
9696
ModuleDependenciesCache &cache);
9797

98+
/// How many filesystem lookups were performed by the scanner
99+
unsigned getNumLookups() { return NumLookups; }
100+
98101
private:
99102
/// Main routine that computes imported module dependency transitive
100103
/// closure for the given module.
@@ -166,6 +169,8 @@ class ModuleDependencyScanner {
166169
llvm::StdThreadPool ScanningThreadPool;
167170
/// Protect worker access.
168171
std::mutex WorkersLock;
172+
/// Count of filesystem queries performed
173+
std::atomic<unsigned> NumLookups = 0;
169174
};
170175

171176
} // namespace swift

lib/DependencyScan/ModuleDependencyCacheSerialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,6 +1783,7 @@ void ModuleDependenciesCacheSerializer::collectStringsAndArrays(
17831783
addIdentifier(swiftTextDeps->textualModuleDetails
17841784
.CASBridgingHeaderIncludeTreeRootID);
17851785
addIdentifier(swiftTextDeps->moduleCacheKey);
1786+
addIdentifier(swiftTextDeps->userModuleVersion);
17861787
break;
17871788
}
17881789
case swift::ModuleDependencyKind::SwiftBinary: {

lib/DependencyScan/ModuleDependencyScanner.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ ModuleDependencyScanningWorker::scanFilesystemForClangModuleDependency(
248248
template <typename Function, typename... Args>
249249
auto ModuleDependencyScanner::withDependencyScanningWorker(Function &&F,
250250
Args &&...ArgList) {
251+
NumLookups++;
251252
auto getWorker = [this]() -> std::unique_ptr<ModuleDependencyScanningWorker> {
252253
std::lock_guard<std::mutex> guard(WorkersLock);
253254
// If we have run out of workers, something has gone wrong as we must never

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,17 +1529,12 @@ swift::dependencies::performModuleScan(
15291529

15301530
// Identify imports of the main module and add an entry for it
15311531
// to the dependency graph.
1532-
auto mainModuleDepInfo =
1533-
scanner.getMainModuleDependencyInfo(instance.getMainModule());
15341532
auto mainModuleName = instance.getMainModule()->getNameStr();
15351533
auto mainModuleID = ModuleDependencyID{mainModuleName.str(),
15361534
ModuleDependencyKind::SwiftSource};
1537-
// We may be re-using an instance of the cache which already contains
1538-
// an entry for this module.
1539-
if (cache.findDependency(mainModuleID))
1540-
cache.updateDependency(mainModuleID, std::move(*mainModuleDepInfo));
1541-
else
1542-
cache.recordDependency(mainModuleName, std::move(*mainModuleDepInfo));
1535+
if (!cache.hasDependency(mainModuleID))
1536+
cache.recordDependency(mainModuleName,
1537+
*scanner.getMainModuleDependencyInfo(instance.getMainModule()));
15431538

15441539
// Perform the full module scan starting at the main module.
15451540
auto allModules = scanner.performDependencyScan(mainModuleID, cache);
@@ -1552,6 +1547,10 @@ swift::dependencies::performModuleScan(
15521547
topologicallySortedModuleList);
15531548
resolveImplicitLinkLibraries(instance, cache);
15541549
updateDependencyTracker(instance, cache, allModules);
1550+
1551+
if (instance.getInvocation().getFrontendOptions().EmitDependencyScannerCacheRemarks)
1552+
instance.getASTContext().Diags.diagnose(SourceLoc(), diag::remark_scanner_uncached_lookups, scanner.getNumLookups());
1553+
15551554
return generateFullDependencyGraph(instance, diagnosticCollector, cache,
15561555
topologicallySortedModuleList);
15571556
}

0 commit comments

Comments
 (0)