@@ -28,10 +28,10 @@ import com.intellij.util.io.DigestUtil
2828import com.intellij.util.net.HttpConfigurable
2929import com.intellij.util.net.JdkProxyProvider
3030import com.intellij.util.net.ssl.CertificateManager
31+ import kotlinx.coroutines.CancellationException
3132import kotlinx.coroutines.CoroutineScope
3233import kotlinx.coroutines.Deferred
3334import kotlinx.coroutines.Job
34- import kotlinx.coroutines.CancellationException
3535import kotlinx.coroutines.async
3636import kotlinx.coroutines.channels.BufferOverflow
3737import 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 {
0 commit comments