Skip to content

Commit f0be6d6

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 f0be6d6

File tree

3 files changed

+37
-31
lines changed

3 files changed

+37
-31
lines changed

Sources/SemanticIndex/PreparationTaskDescription.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ public struct PreparationTaskDescription: IndexTaskDescription {
7474
// Only use the last two digits of the preparation ID for the logging scope to avoid creating too many scopes.
7575
// See comment in `withLoggingScope`.
7676
// The last 2 digits should be sufficient to differentiate between multiple concurrently running preparation operations
77-
await withLoggingSubsystemAndScope(
78-
subsystem: "org.swift.sourcekit-lsp.indexing",
79-
scope: "preparation-\(id % 100)"
80-
) {
77+
await withLoggingSubsystemAndScope(subsystem: indexLoggingSubsystem, scope: "preparation-\(id % 100)") {
8178
let targetsToPrepare = await targetsToPrepare.asyncFilter {
8279
await !preparationUpToDateStatus.isUpToDate($0)
8380
}.sorted(by: {
@@ -98,10 +95,13 @@ public struct PreparationTaskDescription: IndexTaskDescription {
9895
let signposter = Logger(subsystem: LoggingScope.subsystem, category: "preparation").makeSignposter()
9996
let signpostID = signposter.makeSignpostID()
10097
let state = signposter.beginInterval("Preparing", id: signpostID, "Preparing \(targetsToPrepareDescription)")
98+
let startDate = Date()
10199
defer {
100+
logger.log(
101+
"Finished preparation in \(Date().timeIntervalSince(startDate) * 1000, privacy: .public)ms: \(targetsToPrepareDescription)"
102+
)
102103
signposter.endInterval("Preparing", state)
103104
}
104-
let startDate = Date()
105105
do {
106106
try await buildSystemManager.prepare(
107107
targets: targetsToPrepare,
@@ -116,9 +116,6 @@ public struct PreparationTaskDescription: IndexTaskDescription {
116116
if !Task.isCancelled {
117117
await preparationUpToDateStatus.markUpToDate(targetsToPrepare, updateOperationStartDate: startDate)
118118
}
119-
logger.log(
120-
"Finished preparation in \(Date().timeIntervalSince(startDate) * 1000, privacy: .public)ms: \(targetsToPrepareDescription)"
121-
)
122119
}
123120
}
124121

Sources/SemanticIndex/SemanticIndexManager.swift

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import LSPLogging
1515
import LanguageServerProtocol
1616
import SKCore
1717

18+
/// The logging subsystem that should be used for all index-related logging.
19+
let indexLoggingSubsystem = "org.swift.sourcekit-lsp.indexing"
20+
1821
/// A wrapper around `QueuedTask` that only allows equality comparison and inspection whether the `QueuedTask` is
1922
/// currently executing.
2023
///
@@ -186,26 +189,35 @@ public final actor SemanticIndexManager {
186189
/// This method is intended to initially update the index of a project after it is opened.
187190
public func scheduleBuildGraphGenerationAndBackgroundIndexAllFiles() async {
188191
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)
192+
await withLoggingSubsystemAndScope(subsystem: indexLoggingSubsystem, scope: "build-graph-generation") {
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+
let startDate = Date()
200+
defer {
201+
logger.log(
202+
"Finished build graph generation in \(Date().timeIntervalSince(startDate) * 1000, privacy: .public)ms"
203+
)
204+
signposter.endInterval("Preparing", state)
206205
}
207-
await scheduleBackgroundIndex(files: filesToIndex)
208-
generateBuildGraphTask = nil
206+
await testHooks.buildGraphGenerationDidStart?()
207+
await orLog("Generating build graph") { try await self.buildSystemManager.generateBuildGraph() }
208+
await testHooks.buildGraphGenerationDidFinish?()
209+
let index = index.checked(for: .modifiedFiles)
210+
let filesToIndex = await self.buildSystemManager.sourceFiles().lazy.map(\.uri)
211+
.filter { uri in
212+
guard let url = uri.fileURL else {
213+
// The URI is not a file, so there's nothing we can index.
214+
return false
215+
}
216+
return !index.hasUpToDateUnit(for: url)
217+
}
218+
await scheduleBackgroundIndex(files: filesToIndex)
219+
generateBuildGraphTask = nil
220+
}
209221
}
210222
indexStatusDidChange()
211223
}

Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,7 @@ public struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
134134
// Only use the last two digits of the indexing ID for the logging scope to avoid creating too many scopes.
135135
// See comment in `withLoggingScope`.
136136
// The last 2 digits should be sufficient to differentiate between multiple concurrently running indexing operation.
137-
await withLoggingSubsystemAndScope(
138-
subsystem: "org.swift.sourcekit-lsp.indexing",
139-
scope: "update-indexstore-\(id % 100)"
140-
) {
137+
await withLoggingSubsystemAndScope(subsystem: indexLoggingSubsystem, scope: "update-indexstore-\(id % 100)") {
141138
let startDate = Date()
142139

143140
await testHooks.updateIndexStoreTaskDidStart?(self)

0 commit comments

Comments
 (0)