summaryrefslogtreecommitdiff
path: root/src/inspector_agent.h
diff options
context:
space:
mode:
authorMiroslav Bajtoš <mbajtoss@gmail.com>2017-07-17 16:51:26 +0200
committerTimothy Gu <timothygu99@gmail.com>2017-08-17 20:52:39 +0800
commita0895ed6c484fc3b322c70bcbf36080b1fe70154 (patch)
tree89501c4b775237148975c269ea414f5069285897 /src/inspector_agent.h
parentb616e879474f72333a73db1d879abf5b5ba36f1d (diff)
downloadandroid-node-v8-a0895ed6c484fc3b322c70bcbf36080b1fe70154.tar.gz
android-node-v8-a0895ed6c484fc3b322c70bcbf36080b1fe70154.tar.bz2
android-node-v8-a0895ed6c484fc3b322c70bcbf36080b1fe70154.zip
inspector: enable async stack traces
Implement a special async_hooks listener that forwards information about async tasks to V8Inspector asyncTask* API, thus enabling DevTools feature "async stack traces". The feature is enabled only on 64bit platforms due to a technical limitation of V8 Inspector: inspector uses a pointer as a task id, while async_hooks use 64bit numbers as ids. To avoid performance penalty of async_hooks when not debugging, the new listener is enabled only when the process enters a debug mode: - When the process is started with `--inspect` or `--inspect-brk`, the listener is enabled immediately and async stack traces lead all the way to the first tick of the event loop. - When the debug mode is enabled via SIGUSR1 or `_debugProcess()`, the listener is enabled together with the debugger. As a result, only async operations started after the signal was received will be correctly observed and reported to V8 Inspector. For example, a `setInterval()` called in the first tick of the event will not be shown in the async stack trace when the callback is invoked. This behaviour is consistent with Chrome DevTools. Last but not least, this commit fixes handling of InspectorAgent's internal property `enabled_` to ensure it's set back to `false` after the debugger is deactivated (typically via `process._debugEnd()`). Fixes: https://github.com/nodejs/node/issues/11370 PR-URL: https://github.com/nodejs/node/pull/13870 Reviewed-by: Timothy Gu <timothygu99@gmail.com> Reviewed-by: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/inspector_agent.h')
-rw-r--r--src/inspector_agent.h27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/inspector_agent.h b/src/inspector_agent.h
index cf9a8bff86..6ec1bc28dc 100644
--- a/src/inspector_agent.h
+++ b/src/inspector_agent.h
@@ -16,17 +16,7 @@ namespace node {
class Environment;
} // namespace node
-namespace v8 {
-class Context;
-template <typename V>
-class FunctionCallbackInfo;
-template<typename T>
-class Local;
-class Message;
-class Object;
-class Platform;
-class Value;
-} // namespace v8
+#include "v8.h"
namespace v8_inspector {
class StringView;
@@ -67,6 +57,18 @@ class Agent {
void FatalException(v8::Local<v8::Value> error,
v8::Local<v8::Message> message);
+ // Async stack traces instrumentation.
+ void AsyncTaskScheduled(const v8_inspector::StringView& taskName, void* task,
+ bool recurring);
+ void AsyncTaskCanceled(void* task);
+ void AsyncTaskStarted(void* task);
+ void AsyncTaskFinished(void* task);
+ void AllAsyncTasksCanceled();
+
+ void RegisterAsyncHook(v8::Isolate* isolate,
+ v8::Local<v8::Function> enable_function,
+ v8::Local<v8::Function> disable_function);
+
// These methods are called by the WS protocol and JS binding to create
// inspector sessions. The inspector responds by using the delegate to send
// messages back.
@@ -107,6 +109,9 @@ class Agent {
std::string path_;
DebugOptions debug_options_;
int next_context_number_;
+
+ v8::Persistent<v8::Function> enable_async_hook_function_;
+ v8::Persistent<v8::Function> disable_async_hook_function_;
};
} // namespace inspector