-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: various improvements toward a complete embedder API #30229
Changes from all commits
193d09b
49e1721
e4e4e76
ded953f
36787d7
e18e4f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
#include "diagnosticfilename-inl.h" | ||
#include "memory_tracker-inl.h" | ||
#include "node_file.h" | ||
#include "node_errors.h" | ||
#include "node_internals.h" | ||
#include "util-inl.h" | ||
#include "v8-inspector.h" | ||
|
@@ -13,6 +14,7 @@ | |
namespace node { | ||
namespace profiler { | ||
|
||
using errors::TryCatchScope; | ||
using v8::Context; | ||
using v8::Function; | ||
using v8::FunctionCallbackInfo; | ||
|
@@ -219,12 +221,21 @@ void V8CoverageConnection::WriteProfile(Local<String> message) { | |
} | ||
|
||
// append source-map cache information to coverage object: | ||
Local<Function> source_map_cache_getter = env_->source_map_cache_getter(); | ||
Local<Value> source_map_cache_v; | ||
if (!source_map_cache_getter->Call(env()->context(), | ||
Undefined(isolate), 0, nullptr) | ||
.ToLocal(&source_map_cache_v)) { | ||
return; | ||
{ | ||
TryCatchScope try_catch(env()); | ||
{ | ||
Isolate::AllowJavascriptExecutionScope allow_js_here(isolate); | ||
Local<Function> source_map_cache_getter = env_->source_map_cache_getter(); | ||
if (!source_map_cache_getter->Call( | ||
context, Undefined(isolate), 0, nullptr) | ||
.ToLocal(&source_map_cache_v)) { | ||
return; | ||
} | ||
} | ||
if (try_catch.HasCaught() && !try_catch.HasTerminated()) { | ||
PrintCaughtException(isolate, context, try_catch); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really related to this PR but now come to think of it we should probably avoid executing JS at all during profile serialization considering we also write the profiles when there is an uncaught exception... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @joyeecheung Yeah … I had the same thought, and I talked about it with @bcoe – it turns out re-implementing the JS code in C++ expands the code quite noticeably, and moving the source map caches to C++ is also tricky, in part because the CJS cache relies on |
||
} | ||
} | ||
// Avoid writing to disk if no source-map data: | ||
if (!source_map_cache_v->IsUndefined()) { | ||
|
@@ -351,7 +362,7 @@ void V8HeapProfilerConnection::End() { | |
|
||
// For now, we only support coverage profiling, but we may add more | ||
// in the future. | ||
void EndStartedProfilers(Environment* env) { | ||
static void EndStartedProfilers(Environment* env) { | ||
Debug(env, DebugCategory::INSPECTOR_PROFILER, "EndStartedProfilers\n"); | ||
V8ProfilerConnection* connection = env->cpu_profiler_connection(); | ||
if (connection != nullptr && !connection->ending()) { | ||
|
@@ -390,6 +401,10 @@ std::string GetCwd(Environment* env) { | |
} | ||
|
||
void StartProfilers(Environment* env) { | ||
AtExit(env, [](void* env) { | ||
EndStartedProfilers(static_cast<Environment*>(env)); | ||
}, env); | ||
|
||
Isolate* isolate = env->isolate(); | ||
Local<String> coverage_str = env->env_vars()->Get( | ||
isolate, FIXED_ONE_BYTE_STRING(isolate, "NODE_V8_COVERAGE")) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC this is the first time we use
AtExit
internally? (I vaguely remember we have done that before but I could not find any existing AtExit calls ATM)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think so 👍