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
This commit is contained in:
Irina.Chernushina
2018-03-27 12:41:09 +02:00
parent 1f5dece713
commit 44250e9cf0
2 changed files with 29 additions and 27 deletions
@@ -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<Vm>() {
val result = AsyncPromise<Vm>()
result
.onSuccess() {
.onSuccess {
connectionSucceeded(it, address)
}
.rejected {
@@ -145,4 +148,19 @@ fun <T> chooseDebuggee(targets: Collection<T>, 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
}
@@ -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<T, R : ResponseResultReader>(val methodName: String) {
abstract class EventType<out T, in R : ResponseResultReader>(val methodName: String) {
abstract fun read(protocolReader: R, reader: JsonReaderEx): T
}
@@ -27,19 +13,24 @@ class EventMap<R : ResponseResultReader>(private val protocolReader: R) {
private val nameToType = ContainerUtil.newConcurrentMap<String, EventType<*, R>>()
fun <T : Any?> add(type: EventType<T, R>, 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 <T> addMulti(vararg types: EventType<out T, R>, eventHandler: (T) -> Unit) {
fun <T : Any?> remove(type: EventType<T, R>, handler: (T) -> Unit) {
@Suppress("UNCHECKED_CAST")
nameToHandler[type.methodName]?.remove(handler as (Any?) -> Unit)
}
fun <T> addMulti(vararg types: EventType<T, R>, 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<R : ResponseResultReader>(private val protocolReader: R) {
handler(eventData)
}
}
fun <T : Any?> handleEvent(type: EventType<T, R>, event: T) {
val handlers = nameToHandler.get(type.methodName) ?: return
for (handler in handlers) {
handler(event)
}
}
}