From 44250e9cf010f178ca68acae7bf0388b86fca613 Mon Sep 17 00:00:00 2001 From: "Irina.Chernushina" Date: Mon, 26 Mar 2018 17:44:40 +0200 Subject: [PATCH] v8 heap snapshots: take snapshot with v8-inspector - in debug, use existing vm connection; if --debug-brk was passed (for Node.js < 7.0.0), Run mode should be used to take snapshots - for run, pass --inspect=port to Node.js parameters from profiling extension and open vm connection from take snapshot action (close connection after the work is done) - simplify the logic since proxy for v8 heap snapshots is not needed any more - remove not needed fields from ui WEB-29269 Support Node.js heap profiling with Inspector APIs --- .../debugger-ui/src/RemoteVmConnection.kt | 20 ++++++++++- .../org/jetbrains/jsonProtocol/EventMap.kt | 36 ++++++------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/platform/script-debugger/debugger-ui/src/RemoteVmConnection.kt b/platform/script-debugger/debugger-ui/src/RemoteVmConnection.kt index b05a012a1b5a..6055d85b556d 100644 --- a/platform/script-debugger/debugger-ui/src/RemoteVmConnection.kt +++ b/platform/script-debugger/debugger-ui/src/RemoteVmConnection.kt @@ -1,6 +1,7 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.debugger.connection +import com.intellij.execution.ExecutionException import com.intellij.execution.process.ProcessHandler import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.ui.popup.JBPopupFactory @@ -15,7 +16,9 @@ import org.jetbrains.debugger.Vm import org.jetbrains.io.NettyUtil import org.jetbrains.rpc.LOG import java.net.ConnectException +import java.net.InetAddress import java.net.InetSocketAddress +import java.util.concurrent.TimeUnit import java.util.concurrent.atomic.AtomicReference import java.util.function.Consumer import javax.swing.JList @@ -40,7 +43,7 @@ abstract class RemoteVmConnection : VmConnection() { val result = AsyncPromise() result - .onSuccess() { + .onSuccess { connectionSucceeded(it, address) } .rejected { @@ -145,4 +148,19 @@ fun chooseDebuggee(targets: Collection, selectedIndex: Int, renderer: (T, .showInFocusCenter() } return result +} + +@Throws(ExecutionException::class) +fun initRemoteVmConnectionSync(connection: RemoteVmConnection, debugPort: Int): Vm { + val address = InetSocketAddress(InetAddress.getLoopbackAddress(), debugPort) + val vmPromise = connection.open(address) + val vm: Vm + try { + vm = vmPromise.blockingGet(30, TimeUnit.SECONDS)!! + } + catch (e: Exception) { + throw ExecutionException("Cannot connect to VM ($address)", e) + } + + return vm } \ No newline at end of file diff --git a/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/EventMap.kt b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/EventMap.kt index 0fdd30fc3093..297c7ffc4d0e 100644 --- a/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/EventMap.kt +++ b/platform/script-debugger/protocol/protocol-reader-runtime/src/org/jetbrains/jsonProtocol/EventMap.kt @@ -1,24 +1,10 @@ -/* - * Copyright 2000-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jsonProtocol import com.intellij.util.containers.ContainerUtil import org.jetbrains.io.JsonReaderEx -abstract class EventType(val methodName: String) { +abstract class EventType(val methodName: String) { abstract fun read(protocolReader: R, reader: JsonReaderEx): T } @@ -27,19 +13,24 @@ class EventMap(private val protocolReader: R) { private val nameToType = ContainerUtil.newConcurrentMap>() fun add(type: EventType, handler: (T) -> Unit) { - nameToType.put(type.methodName, type) + nameToType[type.methodName] = type @Suppress("UNCHECKED_CAST") nameToHandler.getOrPut(type.methodName, { ContainerUtil.createLockFreeCopyOnWriteList() }).add(handler as (Any?) -> Unit) } - fun addMulti(vararg types: EventType, eventHandler: (T) -> Unit) { + fun remove(type: EventType, handler: (T) -> Unit) { + @Suppress("UNCHECKED_CAST") + nameToHandler[type.methodName]?.remove(handler as (Any?) -> Unit) + } + + fun addMulti(vararg types: EventType, eventHandler: (T) -> Unit) { for (type in types) { add(type, eventHandler) } } fun handleEvent(method: String, data: JsonReaderEx?) { - val handlers = nameToHandler.get(method) + val handlers = nameToHandler[method] if (handlers == null || handlers.isEmpty()) { return } @@ -49,11 +40,4 @@ class EventMap(private val protocolReader: R) { handler(eventData) } } - - fun handleEvent(type: EventType, event: T) { - val handlers = nameToHandler.get(type.methodName) ?: return - for (handler in handlers) { - handler(event) - } - } } \ No newline at end of file