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

tracing: Fix some race conditions #22812

Closed
wants to merge 2 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
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.9',
'v8_embedder_string': '-node.10',

# Enable disassembler for `--print-code` v8 options
'v8_enable_disassembler': 1,
Expand Down
32 changes: 18 additions & 14 deletions deps/v8/src/libplatform/tracing/tracing-controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ uint64_t TracingController::AddTraceEvent(
const uint64_t* arg_values,
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
unsigned int flags) {
uint64_t handle;
TraceObject* trace_object = trace_buffer_->AddTraceEvent(&handle);
if (trace_object) {
trace_object->Initialize(
phase, category_enabled_flag, name, scope, id, bind_id, num_args,
arg_names, arg_types, arg_values, arg_convertables, flags,
CurrentTimestampMicroseconds(), CurrentCpuTimestampMicroseconds());
uint64_t handle = 0;
if (mode_ != DISABLED) {
TraceObject* trace_object = trace_buffer_->AddTraceEvent(&handle);
if (trace_object) {
trace_object->Initialize(
phase, category_enabled_flag, name, scope, id, bind_id, num_args,
arg_names, arg_types, arg_values, arg_convertables, flags,
CurrentTimestampMicroseconds(), CurrentCpuTimestampMicroseconds());
}
}
return handle;
}
Expand All @@ -81,13 +83,15 @@ uint64_t TracingController::AddTraceEventWithTimestamp(
const uint64_t* arg_values,
std::unique_ptr<v8::ConvertableToTraceFormat>* arg_convertables,
unsigned int flags, int64_t timestamp) {
uint64_t handle;
TraceObject* trace_object = trace_buffer_->AddTraceEvent(&handle);
if (trace_object) {
trace_object->Initialize(phase, category_enabled_flag, name, scope, id,
bind_id, num_args, arg_names, arg_types,
arg_values, arg_convertables, flags, timestamp,
CurrentCpuTimestampMicroseconds());
uint64_t handle = 0;
if (mode_ != DISABLED) {
TraceObject* trace_object = trace_buffer_->AddTraceEvent(&handle);
if (trace_object) {
trace_object->Initialize(phase, category_enabled_flag, name, scope, id,
bind_id, num_args, arg_names, arg_types,
arg_values, arg_convertables, flags, timestamp,
CurrentCpuTimestampMicroseconds());
}
}
return handle;
}
Expand Down
8 changes: 7 additions & 1 deletion src/tracing/node_trace_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ void InternalTraceBuffer::Flush(bool blocking) {
for (size_t i = 0; i < total_chunks_; ++i) {
auto& chunk = chunks_[i];
for (size_t j = 0; j < chunk->size(); ++j) {
agent_->AppendTraceEvent(chunk->GetEventAt(j));
TraceObject* trace_event = chunk->GetEventAt(j);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not auto?

Copy link
Member

@addaleax addaleax Sep 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tend to avoid auto, except for cases where the type is hard to spell out (e.g. STL iterator types/dependent on templating), or long and easy to infer (e.g. auto foo = new VeryLongClassName();). Using auto means spending more time writing the code, but more time reading it, and Node.js code is typically read a lot more than it is written.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it's time for that to change (ES.11).
Beside using the CCG to not bikeshed, for me as a reader TraceObject* is as opaque as auto, that why we have IDEs.

// Another thread may have added a trace that is yet to be
// initialized. Skip such traces.
// https://github.com/nodejs/node/issues/21038.
if (trace_event->name()) {
agent_->AppendTraceEvent(trace_event);
}
}
}
total_chunks_ = 0;
Expand Down