mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
tracing: Update to use new Platform tracing apis
V8 modified the platform API to accept a tracing controller at platform creation time that is required to be present for the lifetime of the platform if tracing will every be enabled. This will simplify the implementation of a v8::Platform subclass for node. PR-URL: https://github.com/nodejs/node/pull/14001 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
This commit is contained in:
1 parent
fabe1b4e19
commit
5e5a52fc93
5 files changed
+34
-36
No files matched your search
+8
-7
@@ -251,12 +251,15 @@ node::DebugOptions debug_options;
|
||||
static struct {
|
||||
#if NODE_USE_V8_PLATFORM
|
||||
void Initialize(int thread_pool_size) {
|
||||
tracing_agent_ =
|
||||
trace_enabled ? new tracing::Agent() : nullptr;
|
||||
platform_ = v8::platform::CreateDefaultPlatform(
|
||||
thread_pool_size,
|
||||
v8::platform::IdleTaskSupport::kDisabled,
|
||||
v8::platform::InProcessStackDumping::kDisabled);
|
||||
thread_pool_size, v8::platform::IdleTaskSupport::kDisabled,
|
||||
v8::platform::InProcessStackDumping::kDisabled,
|
||||
trace_enabled ? tracing_agent_->GetTracingController() : nullptr);
|
||||
V8::InitializePlatform(platform_);
|
||||
tracing::TraceEventHelper::SetCurrentPlatform(platform_);
|
||||
tracing::TraceEventHelper::SetTracingController(
|
||||
trace_enabled ? tracing_agent_->GetTracingController() : nullptr);
|
||||
}
|
||||
|
||||
void PumpMessageLoop(Isolate* isolate) {
|
||||
@@ -283,9 +286,7 @@ static struct {
|
||||
#endif // HAVE_INSPECTOR
|
||||
|
||||
void StartTracingAgent() {
|
||||
CHECK(tracing_agent_ == nullptr);
|
||||
tracing_agent_ = new tracing::Agent();
|
||||
tracing_agent_->Start(platform_, trace_enabled_categories);
|
||||
tracing_agent_->Start(trace_enabled_categories);
|
||||
}
|
||||
|
||||
void StopTracingAgent() {
|
||||
|
||||
+8
-12
@@ -12,20 +12,18 @@ namespace tracing {
|
||||
using v8::platform::tracing::TraceConfig;
|
||||
using std::string;
|
||||
|
||||
Agent::Agent() {}
|
||||
|
||||
void Agent::Start(v8::Platform* platform, const string& enabled_categories) {
|
||||
platform_ = platform;
|
||||
|
||||
Agent::Agent() {
|
||||
int err = uv_loop_init(&tracing_loop_);
|
||||
CHECK_EQ(err, 0);
|
||||
|
||||
NodeTraceWriter* trace_writer = new NodeTraceWriter(&tracing_loop_);
|
||||
TraceBuffer* trace_buffer = new NodeTraceBuffer(
|
||||
NodeTraceBuffer::kBufferChunks, trace_writer, &tracing_loop_);
|
||||
|
||||
tracing_controller_ = new TracingController();
|
||||
tracing_controller_->Initialize(trace_buffer);
|
||||
}
|
||||
|
||||
void Agent::Start(const string& enabled_categories) {
|
||||
TraceConfig* trace_config = new TraceConfig();
|
||||
if (!enabled_categories.empty()) {
|
||||
std::stringstream category_list(enabled_categories);
|
||||
@@ -42,27 +40,25 @@ void Agent::Start(v8::Platform* platform, const string& enabled_categories) {
|
||||
// This thread should be created *after* async handles are created
|
||||
// (within NodeTraceWriter and NodeTraceBuffer constructors).
|
||||
// Otherwise the thread could shut down prematurely.
|
||||
err = uv_thread_create(&thread_, ThreadCb, this);
|
||||
int err = uv_thread_create(&thread_, ThreadCb, this);
|
||||
CHECK_EQ(err, 0);
|
||||
|
||||
tracing_controller_->Initialize(trace_buffer);
|
||||
tracing_controller_->StartTracing(trace_config);
|
||||
v8::platform::SetTracingController(platform, tracing_controller_);
|
||||
started_ = true;
|
||||
}
|
||||
|
||||
void Agent::Stop() {
|
||||
if (!IsStarted()) {
|
||||
if (!started_) {
|
||||
return;
|
||||
}
|
||||
// Perform final Flush on TraceBuffer. We don't want the tracing controller
|
||||
// to flush the buffer again on destruction of the V8::Platform.
|
||||
tracing_controller_->StopTracing();
|
||||
tracing_controller_->Initialize(nullptr);
|
||||
tracing_controller_ = nullptr;
|
||||
started_ = false;
|
||||
|
||||
// Thread should finish when the tracing loop is stopped.
|
||||
uv_thread_join(&thread_);
|
||||
v8::platform::SetTracingController(platform_, nullptr);
|
||||
}
|
||||
|
||||
// static
|
||||
|
||||
+4
-3
@@ -12,16 +12,17 @@ namespace tracing {
|
||||
class Agent {
|
||||
public:
|
||||
Agent();
|
||||
void Start(v8::Platform* platform, const std::string& enabled_categories);
|
||||
void Start(const std::string& enabled_categories);
|
||||
void Stop();
|
||||
|
||||
TracingController* GetTracingController() { return tracing_controller_; }
|
||||
|
||||
private:
|
||||
bool IsStarted() { return platform_ != nullptr; }
|
||||
static void ThreadCb(void* arg);
|
||||
|
||||
uv_thread_t thread_;
|
||||
uv_loop_t tracing_loop_;
|
||||
v8::Platform* platform_ = nullptr;
|
||||
bool started_ = false;
|
||||
TracingController* tracing_controller_ = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
namespace node {
|
||||
namespace tracing {
|
||||
|
||||
v8::Platform* platform_ = nullptr;
|
||||
v8::TracingController* controller_ = nullptr;
|
||||
|
||||
void TraceEventHelper::SetCurrentPlatform(v8::Platform* platform) {
|
||||
platform_ = platform;
|
||||
void TraceEventHelper::SetTracingController(v8::TracingController* controller) {
|
||||
controller_ = controller;
|
||||
}
|
||||
|
||||
v8::Platform* TraceEventHelper::GetCurrentPlatform() {
|
||||
return platform_;
|
||||
v8::TracingController* TraceEventHelper::GetTracingController() {
|
||||
return controller_;
|
||||
}
|
||||
|
||||
} // namespace tracing
|
||||
|
||||
@@ -70,7 +70,7 @@ enum CategoryGroupEnabledFlags {
|
||||
// const uint8_t*
|
||||
// TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED(const char* category_group)
|
||||
#define TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED \
|
||||
node::tracing::TraceEventHelper::GetCurrentPlatform() \
|
||||
node::tracing::TraceEventHelper::GetTracingController() \
|
||||
->GetCategoryGroupEnabled
|
||||
|
||||
// Get the number of times traces have been recorded. This is used to implement
|
||||
@@ -99,7 +99,7 @@ enum CategoryGroupEnabledFlags {
|
||||
// const char* name,
|
||||
// uint64_t id)
|
||||
#define TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION \
|
||||
node::tracing::TraceEventHelper::GetCurrentPlatform() \
|
||||
node::tracing::TraceEventHelper::GetTracingController() \
|
||||
->UpdateTraceEventDuration
|
||||
|
||||
// Defines atomic operations used internally by the tracing system.
|
||||
@@ -258,8 +258,8 @@ extern intptr_t kRuntimeCallStatsTracingEnabled;
|
||||
|
||||
class TraceEventHelper {
|
||||
public:
|
||||
static v8::Platform* GetCurrentPlatform();
|
||||
static void SetCurrentPlatform(v8::Platform* platform);
|
||||
static v8::TracingController* GetTracingController();
|
||||
static void SetTracingController(v8::TracingController* controller);
|
||||
};
|
||||
|
||||
// TraceID encapsulates an ID that can either be an integer or pointer. Pointers
|
||||
@@ -406,11 +406,11 @@ static inline uint64_t AddTraceEventImpl(
|
||||
static_cast<intptr_t>(arg_values[1])));
|
||||
}
|
||||
// DCHECK(num_args <= 2);
|
||||
v8::Platform* platform =
|
||||
node::tracing::TraceEventHelper::GetCurrentPlatform();
|
||||
return platform->AddTraceEvent(phase, category_group_enabled, name, scope, id,
|
||||
bind_id, num_args, arg_names, arg_types,
|
||||
arg_values, arg_convertibles, flags);
|
||||
v8::TracingController* controller =
|
||||
node::tracing::TraceEventHelper::GetTracingController();
|
||||
return controller->AddTraceEvent(phase, category_group_enabled, name, scope, id,
|
||||
bind_id, num_args, arg_names, arg_types,
|
||||
arg_values, arg_convertibles, flags);
|
||||
}
|
||||
|
||||
// Define SetTraceValue for each allowed type. It stores the type and
|
||||
|
||||
Reference in new issue
Block a user