Skip to content

Commit 64b1fc6

Browse files
committed
Merge branch 'manodnyb/addNodePerfLogs2' of https://github.com/aws/aws-toolkit-jetbrains into manodnyb/addNodePerfLogs2
2 parents 8aca112 + 445fcf0 commit 64b1fc6

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/settings/CodeWhispererConfigurable.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@ class CodeWhispererConfigurable(private val project: Project) :
111111
.resizableColumn()
112112
.align(Align.FILL)
113113
}
114+
row {
115+
checkBox("Enable CPU profiling")
116+
.bindSelected(
117+
{ LspSettings.getInstance().isCpuProfilingEnabled() },
118+
{ LspSettings.getInstance().setCpuProfilingEnabled(it) }
119+
)
120+
.comment("Enable CPU profiling for the LSP server to help diagnose performance issues")
121+
}
114122
}
115123

116124
group(message("aws.settings.codewhisperer.group.general")) {

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ import com.intellij.util.io.DigestUtil
2828
import com.intellij.util.net.HttpConfigurable
2929
import com.intellij.util.net.JdkProxyProvider
3030
import com.intellij.util.net.ssl.CertificateManager
31+
import kotlinx.coroutines.CancellationException
3132
import kotlinx.coroutines.CoroutineScope
3233
import kotlinx.coroutines.Deferred
3334
import kotlinx.coroutines.Job
34-
import kotlinx.coroutines.CancellationException
3535
import kotlinx.coroutines.async
3636
import kotlinx.coroutines.channels.BufferOverflow
3737
import kotlinx.coroutines.delay
@@ -126,17 +126,19 @@ internal class LSPProcessListener : ProcessListener {
126126

127127
override fun processTerminated(event: ProcessEvent) {
128128
LOG.info { "LSP process terminated with exit code ${event.exitCode}" }
129-
130-
// Check for CPU profile file after process termination
131-
val processId = ProcessHandle.current().pid()
132-
val profileDir = System.getProperty("java.io.tmpdir").trimEnd('/')
133-
val profilePath = "$profileDir/node-profile-$processId.cpuprofile"
134-
if (Files.exists(Path.of(profilePath))) {
135-
LOG.info { "CPU profile file created: $profilePath" }
136-
} else {
137-
LOG.warn { "CPU profile file not found at: $profilePath" }
129+
130+
// Check for CPU profile file after process termination only if profiling was enabled
131+
if (LspSettings.getInstance().isCpuProfilingEnabled()) {
132+
val processId = ProcessHandle.current().pid()
133+
val profileDir = System.getProperty("java.io.tmpdir").trimEnd('/')
134+
val profilePath = "$profileDir/node-profile-$processId.cpuprofile"
135+
if (Files.exists(Path.of(profilePath))) {
136+
LOG.info { "CPU profile file created: $profilePath" }
137+
} else {
138+
LOG.warn { "CPU profile file not found at: $profilePath" }
139+
}
138140
}
139-
141+
140142
try {
141143
this.outputStreamWriter.close()
142144
this.outputStream.close()
@@ -475,20 +477,22 @@ private class AmazonQServerInstance(private val project: Project, private val cs
475477
val nodePath = getNodeRuntimePath(artifact.resolve(node))
476478
val emptyFile = Files.createTempFile("empty", null).toAbsolutePath().toString()
477479

478-
val processId = ProcessHandle.current().pid()
479-
val profileDir = System.getProperty("java.io.tmpdir").trimEnd('/')
480-
val profilePath = "node-profile-$processId"
481-
LOG.info { "Node.js CPU profile will be saved to: $profileDir $profilePath" }
482-
483480
val cmd = NodeExePatcher.patch(nodePath)
484481
.withParameters(
485-
"--cpu-prof",
486-
"--cpu-prof-dir=$profileDir",
487-
"--cpu-prof-name=$profilePath.cpuprofile",
488-
// "--cpu-prof-name=node-profile-$processId.cpuprofile",
489-
LspSettings.getInstance().getArtifactPath() ?: artifact.resolve("aws-lsp-codewhisperer.js").toString(),
490-
"--stdio",
491-
"--set-credentials-encryption-key",
482+
buildList {
483+
if (LspSettings.getInstance().isCpuProfilingEnabled()) {
484+
val processId = ProcessHandle.current().pid()
485+
val profileDir = System.getProperty("java.io.tmpdir").trimEnd('/')
486+
val profilePath = "node-profile-$processId.cpuprofile.cpuprofile"
487+
LOG.info { "Node.js CPU profile will be saved to: $profileDir $profilePath" }
488+
add("--cpu-prof")
489+
add("--cpu-prof-dir=$profileDir")
490+
add("--cpu-prof-name=$profilePath")
491+
}
492+
add(LspSettings.getInstance().getArtifactPath() ?: artifact.resolve("aws-lsp-codewhisperer.js").toString())
493+
add("--stdio")
494+
add("--set-credentials-encryption-key")
495+
}
492496
).withEnvironment(
493497
buildMap {
494498
extraCaCerts?.let {

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/settings/LspSettings.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class LspSettings : PersistentStateComponent<LspConfiguration> {
2727

2828
fun getNodeRuntimePath() = state.nodeRuntimePath
2929

30+
fun isCpuProfilingEnabled() = state.cpuProfilingEnabled
31+
3032
fun setArtifactPath(artifactPath: String?) {
3133
state.artifactPath = artifactPath.nullize(nullizeSpaces = true)
3234
}
@@ -35,6 +37,10 @@ class LspSettings : PersistentStateComponent<LspConfiguration> {
3537
state.nodeRuntimePath = nodeRuntimePath.nullize(nullizeSpaces = true)
3638
}
3739

40+
fun setCpuProfilingEnabled(enabled: Boolean) {
41+
state.cpuProfilingEnabled = enabled
42+
}
43+
3844
companion object {
3945
fun getInstance(): LspSettings = service()
4046
}
@@ -43,4 +49,5 @@ class LspSettings : PersistentStateComponent<LspConfiguration> {
4349
class LspConfiguration : BaseState() {
4450
var artifactPath by string()
4551
var nodeRuntimePath by string()
52+
var cpuProfilingEnabled by property(false)
4653
}

0 commit comments

Comments
 (0)