Skip to content

Commit 6c74084

Browse files
committed
Log when the build graph starts being generated and when it finishes
The signposts aren’t easily visible in the log (you need to add `--signpost` to `log show`) and don’t get logged on non-Darwin platforms at all. Add logging for it.
1 parent 8bfd02d commit 6c74084

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

Sources/SemanticIndex/SemanticIndexManager.swift

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -186,26 +186,38 @@ public final actor SemanticIndexManager {
186186
/// This method is intended to initially update the index of a project after it is opened.
187187
public func scheduleBuildGraphGenerationAndBackgroundIndexAllFiles() async {
188188
generateBuildGraphTask = Task(priority: .low) {
189-
let signposter = Logger(subsystem: LoggingScope.subsystem, category: "preparation").makeSignposter()
190-
let signpostID = signposter.makeSignpostID()
191-
let state = signposter.beginInterval("Preparing", id: signpostID, "Generating build graph")
192-
defer {
193-
signposter.endInterval("Preparing", state)
194-
}
195-
await testHooks.buildGraphGenerationDidStart?()
196-
await orLog("Generating build graph") { try await self.buildSystemManager.generateBuildGraph() }
197-
await testHooks.buildGraphGenerationDidFinish?()
198-
let index = index.checked(for: .modifiedFiles)
199-
let filesToIndex = await self.buildSystemManager.sourceFiles().lazy.map(\.uri)
200-
.filter { uri in
201-
guard let url = uri.fileURL else {
202-
// The URI is not a file, so there's nothing we can index.
203-
return false
204-
}
205-
return !index.hasUpToDateUnit(for: url)
189+
await withLoggingSubsystemAndScope(
190+
subsystem: "org.swift.sourcekit-lsp.indexing",
191+
scope: "build-graph-generation"
192+
) {
193+
logger.log(
194+
"Starting build graph generation with priority \(Task.currentPriority.rawValue, privacy: .public)"
195+
)
196+
let signposter = logger.makeSignposter()
197+
let signpostID = signposter.makeSignpostID()
198+
let state = signposter.beginInterval("Preparing", id: signpostID, "Generating build graph")
199+
defer {
200+
signposter.endInterval("Preparing", state)
206201
}
207-
await scheduleBackgroundIndex(files: filesToIndex)
208-
generateBuildGraphTask = nil
202+
await testHooks.buildGraphGenerationDidStart?()
203+
let startDate = Date()
204+
await orLog("Generating build graph") { try await self.buildSystemManager.generateBuildGraph() }
205+
await testHooks.buildGraphGenerationDidFinish?()
206+
let index = index.checked(for: .modifiedFiles)
207+
let filesToIndex = await self.buildSystemManager.sourceFiles().lazy.map(\.uri)
208+
.filter { uri in
209+
guard let url = uri.fileURL else {
210+
// The URI is not a file, so there's nothing we can index.
211+
return false
212+
}
213+
return !index.hasUpToDateUnit(for: url)
214+
}
215+
await scheduleBackgroundIndex(files: filesToIndex)
216+
logger.log(
217+
"Finished build graph generation in \(Date().timeIntervalSince(startDate) * 1000, privacy: .public)ms"
218+
)
219+
generateBuildGraphTask = nil
220+
}
209221
}
210222
indexStatusDidChange()
211223
}

0 commit comments

Comments
 (0)