From cfe4bc15d722d5687251ef9404d6fe649239507e Mon Sep 17 00:00:00 2001 From: Konstantin Nisht Date: Wed, 11 Jun 2025 13:31:03 +0200 Subject: [PATCH] [scanning] IJPL-187339: Add telemetry for scanning GitOrigin-RevId: 213b75262c244c19d9cdace39f2d5b0113fcc53b --- .../util/indexing/UnindexedFilesScanner.kt | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesScanner.kt b/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesScanner.kt index efb7b2fb9234..a0b89d0549a5 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesScanner.kt +++ b/platform/lang-impl/src/com/intellij/util/indexing/UnindexedFilesScanner.kt @@ -21,9 +21,11 @@ import com.intellij.openapi.util.UserDataHolderEx import com.intellij.openapi.util.registry.Registry import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFileWithId +import com.intellij.platform.diagnostic.telemetry.IJTracer import com.intellij.platform.diagnostic.telemetry.Indexes import com.intellij.platform.diagnostic.telemetry.TelemetryManager.Companion.getInstance import com.intellij.platform.diagnostic.telemetry.helpers.use +import com.intellij.platform.diagnostic.telemetry.helpers.useWithScope import com.intellij.platform.util.coroutines.forEachConcurrent import com.intellij.util.gist.GistManager import com.intellij.util.gist.GistManagerImpl @@ -44,6 +46,7 @@ import com.intellij.util.indexing.roots.IndexableFilesIterator import com.intellij.util.indexing.roots.kind.IndexableSetOrigin import com.intellij.util.indexing.roots.kind.SdkOrigin import com.intellij.util.indexing.roots.origin.GenericContentEntityOrigin +import io.opentelemetry.api.trace.Span import kotlinx.coroutines.* import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.TestOnly @@ -434,10 +437,12 @@ class UnindexedFilesScanner ( sharedExplanationLogger: IndexingReasonExplanationLogger, ) { runBlockingCancellable { - withContext(SCANNING_DISPATCHER) { + tracer.spanBuilder("runBlocking in scanning").useWithScope(context = SCANNING_DISPATCHER) { providers.forEachConcurrent(SCANNING_PARALLELISM) { provider -> try { - scanSingleProvider(provider, sessions, indexableFilesDeduplicateFilter, sharedExplanationLogger) + tracer.spanBuilder("Scanning of ${provider.debugName}").use { + scanSingleProvider(provider, sessions, indexableFilesDeduplicateFilter, sharedExplanationLogger) + } } catch (t: Throwable) { if (t is CancellationException) throw t @@ -471,9 +476,13 @@ class UnindexedFilesScanner ( try { progressReporter.getSubTaskReporter().use { subTaskReporter -> subTaskReporter.setText(provider.rootsScanningProgressText) - val files: ArrayDeque = getFilesToScan(fileScannerVisitors, scanningStatistics, provider, thisProviderDeduplicateFilter) + val files: ArrayDeque = tracer.spanBuilder("Getting files to scan").use { + getFilesToScan(fileScannerVisitors, scanningStatistics, provider, thisProviderDeduplicateFilter) + } PushedFilePropertiesUpdaterImpl.finishVisitors(fileScannerVisitors) - scanFiles(provider, scanningStatistics, sharedExplanationLogger, files) + tracer.spanBuilder("Scanning gathered files").use { span -> + scanFiles(provider, scanningStatistics, sharedExplanationLogger, files, span) + } } } catch (e: Exception) { @@ -503,11 +512,18 @@ class UnindexedFilesScanner ( scanningStatistics: ScanningStatistics, sharedExplanationLogger: IndexingReasonExplanationLogger, files: ArrayDeque, + span: Span, ) { val indexingQueue = project.getService(PerProjectIndexingQueue::class.java) scanningStatistics.startFileChecking() try { + var counter = 0 readAction { + val currentCounter = counter++ + if (currentCounter != 0) { + // report only restarts of scanning read action + span.addEvent("Read action restart #${currentCounter} (${files.size} files remain to scan)") + } val finder = if (ourTestMode == TestMode.PUSHING) null else UnindexedFilesFinder(project, sharedExplanationLogger, forceReindexingTrigger, scanningRequest) @@ -776,3 +792,6 @@ private fun Deferred.getCompletedSafe(): T? { null } } + + +private val tracer: IJTracer get() = getInstance().getTracer(Indexes) \ No newline at end of file