Skip to content

Commit d47bce1

Browse files
committed
Add signposts for background preparation and indexing
This allows nice visualization of the indexing progress in Instruments.
1 parent 44acd0d commit d47bce1

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
@@ -69,7 +69,10 @@ public struct PreparationTaskDescription: IndexTaskDescription {
6969
// Only use the last two digits of the preparation ID for the logging scope to avoid creating too many scopes.
7070
// See comment in `withLoggingScope`.
7171
// The last 2 digits should be sufficient to differentiate between multiple concurrently running preparation operations
72-
await withLoggingScope("preparation-\(id % 100)") {
72+
await withLoggingSubsystemAndScope(
73+
subsystem: "org.swift.sourcekit-lsp.indexing",
74+
scope: "preparation-\(id % 100)"
75+
) {
7376
await testHooks.preparationTaskDidStart?(self)
7477
let targetsToPrepare = await targetsToPrepare.asyncFilter {
7578
await !preparationUpToDateStatus.isUpToDate($0)
@@ -87,6 +90,12 @@ public struct PreparationTaskDescription: IndexTaskDescription {
8790
logger.log(
8891
"Starting preparation with priority \(Task.currentPriority.rawValue, privacy: .public): \(targetsToPrepareDescription)"
8992
)
93+
let signposter = Logger(subsystem: LoggingScope.subsystem, category: "preparation").makeSignposter()
94+
let signpostID = signposter.makeSignpostID()
95+
let state = signposter.beginInterval("Preparing", id: signpostID, "Preparing \(targetsToPrepareDescription)")
96+
defer {
97+
signposter.endInterval("Preparing", state)
98+
}
9099
let startDate = Date()
91100
do {
92101
try await buildSystemManager.prepare(targets: targetsToPrepare)

Sources/SemanticIndex/SemanticIndexManager.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ public final actor SemanticIndexManager {
178178
/// This method is intended to initially update the index of a project after it is opened.
179179
public func scheduleBuildGraphGenerationAndBackgroundIndexAllFiles() async {
180180
generateBuildGraphTask = Task(priority: .low) {
181+
let signposter = Logger(subsystem: LoggingScope.subsystem, category: "preparation").makeSignposter()
182+
let signpostID = signposter.makeSignpostID()
183+
let state = signposter.beginInterval("Preparing", id: signpostID, "Generating build graph")
184+
defer {
185+
signposter.endInterval("Preparing", state)
186+
}
181187
await orLog("Generating build graph") { try await self.buildSystemManager.generateBuildGraph() }
182188
let index = index.checked(for: .modifiedFiles)
183189
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
@@ -304,6 +304,16 @@ public struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
304304
if Task.isCancelled {
305305
return
306306
}
307+
let signposter = Logger(subsystem: LoggingScope.subsystem, category: "indexing").makeSignposter()
308+
let signpostID = signposter.makeSignpostID()
309+
let state = signposter.beginInterval(
310+
"Indexing",
311+
id: signpostID,
312+
"Indexing \(indexFile.fileURL?.lastPathComponent ?? indexFile.pseudoPath)"
313+
)
314+
defer {
315+
signposter.endInterval("Indexing", state)
316+
}
307317
let process = try Process.launch(
308318
arguments: processArguments,
309319
workingDirectory: workingDirectory

0 commit comments

Comments
 (0)