From 4c2516c07bccacb290f104f4e220e1b44852b45b Mon Sep 17 00:00:00 2001 From: Konstantin Hudyakov Date: Mon, 14 Apr 2025 15:42:46 +0300 Subject: [PATCH] [terminal] IJPL-182482 Report backend document update latency Report it with the length of the updated text. GitOrigin-RevId: bb89d8c5ad1d666147b1b431430608f050fccd70 --- .../backend/StateAwareTerminalSession.kt | 16 ++++++++++++++-- .../fus/ReworkedTerminalUsageCollector.kt | 13 +++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/plugins/terminal/backend/src/com/intellij/terminal/backend/StateAwareTerminalSession.kt b/plugins/terminal/backend/src/com/intellij/terminal/backend/StateAwareTerminalSession.kt index 81a58476799f..465835033612 100644 --- a/plugins/terminal/backend/src/com/intellij/terminal/backend/StateAwareTerminalSession.kt +++ b/plugins/terminal/backend/src/com/intellij/terminal/backend/StateAwareTerminalSession.kt @@ -16,6 +16,7 @@ import org.jetbrains.plugins.terminal.block.reworked.* import org.jetbrains.plugins.terminal.block.ui.TerminalUiUtils import org.jetbrains.plugins.terminal.fus.ReworkedTerminalUsageCollector import kotlin.coroutines.cancellation.CancellationException +import kotlin.time.TimeSource /** * TerminalSession implementation that stores the state of the [delegate] session output. @@ -81,9 +82,8 @@ internal class StateAwareTerminalSession(private val delegate: TerminalSession) private fun handleEvent(event: TerminalOutputEvent) { when (event) { is TerminalContentUpdatedEvent -> { - val styles = event.styles.map { it.toStyleRange() } val model = getCurrentOutputModel() - model.updateContent(event.startLineLogicalIndex, event.text, styles) + updateOutputModelContent(model, event) val latency = event.readTime?.elapsedNow() if (latency != null) { @@ -128,4 +128,16 @@ internal class StateAwareTerminalSession(private val delegate: TerminalSession) private fun getCurrentOutputModel(): TerminalOutputModel { return if (sessionModel.terminalState.value.isAlternateScreenBuffer) alternateBufferModel else outputModel } + + private fun updateOutputModelContent(model: TerminalOutputModel, event: TerminalContentUpdatedEvent) { + val startTime = TimeSource.Monotonic.markNow() + + val styles = event.styles.map { it.toStyleRange() } + model.updateContent(event.startLineLogicalIndex, event.text, styles) + + ReworkedTerminalUsageCollector.logBackendDocumentUpdateLatency( + textLength = event.text.length, + duration = startTime.elapsedNow(), + ) + } } \ No newline at end of file diff --git a/plugins/terminal/src/org/jetbrains/plugins/terminal/fus/ReworkedTerminalUsageCollector.kt b/plugins/terminal/src/org/jetbrains/plugins/terminal/fus/ReworkedTerminalUsageCollector.kt index e48a41832d19..c266f9e705b5 100644 --- a/plugins/terminal/src/org/jetbrains/plugins/terminal/fus/ReworkedTerminalUsageCollector.kt +++ b/plugins/terminal/src/org/jetbrains/plugins/terminal/fus/ReworkedTerminalUsageCollector.kt @@ -75,6 +75,12 @@ object ReworkedTerminalUsageCollector : CounterUsagesCollector() { DURATION_FIELD, ) + private val backendDocumentUpdateLatencyEvent = GROUP.registerVarargEvent( + "terminal.backend.document.update.latency", + TEXT_LENGTH_FIELD, + DURATION_FIELD, + ) + @JvmStatic fun logLocalShellStarted(project: Project, shellCommand: Array) { localShellStartedEvent.log(project, @@ -135,4 +141,11 @@ object ReworkedTerminalUsageCollector : CounterUsagesCollector() { DURATION_FIELD with duration ) } + + fun logBackendDocumentUpdateLatency(textLength: Int, duration: Duration) { + backendDocumentUpdateLatencyEvent.log( + TEXT_LENGTH_FIELD with textLength, + DURATION_FIELD with duration + ) + } }