Skip to content

Commit 8263793

Browse files
committed
Add signposts for background preparation and indexing
This allows nice visualization of the indexing progress in Instruments.
1 parent 814f3c5 commit 8263793

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

Sources/LSPLogging/NonDarwinLogging.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,5 +394,6 @@ public struct NonDarwinSignposter: Sendable {
394394

395395
public func emitEvent(_ name: StaticString, id: NonDarwinSignpostID, _ message: NonDarwinLogMessage = "") {}
396396

397-
public func endInterval(_ name: StaticString, _ state: NonDarwinSignpostIntervalState, _ message: StaticString) {}
397+
public func endInterval(_ name: StaticString, _ state: NonDarwinSignpostIntervalState, _ message: StaticString = "") {
398+
}
398399
}

Sources/SemanticIndex/PreparationTaskDescription.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ 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 withLoggingScope("preparation-\(id % 100)") {
77+
await withLoggingSubsystemAndScope(
78+
subsystem: "org.swift.sourcekit-lsp.indexing",
79+
scope: "preparation-\(id % 100)"
80+
) {
7881
await testHooks.preparationTaskDidStart?(self)
7982
let targetsToPrepare = await targetsToPrepare.asyncFilter {
8083
await !preparationUpToDateStatus.isUpToDate($0)
@@ -92,6 +95,12 @@ public struct PreparationTaskDescription: IndexTaskDescription {
9295
logger.log(
9396
"Starting preparation with priority \(Task.currentPriority.rawValue, privacy: .public): \(targetsToPrepareDescription)"
9497
)
98+
let signposter = Logger(subsystem: LoggingScope.subsystem, category: "preparation").makeSignposter()
99+
let signpostID = signposter.makeSignpostID()
100+
let state = signposter.beginInterval("Preparing", id: signpostID, "Preparing \(targetsToPrepareDescription)")
101+
defer {
102+
signposter.endInterval("Preparing", state)
103+
}
95104
let startDate = Date()
96105
do {
97106
try await buildSystemManager.prepare(

Sources/SemanticIndex/SemanticIndexManager.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,12 @@ 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+
}
189195
await orLog("Generating build graph") { try await self.buildSystemManager.generateBuildGraph() }
190196
let index = index.checked(for: .modifiedFiles)
191197
let filesToIndex = await self.buildSystemManager.sourceFiles().lazy.map(\.uri)

Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,16 @@ public struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
310310
return
311311
}
312312
let start = ContinuousClock.now
313+
let signposter = Logger(subsystem: LoggingScope.subsystem, category: "indexing").makeSignposter()
314+
let signpostID = signposter.makeSignpostID()
315+
let state = signposter.beginInterval(
316+
"Indexing",
317+
id: signpostID,
318+
"Indexing \(indexFile.fileURL?.lastPathComponent ?? indexFile.pseudoPath)"
319+
)
320+
defer {
321+
signposter.endInterval("Indexing", state)
322+
}
313323
let process = try Process.launch(
314324
arguments: processArguments,
315325
workingDirectory: workingDirectory

0 commit comments

Comments
 (0)