diff --git a/node.gyp b/node.gyp index 20167458d4c5ef..c12fb4c0cf79f4 100644 --- a/node.gyp +++ b/node.gyp @@ -234,6 +234,9 @@ 'src/stream_base.h', 'src/stream_base-inl.h', 'src/stream_wrap.h', + 'src/tracing/agent.h', + 'src/tracing/node_trace_buffer.h', + 'src/tracing/node_trace_writer.h', 'src/tracing/trace_event.h' 'src/tree.h', 'src/util.h', diff --git a/src/node.h b/src/node.h index 24ebce87c8fdfc..1255a4af7f11ce 100644 --- a/src/node.h +++ b/src/node.h @@ -41,7 +41,6 @@ #include "v8.h" // NOLINT(build/include_order) #include "node_version.h" // NODE_MODULE_VERSION -#include "tracing/trace_event.h" #define NODE_MAKE_VERSION(major, minor, patch) \ ((major) * 0x1000 + (minor) * 0x100 + (patch)) diff --git a/src/node_internals.h b/src/node_internals.h index b68594162b8ab8..156d934d0ec004 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -8,6 +8,7 @@ #include "util-inl.h" #include "uv.h" #include "v8.h" +#include "tracing/trace_event.h" #include #include diff --git a/src/tracing/agent.cc b/src/tracing/agent.cc index 97a3e11a2c458c..ceab09e5a2789c 100644 --- a/src/tracing/agent.cc +++ b/src/tracing/agent.cc @@ -56,7 +56,9 @@ void Agent::Stop() { // 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(); - delete tracing_controller_; + tracing_controller_->Initialize(nullptr); + tracing_controller_ = nullptr; + // Thread should finish when the tracing loop is stopped. uv_thread_join(&thread_); v8::platform::SetTracingController(platform_, nullptr); diff --git a/src/tracing/agent.h b/src/tracing/agent.h index 098f955192e0cf..f6cb5af97f4bbc 100644 --- a/src/tracing/agent.h +++ b/src/tracing/agent.h @@ -22,7 +22,7 @@ class Agent { uv_thread_t thread_; uv_loop_t tracing_loop_; v8::Platform* platform_ = nullptr; - TracingController* tracing_controller_; + TracingController* tracing_controller_ = nullptr; }; } // namespace tracing diff --git a/src/tracing/node_trace_buffer.cc b/src/tracing/node_trace_buffer.cc index 4773e08325a3ef..4e99361cbefee3 100644 --- a/src/tracing/node_trace_buffer.cc +++ b/src/tracing/node_trace_buffer.cc @@ -4,9 +4,9 @@ namespace node { namespace tracing { InternalTraceBuffer::InternalTraceBuffer(size_t max_chunks, uint32_t id, - NodeTraceWriter* trace_writer, NodeTraceBuffer* external_buffer) - : id_(id), flushing_(false), max_chunks_(max_chunks), - trace_writer_(trace_writer), external_buffer_(external_buffer) { + NodeTraceWriter* trace_writer) + : flushing_(false), max_chunks_(max_chunks), + trace_writer_(trace_writer), id_(id) { chunks_.resize(max_chunks); } @@ -89,8 +89,8 @@ void InternalTraceBuffer::ExtractHandle( NodeTraceBuffer::NodeTraceBuffer(size_t max_chunks, NodeTraceWriter* trace_writer, uv_loop_t* tracing_loop) : tracing_loop_(tracing_loop), trace_writer_(trace_writer), - buffer1_(max_chunks, 0, trace_writer, this), - buffer2_(max_chunks, 1, trace_writer, this) { + buffer1_(max_chunks, 0, trace_writer), + buffer2_(max_chunks, 1, trace_writer) { current_buf_.store(&buffer1_); flush_signal_.data = this; diff --git a/src/tracing/node_trace_buffer.h b/src/tracing/node_trace_buffer.h index 619799fdb21978..296c958b80e3fa 100644 --- a/src/tracing/node_trace_buffer.h +++ b/src/tracing/node_trace_buffer.h @@ -20,8 +20,7 @@ class NodeTraceBuffer; class InternalTraceBuffer { public: InternalTraceBuffer(size_t max_chunks, uint32_t id, - NodeTraceWriter* trace_writer, - NodeTraceBuffer* external_buffer); + NodeTraceWriter* trace_writer); TraceObject* AddTraceEvent(uint64_t* handle); TraceObject* GetEventByHandle(uint64_t handle); @@ -44,7 +43,6 @@ class InternalTraceBuffer { bool flushing_; size_t max_chunks_; NodeTraceWriter* trace_writer_; - NodeTraceBuffer* external_buffer_; std::vector> chunks_; size_t total_chunks_ = 0; uint32_t current_chunk_seq_ = 1; diff --git a/test/parallel/test-trace-event.js b/test/parallel/test-trace-event.js index 18734705834407..fde718d7bc06fb 100644 --- a/test/parallel/test-trace-event.js +++ b/test/parallel/test-trace-event.js @@ -21,15 +21,19 @@ proc_no_categories.once('exit', common.mustCall(() => { proc.once('exit', common.mustCall(() => { assert(common.fileExists(FILE_NAME)); - fs.readFile(FILE_NAME, (err, data) => { + fs.readFile(FILE_NAME, common.mustCall((err, data) => { const traces = JSON.parse(data.toString()).traceEvents; assert(traces.length > 0); // Values that should be present on all runs to approximate correctness. - assert(traces.some((trace) => { return trace.pid === proc.pid; })); - assert(traces.some((trace) => { return trace.cat === 'v8'; })); assert(traces.some((trace) => { - return trace.name === 'V8.ScriptCompiler'; + if (trace.pid !== proc.pid) + return false; + if (trace.cat !== 'v8') + return false; + if (trace.name !== 'V8.ScriptCompiler') + return false; + return true; })); - }); + })); })); }));