Skip to content
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

v7.x: cherry-pick tracing related fixes #11634

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 0 additions & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions src/node_internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "util-inl.h"
#include "uv.h"
#include "v8.h"
#include "tracing/trace_event.h"

#include <stdint.h>
#include <stdlib.h>
Expand Down
4 changes: 3 additions & 1 deletion src/tracing/agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/tracing/node_trace_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/tracing/node_trace_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -44,7 +43,6 @@ class InternalTraceBuffer {
bool flushing_;
size_t max_chunks_;
NodeTraceWriter* trace_writer_;
NodeTraceBuffer* external_buffer_;
std::vector<std::unique_ptr<TraceBufferChunk>> chunks_;
size_t total_chunks_ = 0;
uint32_t current_chunk_seq_ = 1;
Expand Down
14 changes: 9 additions & 5 deletions test/parallel/test-trace-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}));
});
}));
}));
}));