| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cc22555 commit 8a5d3bc
18 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -187,6 +187,7 @@ | |||
| 187 | 187 | 'src/timers.cc', | |
| 188 | 188 | 'src/timer_wrap.cc', | |
| 189 | 189 | 'src/tracing/agent.cc', | |
| 190 | + 'src/tracing/agent_legacy.cc', | ||
| 190 | 191 | 'src/tracing/node_trace_buffer.cc', | |
| 191 | 192 | 'src/tracing/node_trace_writer.cc', | |
| 192 | 193 | 'src/tracing/trace_event.cc', | |
@@ -323,6 +324,7 @@ | |||
| 323 | 324 | 'src/tcp_wrap.h', | |
| 324 | 325 | 'src/timers.h', | |
| 325 | 326 | 'src/tracing/agent.h', | |
| 327 | + 'src/tracing/agent_legacy.h', | ||
| 326 | 328 | 'src/tracing/node_trace_buffer.h', | |
| 327 | 329 | 'src/tracing/node_trace_writer.h', | |
| 328 | 330 | 'src/tracing/trace_event.h', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,7 +70,6 @@ using v8::SnapshotCreator; | |||
| 70 | 70 | using v8::StackTrace; | |
| 71 | 71 | using v8::String; | |
| 72 | 72 | using v8::Symbol; | |
| 73 | - using v8::TracingController; | ||
| 74 | 73 | using v8::TryCatch; | |
| 75 | 74 | using v8::Uint32; | |
| 76 | 75 | using v8::Undefined; | |
@@ -878,10 +877,9 @@ Environment::Environment(IsolateData* isolate_data, | |||
| 878 | 877 | inspector_agent_ = std::make_unique<inspector::Agent>(this); | |
| 879 | 878 | #endif | |
| 880 | 879 | ||
| 881 | - if (tracing::AgentWriterHandle* writer = GetTracingAgentWriter()) { | ||
| 880 | + if (tracing::Agent* agent = tracing::Agent::GetInstance()) { | ||
| 882 | 881 | trace_state_observer_ = std::make_unique<TrackingTraceStateObserver>(this); | |
| 883 | - if (TracingController* tracing_controller = writer->GetTracingController()) | ||
| 884 | - tracing_controller->AddTraceStateObserver(trace_state_observer_.get()); | ||
| 882 | + agent->AddTraceStateObserver(trace_state_observer_.get()); | ||
| 885 | 883 | } | |
| 886 | 884 | ||
| 887 | 885 | destroy_async_id_list_.reserve(512); | |
@@ -1038,10 +1036,8 @@ Environment::~Environment() { | |||
| 1038 | 1036 | principal_realm_.reset(); | |
| 1039 | 1037 | ||
| 1040 | 1038 | if (trace_state_observer_) { | |
| 1041 | - tracing::AgentWriterHandle* writer = GetTracingAgentWriter(); | ||
| 1042 | - CHECK_NOT_NULL(writer); | ||
| 1043 | - if (TracingController* tracing_controller = writer->GetTracingController()) | ||
| 1044 | - tracing_controller->RemoveTraceStateObserver(trace_state_observer_.get()); | ||
| 1039 | + if (tracing::Agent* agent = tracing::Agent::GetInstance()) | ||
| 1040 | + agent->RemoveTraceStateObserver(trace_state_observer_.get()); | ||
| 1045 | 1041 | } | |
| 1046 | 1042 | ||
| 1047 | 1043 | TRACE_EVENT_NESTABLE_ASYNC_END0( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,6 +3,7 @@ | |||
| 3 | 3 | #include "main_thread_interface.h" | |
| 4 | 4 | #include "node_internals.h" | |
| 5 | 5 | #include "node_v8_platform-inl.h" | |
| 6 | + #include "tracing/agent_legacy.h" | ||
| 6 | 7 | #include "v8.h" | |
| 7 | 8 | ||
| 8 | 9 | #include <set> | |
@@ -162,13 +163,14 @@ DispatchResponse TracingAgent::start( | |||
| 162 | 163 | return DispatchResponse::InvalidRequest( | |
| 163 | 164 | "At least one category should be enabled"); | |
| 164 | 165 | ||
| 165 | - tracing::AgentWriterHandle* writer = GetTracingAgentWriter(); | ||
| 166 | - if (writer != nullptr) { | ||
| 166 | + auto* agent = | ||
| 167 | + static_cast<tracing::LegacyTracingAgent*>(tracing::Agent::GetInstance()); | ||
| 168 | + if (agent != nullptr) { | ||
| 167 | 169 | trace_writer_ = | |
| 168 | - writer->agent()->AddClient(categories_set, | ||
| 169 | - std::make_unique<InspectorTraceWriter>( | ||
| 170 | - frontend_object_id_, main_thread_), | ||
| 171 | - tracing::Agent::kIgnoreDefaultCategories); | ||
| 170 | + agent->AddClient(categories_set, | ||
| 171 | + std::make_unique<InspectorTraceWriter>( | ||
| 172 | + frontend_object_id_, main_thread_), | ||
| 173 | + tracing::LegacyTracingAgent::kIgnoreDefaultCategories); | ||
| 172 | 174 | } | |
| 173 | 175 | return DispatchResponse::Success(); | |
| 174 | 176 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,7 +75,7 @@ void NodeCategorySet::New(const FunctionCallbackInfo<Value>& args) { | |||
| 75 | 75 | if (!*val) return; | |
| 76 | 76 | categories.emplace(*val); | |
| 77 | 77 | } | |
| 78 | - CHECK_NOT_NULL(GetTracingAgentWriter()); | ||
| 78 | + CHECK_NOT_NULL(tracing::Agent::GetInstance()); | ||
| 79 | 79 | new NodeCategorySet(env, args.This(), std::move(categories)); | |
| 80 | 80 | } | |
| 81 | 81 | ||
@@ -93,8 +93,10 @@ void NodeCategorySet::Enable(const FunctionCallbackInfo<Value>& args) { | |||
| 93 | 93 | filepath); | |
| 94 | 94 | // Starts the Tracing Agent if it wasn't started already (e.g. through | |
| 95 | 95 | // a command line flag.) | |
| 96 | - StartTracingAgent(); | ||
| 97 | - GetTracingAgentWriter()->Enable(categories); | ||
| 96 | + auto* agent = tracing::Agent::GetInstance(); | ||
| 97 | + agent->StartTracing(per_process::cli_options->trace_event_categories); | ||
| 98 | + tracing::AgentWriterHandle* writer = agent->GetDefaultWriterHandle(); | ||
| 99 | + writer->Enable(categories); | ||
| 98 | 100 | category_set->enabled_ = true; | |
| 99 | 101 | } | |
| 100 | 102 | } | |
@@ -105,15 +107,17 @@ void NodeCategorySet::Disable(const FunctionCallbackInfo<Value>& args) { | |||
| 105 | 107 | CHECK_NOT_NULL(category_set); | |
| 106 | 108 | const auto& categories = category_set->GetCategories(); | |
| 107 | 109 | if (category_set->enabled_ && !categories.empty()) { | |
| 108 | - GetTracingAgentWriter()->Disable(categories); | ||
| 110 | + auto* agent = tracing::Agent::GetInstance(); | ||
| 111 | + tracing::AgentWriterHandle* writer = agent->GetDefaultWriterHandle(); | ||
| 112 | + writer->Disable(categories); | ||
| 109 | 113 | category_set->enabled_ = false; | |
| 110 | 114 | } | |
| 111 | 115 | } | |
| 112 | 116 | ||
| 113 | 117 | void GetEnabledCategories(const FunctionCallbackInfo<Value>& args) { | |
| 114 | 118 | Environment* env = Environment::GetCurrent(args); | |
| 115 | 119 | std::string categories = | |
| 116 | - GetTracingAgentWriter()->agent()->GetEnabledCategories(); | ||
| 120 | + tracing::Agent::GetInstance()->GetEnabledCategories(); | ||
| 117 | 121 | Local<Value> ret; | |
| 118 | 122 | if (!categories.empty() && | |
| 119 | 123 | ToV8Value(env->context(), categories, env->isolate()).ToLocal(&ret)) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,84 +4,30 @@ | |||
| 4 | 4 | #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
| 5 | 5 | ||
| 6 | 6 | #include <memory> | |
| 7 | - #include <string_view> | ||
| 8 | 7 | ||
| 9 | 8 | #include "env-inl.h" | |
| 10 | 9 | #include "node.h" | |
| 11 | - #include "node_metadata.h" | ||
| 12 | - #include "node_platform.h" | ||
| 13 | 10 | #include "node_options.h" | |
| 14 | - #include "tracing/node_trace_writer.h" | ||
| 15 | - #include "tracing/trace_event.h" | ||
| 16 | - #include "tracing/traced_value.h" | ||
| 17 | - #include "util.h" | ||
| 11 | + #include "node_platform.h" | ||
| 12 | + #include "tracing/agent.h" | ||
| 18 | 13 | ||
| 19 | 14 | namespace node { | |
| 20 | 15 | ||
| 21 | - // Ensures that __metadata trace events are only emitted | ||
| 22 | - // when tracing is enabled. | ||
| 23 | - class NodeTraceStateObserver | ||
| 24 | - : public v8::TracingController::TraceStateObserver { | ||
| 25 | - public: | ||
| 26 | - inline void OnTraceEnabled() override { | ||
| 27 | - std::string title = GetProcessTitle(""); | ||
| 28 | - if (!title.empty()) { | ||
| 29 | - // Only emit the metadata event if the title can be retrieved | ||
| 30 | - // successfully. Ignore it otherwise. | ||
| 31 | - TRACE_EVENT_METADATA1( | ||
| 32 | - "__metadata", "process_name", "name", TRACE_STR_COPY(title.c_str())); | ||
| 33 | - } | ||
| 34 | - TRACE_EVENT_METADATA1("__metadata", | ||
| 35 | - "version", | ||
| 36 | - "node", | ||
| 37 | - per_process::metadata.versions.node.c_str()); | ||
| 38 | - TRACE_EVENT_METADATA1( | ||
| 39 | - "__metadata", "thread_name", "name", "JavaScriptMainThread"); | ||
| 40 | - | ||
| 41 | - tracing::ProcessMeta trace_process; | ||
| 42 | - TRACE_EVENT_METADATA1("__metadata", | ||
| 43 | - "node", | ||
| 44 | - "process", | ||
| 45 | - tracing::CastTracedValue(trace_process)); | ||
| 46 | - // This only runs the first time tracing is enabled | ||
| 47 | - controller_->RemoveTraceStateObserver(this); | ||
| 48 | - } | ||
| 49 | - | ||
| 50 | - inline void OnTraceDisabled() override { | ||
| 51 | - // Do nothing here. This should never be called because the | ||
| 52 | - // observer removes itself when OnTraceEnabled() is called. | ||
| 53 | - UNREACHABLE(); | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - explicit NodeTraceStateObserver(v8::TracingController* controller) | ||
| 57 | - : controller_(controller) {} | ||
| 58 | - ~NodeTraceStateObserver() override = default; | ||
| 59 | - | ||
| 60 | - private: | ||
| 61 | - v8::TracingController* controller_; | ||
| 62 | - }; | ||
| 63 | - | ||
| 64 | 16 | struct V8Platform { | |
| 65 | 17 | bool initialized_ = false; | |
| 66 | 18 | ||
| 67 | 19 | #if NODE_USE_V8_PLATFORM | |
| 68 | 20 | inline void Initialize(int thread_pool_size) { | |
| 69 | 21 | CHECK(!initialized_); | |
| 70 | 22 | initialized_ = true; | |
| 71 | - tracing_agent_ = std::make_unique<tracing::Agent>(); | ||
| 72 | - node::tracing::TraceEventHelper::SetAgent(tracing_agent_.get()); | ||
| 73 | - node::tracing::TracingController* controller = | ||
| 74 | - tracing_agent_->GetTracingController(); | ||
| 75 | - trace_state_observer_ = | ||
| 76 | - std::make_unique<NodeTraceStateObserver>(controller); | ||
| 77 | - controller->AddTraceStateObserver(trace_state_observer_.get()); | ||
| 78 | - tracing_file_writer_ = tracing_agent_->DefaultHandle(); | ||
| 23 | + tracing_agent_ = tracing::Agent::CreateDefault(); | ||
| 79 | 24 | // Only start the tracing agent if we enabled any tracing categories. | |
| 80 | 25 | if (!per_process::cli_options->trace_event_categories.empty()) { | |
| 81 | 26 | StartTracingAgent(); | |
| 82 | 27 | } | |
| 83 | 28 | // Tracing must be initialized before platform threads are created. | |
| 84 | - platform_ = new NodePlatform(thread_pool_size, controller); | ||
| 29 | + platform_ = new NodePlatform(thread_pool_size, | ||
| 30 | + tracing_agent_->GetTracingController()); | ||
| 85 | 31 | v8::V8::InitializePlatform(platform_); | |
| 86 | 32 | } | |
| 87 | 33 | // Make sure V8Platform don not call into Libuv threadpool, | |
@@ -90,58 +36,33 @@ struct V8Platform { | |||
| 90 | 36 | if (!initialized_) | |
| 91 | 37 | return; | |
| 92 | 38 | initialized_ = false; | |
| 93 | - node::tracing::TraceEventHelper::SetAgent(nullptr); | ||
| 94 | 39 | StopTracingAgent(); | |
| 95 | 40 | platform_->Shutdown(); | |
| 96 | 41 | delete platform_; | |
| 97 | 42 | platform_ = nullptr; | |
| 98 | 43 | // Destroy tracing after the platform (and platform threads) have been | |
| 99 | 44 | // stopped. | |
| 100 | 45 | tracing_agent_.reset(nullptr); | |
| 101 | - // The observer remove itself in OnTraceEnabled | ||
| 102 | - trace_state_observer_.reset(nullptr); | ||
| 103 | 46 | } | |
| 104 | 47 | ||
| 105 | 48 | inline void DrainVMTasks(v8::Isolate* isolate) { | |
| 106 | 49 | platform_->DrainTasks(isolate); | |
| 107 | 50 | } | |
| 108 | 51 | ||
| 109 | 52 | inline void StartTracingAgent() { | |
| 110 | - constexpr auto convert_to_set = | ||
| 111 | - [](auto& categories) -> std::set<std::string> { | ||
| 112 | - std::set<std::string> out; | ||
| 113 | - for (const auto& s : categories) { | ||
| 114 | - out.emplace(std::string(s.data(), s.size())); | ||
| 115 | - } | ||
| 116 | - return out; | ||
| 117 | - }; | ||
| 118 | - // Attach a new NodeTraceWriter only if this function hasn't been called | ||
| 119 | - // before. | ||
| 120 | - if (tracing_file_writer_.IsDefaultHandle()) { | ||
| 121 | - using std::operator""sv; | ||
| 122 | - auto categories = std::views::split( | ||
| 123 | - per_process::cli_options->trace_event_categories, ","sv); | ||
| 124 | - | ||
| 125 | - tracing_file_writer_ = tracing_agent_->AddClient( | ||
| 126 | - convert_to_set(categories), | ||
| 127 | - std::unique_ptr<tracing::AsyncTraceWriter>( | ||
| 128 | - new tracing::NodeTraceWriter( | ||
| 129 | - per_process::cli_options->trace_event_file_pattern)), | ||
| 130 | - tracing::Agent::kUseDefaultCategories); | ||
| 131 | - } | ||
| 53 | + if (!initialized_) return; | ||
| 54 | + tracing_agent_->StartTracing( | ||
| 55 | + per_process::cli_options->trace_event_categories); | ||
| 132 | 56 | } | |
| 133 | 57 | ||
| 134 | - inline void StopTracingAgent() { tracing_file_writer_.reset(); } | ||
| 135 | - | ||
| 136 | - inline tracing::AgentWriterHandle* GetTracingAgentWriter() { | ||
| 137 | - return &tracing_file_writer_; | ||
| 58 | + inline void StopTracingAgent() { | ||
| 59 | + if (!initialized_) return; | ||
| 60 | + tracing_agent_->StopTracing(); | ||
| 138 | 61 | } | |
| 139 | 62 | ||
| 140 | 63 | inline NodePlatform* Platform() { return platform_; } | |
| 141 | 64 | ||
| 142 | - std::unique_ptr<NodeTraceStateObserver> trace_state_observer_; | ||
| 143 | - std::unique_ptr<tracing::Agent> tracing_agent_; | ||
| 144 | - tracing::AgentWriterHandle tracing_file_writer_; | ||
| 65 | + std::unique_ptr<tracing::Agent, tracing::Agent::Deleter> tracing_agent_; | ||
| 145 | 66 | NodePlatform* platform_; | |
| 146 | 67 | #else // !NODE_USE_V8_PLATFORM | |
| 147 | 68 | inline void Initialize(int thread_pool_size) {} | |
@@ -156,8 +77,6 @@ struct V8Platform { | |||
| 156 | 77 | } | |
| 157 | 78 | inline void StopTracingAgent() {} | |
| 158 | 79 | ||
| 159 | - inline tracing::AgentWriterHandle* GetTracingAgentWriter() { return nullptr; } | ||
| 160 | - | ||
| 161 | 80 | inline NodePlatform* Platform() { return nullptr; } | |
| 162 | 81 | #endif // !NODE_USE_V8_PLATFORM | |
| 163 | 82 | }; | |
@@ -166,14 +85,6 @@ namespace per_process { | |||
| 166 | 85 | extern struct V8Platform v8_platform; | |
| 167 | 86 | } | |
| 168 | 87 | ||
| 169 | - inline void StartTracingAgent() { | ||
| 170 | - return per_process::v8_platform.StartTracingAgent(); | ||
| 171 | - } | ||
| 172 | - | ||
| 173 | - inline tracing::AgentWriterHandle* GetTracingAgentWriter() { | ||
| 174 | - return per_process::v8_platform.GetTracingAgentWriter(); | ||
| 175 | - } | ||
| 176 | - | ||
| 177 | 88 | inline void DisposePlatform() { | |
| 178 | 89 | per_process::v8_platform.Dispose(); | |
| 179 | 90 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments