| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c086736 commit c20c6e5
7 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -349,8 +349,6 @@ Environment::Environment(IsolateData* isolate_data, | |||
| 349 | 349 | credentials::SafeGetenv("NODE_DEBUG_NATIVE", &debug_cats, this); | |
| 350 | 350 | set_debug_categories(debug_cats, true); | |
| 351 | 351 | ||
| 352 | - isolate()->GetHeapProfiler()->AddBuildEmbedderGraphCallback( | ||
| 353 | - BuildEmbedderGraph, this); | ||
| 354 | 352 | if (options_->no_force_async_hooks_checks) { | |
| 355 | 353 | async_hooks_.no_force_checks(); | |
| 356 | 354 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,6 +75,10 @@ class V8CoverageConnection; | |||
| 75 | 75 | class V8CpuProfilerConnection; | |
| 76 | 76 | class V8HeapProfilerConnection; | |
| 77 | 77 | } // namespace profiler | |
| 78 | + | ||
| 79 | + namespace inspector { | ||
| 80 | + class ParentInspectorHandle; | ||
| 81 | + } | ||
| 78 | 82 | #endif // HAVE_INSPECTOR | |
| 79 | 83 | ||
| 80 | 84 | namespace worker { | |
@@ -797,6 +801,13 @@ class Environment : public MemoryRetainer { | |||
| 797 | 801 | void MemoryInfo(MemoryTracker* tracker) const override; | |
| 798 | 802 | ||
| 799 | 803 | void CreateProperties(); | |
| 804 | + // Should be called before InitializeInspector() | ||
| 805 | + void InitializeDiagnostics(); | ||
| 806 | + #if HAVE_INSPECTOR && NODE_USE_V8_PLATFORM | ||
| 807 | + // If the environment is created for a worker, pass parent_handle and | ||
| 808 | + // the ownership if transferred into the Environment. | ||
| 809 | + int InitializeInspector(inspector::ParentInspectorHandle* parent_handle); | ||
| 810 | + #endif | ||
| 800 | 811 | ||
| 801 | 812 | inline size_t async_callback_scope_depth() const; | |
| 802 | 813 | inline void PushAsyncCallbackScope(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -60,6 +60,7 @@ class ParentInspectorHandle { | |||
| 60 | 60 | bool WaitForConnect() { | |
| 61 | 61 | return wait_; | |
| 62 | 62 | } | |
| 63 | + const std::string& url() const { return url_; } | ||
| 63 | 64 | ||
| 64 | 65 | private: | |
| 65 | 66 | int id_; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,6 +47,7 @@ | |||
| 47 | 47 | #endif | |
| 48 | 48 | ||
| 49 | 49 | #if HAVE_INSPECTOR | |
| 50 | + #include "inspector_agent.h" | ||
| 50 | 51 | #include "inspector_io.h" | |
| 51 | 52 | #endif | |
| 52 | 53 | ||
@@ -59,6 +60,10 @@ | |||
| 59 | 60 | #endif // NODE_USE_V8_PLATFORM | |
| 60 | 61 | #include "v8-profiler.h" | |
| 61 | 62 | ||
| 63 | + #if HAVE_INSPECTOR | ||
| 64 | + #include "inspector/worker_inspector.h" // ParentInspectorHandle | ||
| 65 | + #endif | ||
| 66 | + | ||
| 62 | 67 | #ifdef NODE_ENABLE_VTUNE_PROFILING | |
| 63 | 68 | #include "../deps/v8/src/third_party/vtune/v8-vtune.h" | |
| 64 | 69 | #endif | |
@@ -125,7 +130,6 @@ using v8::Local; | |||
| 125 | 130 | using v8::Maybe; | |
| 126 | 131 | using v8::MaybeLocal; | |
| 127 | 132 | using v8::Object; | |
| 128 | - using v8::Script; | ||
| 129 | 133 | using v8::String; | |
| 130 | 134 | using v8::Undefined; | |
| 131 | 135 | using v8::V8; | |
@@ -222,24 +226,61 @@ MaybeLocal<Value> ExecuteBootstrapper(Environment* env, | |||
| 222 | 226 | return scope.EscapeMaybe(result); | |
| 223 | 227 | } | |
| 224 | 228 | ||
| 229 | + #if HAVE_INSPECTOR && NODE_USE_V8_PLATFORM | ||
| 230 | + int Environment::InitializeInspector( | ||
| 231 | + inspector::ParentInspectorHandle* parent_handle) { | ||
| 232 | + std::string inspector_path; | ||
| 233 | + if (parent_handle != nullptr) { | ||
| 234 | + DCHECK(!is_main_thread()); | ||
| 235 | + inspector_path = parent_handle->url(); | ||
| 236 | + inspector_agent_->SetParentHandle( | ||
| 237 | + std::unique_ptr<inspector::ParentInspectorHandle>(parent_handle)); | ||
| 238 | + } else { | ||
| 239 | + inspector_path = argv_.size() > 1 ? argv_[1].c_str() : ""; | ||
| 240 | + } | ||
| 241 | + | ||
| 242 | + CHECK(!inspector_agent_->IsListening()); | ||
| 243 | + // Inspector agent can't fail to start, but if it was configured to listen | ||
| 244 | + // right away on the websocket port and fails to bind/etc, this will return | ||
| 245 | + // false. | ||
| 246 | + inspector_agent_->Start(inspector_path, | ||
| 247 | + options_->debug_options(), | ||
| 248 | + inspector_host_port(), | ||
| 249 | + is_main_thread()); | ||
| 250 | + if (options_->debug_options().inspector_enabled && | ||
| 251 | + !inspector_agent_->IsListening()) { | ||
| 252 | + return 12; // Signal internal error | ||
| 253 | + } | ||
| 254 | + | ||
| 255 | + profiler::StartProfilers(this); | ||
| 256 | + | ||
| 257 | + if (options_->debug_options().break_node_first_line) { | ||
| 258 | + inspector_agent_->PauseOnNextJavascriptStatement("Break at bootstrap"); | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + return 0; | ||
| 262 | + } | ||
| 263 | + #endif // HAVE_INSPECTOR && NODE_USE_V8_PLATFORM | ||
| 264 | + | ||
| 265 | + void Environment::InitializeDiagnostics() { | ||
| 266 | + isolate_->GetHeapProfiler()->AddBuildEmbedderGraphCallback( | ||
| 267 | + Environment::BuildEmbedderGraph, this); | ||
| 268 | + | ||
| 269 | + #if defined HAVE_DTRACE || defined HAVE_ETW | ||
| 270 | + InitDTrace(this); | ||
| 271 | + #endif | ||
| 272 | + } | ||
| 273 | + | ||
| 225 | 274 | MaybeLocal<Value> RunBootstrapping(Environment* env) { | |
| 226 | 275 | CHECK(!env->has_run_bootstrapping_code()); | |
| 227 | 276 | ||
| 228 | 277 | EscapableHandleScope scope(env->isolate()); | |
| 229 | 278 | Isolate* isolate = env->isolate(); | |
| 230 | 279 | Local<Context> context = env->context(); | |
| 231 | 280 | ||
| 232 | - #if HAVE_INSPECTOR | ||
| 233 | - profiler::StartProfilers(env); | ||
| 234 | - #endif // HAVE_INSPECTOR | ||
| 235 | 281 | ||
| 236 | 282 | // Add a reference to the global object | |
| 237 | 283 | Local<Object> global = context->Global(); | |
| 238 | - | ||
| 239 | - #if defined HAVE_DTRACE || defined HAVE_ETW | ||
| 240 | - InitDTrace(env); | ||
| 241 | - #endif | ||
| 242 | - | ||
| 243 | 284 | Local<Object> process = env->process_object(); | |
| 244 | 285 | ||
| 245 | 286 | // Setting global properties for the bootstrappers to use: | |
@@ -249,12 +290,6 @@ MaybeLocal<Value> RunBootstrapping(Environment* env) { | |||
| 249 | 290 | global->Set(context, FIXED_ONE_BYTE_STRING(env->isolate(), "global"), global) | |
| 250 | 291 | .Check(); | |
| 251 | 292 | ||
| 252 | - #if HAVE_INSPECTOR | ||
| 253 | - if (env->options()->debug_options().break_node_first_line) { | ||
| 254 | - env->inspector_agent()->PauseOnNextJavascriptStatement( | ||
| 255 | - "Break at bootstrap"); | ||
| 256 | - } | ||
| 257 | - #endif // HAVE_INSPECTOR | ||
| 258 | 293 | ||
| 259 | 294 | // Create binding loaders | |
| 260 | 295 | std::vector<Local<String>> loaders_params = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -194,27 +194,16 @@ std::unique_ptr<Environment> NodeMainInstance::CreateMainEnvironment( | |||
| 194 | 194 | Environment::kOwnsProcessState | | |
| 195 | 195 | Environment::kOwnsInspector)); | |
| 196 | 196 | env->InitializeLibuv(per_process::v8_is_profiling); | |
| 197 | + env->InitializeDiagnostics(); | ||
| 197 | 198 | ||
| 199 | + // TODO(joyeecheung): when we snapshot the bootstrapped context, | ||
| 200 | + // the inspector and diagnostics setup should after after deserialization. | ||
| 198 | 201 | #if HAVE_INSPECTOR && NODE_USE_V8_PLATFORM | |
| 199 | - CHECK(!env->inspector_agent()->IsListening()); | ||
| 200 | - // Inspector agent can't fail to start, but if it was configured to listen | ||
| 201 | - // right away on the websocket port and fails to bind/etc, this will return | ||
| 202 | - // false. | ||
| 203 | - env->inspector_agent()->Start(args_.size() > 1 ? args_[1].c_str() : "", | ||
| 204 | - env->options()->debug_options(), | ||
| 205 | - env->inspector_host_port(), | ||
| 206 | - true); | ||
| 207 | - if (env->options()->debug_options().inspector_enabled && | ||
| 208 | - !env->inspector_agent()->IsListening()) { | ||
| 209 | - *exit_code = 12; // Signal internal error. | ||
| 202 | + *exit_code = env->InitializeInspector(nullptr); | ||
| 203 | + #endif | ||
| 204 | + if (*exit_code != 0) { | ||
| 210 | 205 | return env; | |
| 211 | 206 | } | |
| 212 | - #else | ||
| 213 | - // inspector_enabled can't be true if !HAVE_INSPECTOR or | ||
| 214 | - // !NODE_USE_V8_PLATFORM | ||
| 215 | - // - the option parser should not allow that. | ||
| 216 | - CHECK(!env->options()->debug_options().inspector_enabled); | ||
| 217 | - #endif // HAVE_INSPECTOR && NODE_USE_V8_PLATFORM | ||
| 218 | 207 | ||
| 219 | 208 | if (RunBootstrapping(env.get()).IsEmpty()) { | |
| 220 | 209 | *exit_code = 1; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,17 +42,6 @@ namespace worker { | |||
| 42 | 42 | namespace { | |
| 43 | 43 | ||
| 44 | 44 | #if NODE_USE_V8_PLATFORM && HAVE_INSPECTOR | |
| 45 | - void StartWorkerInspector( | ||
| 46 | - Environment* child, | ||
| 47 | - std::unique_ptr<inspector::ParentInspectorHandle> parent_handle, | ||
| 48 | - const std::string& url) { | ||
| 49 | - child->inspector_agent()->SetParentHandle(std::move(parent_handle)); | ||
| 50 | - child->inspector_agent()->Start(url, | ||
| 51 | - child->options()->debug_options(), | ||
| 52 | - child->inspector_host_port(), | ||
| 53 | - false); | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | 45 | void WaitForWorkerInspectorToStop(Environment* child) { | |
| 57 | 46 | child->inspector_agent()->WaitForDisconnect(); | |
| 58 | 47 | child->inspector_agent()->Stop(); | |
@@ -67,11 +56,10 @@ Worker::Worker(Environment* env, | |||
| 67 | 56 | std::shared_ptr<PerIsolateOptions> per_isolate_opts, | |
| 68 | 57 | std::vector<std::string>&& exec_argv) | |
| 69 | 58 | : AsyncWrap(env, wrap, AsyncWrap::PROVIDER_WORKER), | |
| 70 | - url_(url), | ||
| 71 | 59 | per_isolate_opts_(per_isolate_opts), | |
| 72 | 60 | exec_argv_(exec_argv), | |
| 73 | 61 | platform_(env->isolate_data()->platform()), | |
| 74 | - profiler_idle_notifier_started_(env->profiler_idle_notifier_started()), | ||
| 62 | + start_profiler_idle_notifier_(env->profiler_idle_notifier_started()), | ||
| 75 | 63 | thread_id_(Environment::AllocateThreadId()), | |
| 76 | 64 | env_vars_(env->env_vars()) { | |
| 77 | 65 | Debug(this, "Creating new worker instance with thread id %llu", thread_id_); | |
@@ -265,7 +253,7 @@ void Worker::Run() { | |||
| 265 | 253 | env_->set_abort_on_uncaught_exception(false); | |
| 266 | 254 | env_->set_worker_context(this); | |
| 267 | 255 | ||
| 268 | - env_->InitializeLibuv(profiler_idle_notifier_started_); | ||
| 256 | + env_->InitializeLibuv(start_profiler_idle_notifier_); | ||
| 269 | 257 | } | |
| 270 | 258 | { | |
| 271 | 259 | Mutex::ScopedLock lock(mutex_); | |
@@ -275,13 +263,11 @@ void Worker::Run() { | |||
| 275 | 263 | Debug(this, "Created Environment for worker with id %llu", thread_id_); | |
| 276 | 264 | if (is_stopped()) return; | |
| 277 | 265 | { | |
| 266 | + env_->InitializeDiagnostics(); | ||
| 278 | 267 | #if NODE_USE_V8_PLATFORM && HAVE_INSPECTOR | |
| 279 | - StartWorkerInspector(env_.get(), | ||
| 280 | - std::move(inspector_parent_handle_), | ||
| 281 | - url_); | ||
| 282 | - #endif | ||
| 268 | + env_->InitializeInspector(inspector_parent_handle_.release()); | ||
| 283 | 269 | inspector_started = true; | |
| 284 | - | ||
| 270 | + #endif | ||
| 285 | 271 | HandleScope handle_scope(isolate_); | |
| 286 | 272 | AsyncCallbackScope callback_scope(env_.get()); | |
| 287 | 273 | env_->async_hooks()->push_async_ids(1, 0); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,15 +54,14 @@ class Worker : public AsyncWrap { | |||
| 54 | 54 | private: | |
| 55 | 55 | void OnThreadStopped(); | |
| 56 | 56 | void CreateEnvMessagePort(Environment* env); | |
| 57 | - const std::string url_; | ||
| 58 | 57 | ||
| 59 | 58 | std::shared_ptr<PerIsolateOptions> per_isolate_opts_; | |
| 60 | 59 | std::vector<std::string> exec_argv_; | |
| 61 | 60 | std::vector<std::string> argv_; | |
| 62 | 61 | ||
| 63 | 62 | MultiIsolatePlatform* platform_; | |
| 64 | 63 | v8::Isolate* isolate_ = nullptr; | |
| 65 | - bool profiler_idle_notifier_started_; | ||
| 64 | + bool start_profiler_idle_notifier_; | ||
| 66 | 65 | uv_thread_t tid_; | |
| 67 | 66 | ||
| 68 | 67 | #if NODE_USE_V8_PLATFORM && HAVE_INSPECTOR | |
| Back | FazBrowse Home | New Git URL |
0 commit comments