Skip to content

Add signposts for background preparation and indexing #1327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/LSPLogging/NonDarwinLogging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -394,5 +394,6 @@ public struct NonDarwinSignposter: Sendable {

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

public func endInterval(_ name: StaticString, _ state: NonDarwinSignpostIntervalState, _ message: StaticString) {}
public func endInterval(_ name: StaticString, _ state: NonDarwinSignpostIntervalState, _ message: StaticString = "") {
}
}
11 changes: 10 additions & 1 deletion Sources/SemanticIndex/PreparationTaskDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ public struct PreparationTaskDescription: IndexTaskDescription {
// Only use the last two digits of the preparation ID for the logging scope to avoid creating too many scopes.
// See comment in `withLoggingScope`.
// The last 2 digits should be sufficient to differentiate between multiple concurrently running preparation operations
await withLoggingScope("preparation-\(id % 100)") {
await withLoggingSubsystemAndScope(
subsystem: "org.swift.sourcekit-lsp.indexing",
scope: "preparation-\(id % 100)"
) {
await testHooks.preparationTaskDidStart?(self)
let targetsToPrepare = await targetsToPrepare.asyncFilter {
await !preparationUpToDateStatus.isUpToDate($0)
Expand All @@ -92,6 +95,12 @@ public struct PreparationTaskDescription: IndexTaskDescription {
logger.log(
"Starting preparation with priority \(Task.currentPriority.rawValue, privacy: .public): \(targetsToPrepareDescription)"
)
let signposter = Logger(subsystem: LoggingScope.subsystem, category: "preparation").makeSignposter()
let signpostID = signposter.makeSignpostID()
let state = signposter.beginInterval("Preparing", id: signpostID, "Preparing \(targetsToPrepareDescription)")
defer {
signposter.endInterval("Preparing", state)
}
let startDate = Date()
do {
try await buildSystemManager.prepare(
Expand Down
6 changes: 6 additions & 0 deletions Sources/SemanticIndex/SemanticIndexManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ public final actor SemanticIndexManager {
/// This method is intended to initially update the index of a project after it is opened.
public func scheduleBuildGraphGenerationAndBackgroundIndexAllFiles() async {
generateBuildGraphTask = Task(priority: .low) {
let signposter = Logger(subsystem: LoggingScope.subsystem, category: "preparation").makeSignposter()
let signpostID = signposter.makeSignpostID()
let state = signposter.beginInterval("Preparing", id: signpostID, "Generating build graph")
defer {
signposter.endInterval("Preparing", state)
}
await orLog("Generating build graph") { try await self.buildSystemManager.generateBuildGraph() }
let index = index.checked(for: .modifiedFiles)
let filesToIndex = await self.buildSystemManager.sourceFiles().lazy.map(\.uri)
Expand Down
10 changes: 10 additions & 0 deletions Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,16 @@ public struct UpdateIndexStoreTaskDescription: IndexTaskDescription {
return
}
let start = ContinuousClock.now
let signposter = Logger(subsystem: LoggingScope.subsystem, category: "indexing").makeSignposter()
let signpostID = signposter.makeSignpostID()
let state = signposter.beginInterval(
"Indexing",
id: signpostID,
"Indexing \(indexFile.fileURL?.lastPathComponent ?? indexFile.pseudoPath)"
)
defer {
signposter.endInterval("Indexing", state)
}
let process = try Process.launch(
arguments: processArguments,
workingDirectory: workingDirectory
Expand Down