From 77da7682dfa6c164fb4c4b26b4b7efad143d8539 Mon Sep 17 00:00:00 2001 From: "roman.ivanitskii" Date: Thu, 3 Nov 2022 13:45:49 +0200 Subject: [PATCH] [kotlin-plugin] measure time in OpenFileCommand like first highlighting GitOrigin-RevId: d575250647f3c3a95546f6bbf4f3a3fde235b86c --- .../commands/OpenFileCommand.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/performanceTesting/src/com/jetbrains/performancePlugin/commands/OpenFileCommand.kt b/plugins/performanceTesting/src/com/jetbrains/performancePlugin/commands/OpenFileCommand.kt index 8f14e1624417..7150a5c1b07f 100644 --- a/plugins/performanceTesting/src/com/jetbrains/performancePlugin/commands/OpenFileCommand.kt +++ b/plugins/performanceTesting/src/com/jetbrains/performancePlugin/commands/OpenFileCommand.kt @@ -7,11 +7,14 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.project.guessProjectDir import com.intellij.openapi.ui.playback.PlaybackContext import com.intellij.openapi.ui.playback.commands.PlaybackCommandCoroutineAdapter +import com.intellij.openapi.util.Ref import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.vfs.JarFileSystem import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VirtualFile +import com.jetbrains.performancePlugin.PerformanceTestSpan import com.jetbrains.performancePlugin.PerformanceTestingBundle +import io.opentelemetry.api.trace.Span import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.jetbrains.annotations.NonNls @@ -20,6 +23,7 @@ import java.util.concurrent.CompletableFuture internal class OpenFileCommand(text: String, line: Int) : PlaybackCommandCoroutineAdapter(text, line) { companion object { const val PREFIX: @NonNls String = CMD_PREFIX + "openFile" + const val SPAN_NAME: @NonNls String = "firstHighlight" @JvmStatic fun findFile(filePath: String, project: Project): VirtualFile? { @@ -35,12 +39,10 @@ internal class OpenFileCommand(text: String, line: Int) : PlaybackCommandCorouti val filePath = text.split(' ', limit = 2)[1] val project = context.project val file = findFile(filePath, project) ?: error(PerformanceTestingBundle.message("command.file.not.found", filePath)) - withContext(Dispatchers.EDT) { - FileEditorManager.getInstance(project).openFile(file, true) - } - val job = CompletableFuture() val connection = project.messageBus.simpleConnect() + val span = PerformanceTestSpan.TRACER.spanBuilder(SPAN_NAME).setParent(PerformanceTestSpan.getContext()) + val spanRef = Ref() connection.subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, object : DaemonCodeAnalyzer.DaemonListener { override fun daemonFinished() { try { @@ -48,11 +50,15 @@ internal class OpenFileCommand(text: String, line: Int) : PlaybackCommandCorouti context.message(PerformanceTestingBundle.message("command.file.opened", file.name), line) } finally { + spanRef.get()?.end() job.complete(Unit) } } }) - + withContext(Dispatchers.EDT) { + spanRef.set(span.startSpan()) + FileEditorManager.getInstance(project).openFile(file, true) + } job.join() } } \ No newline at end of file