Skip to content

Commit

Permalink
src: use unique_ptr for internal JSON trace writer
Browse files Browse the repository at this point in the history
PR-URL: #21867
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
  • Loading branch information
addaleax authored and targos committed Aug 1, 2018
1 parent ce48936 commit 6b58746
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions src/tracing/node_trace_writer.cc
Expand Up @@ -37,9 +37,7 @@ void NodeTraceWriter::WriteSuffix() {
{
Mutex::ScopedLock scoped_lock(stream_mutex_);
if (total_traces_ > 0) {
total_traces_ = 0; // so we don't write it again in FlushPrivate
// Appends "]}" to stream_.
delete json_trace_writer_;
total_traces_ = kTracesPerFile; // Act as if we reached the file limit.
should_flush = true;
}
}
Expand Down Expand Up @@ -111,7 +109,7 @@ void NodeTraceWriter::AppendTraceEvent(TraceObject* trace_event) {
// to a state where we can start writing trace events to it.
// Repeatedly constructing and destroying json_trace_writer_ allows
// us to use V8's JSON writer instead of implementing our own.
json_trace_writer_ = TraceWriter::CreateJSONTraceWriter(stream_);
json_trace_writer_.reset(TraceWriter::CreateJSONTraceWriter(stream_));
}
++total_traces_;
json_trace_writer_->AppendTraceEvent(trace_event);
Expand All @@ -126,7 +124,7 @@ void NodeTraceWriter::FlushPrivate() {
total_traces_ = 0;
// Destroying the member JSONTraceWriter object appends "]}" to
// stream_ - in other words, ending a JSON file.
delete json_trace_writer_;
json_trace_writer_.reset();
}
// str() makes a copy of the contents of the stream.
str = stream_.str();
Expand Down
2 changes: 1 addition & 1 deletion src/tracing/node_trace_writer.h
Expand Up @@ -63,7 +63,7 @@ class NodeTraceWriter : public AsyncTraceWriter {
int file_num_ = 0;
const std::string& log_file_pattern_;
std::ostringstream stream_;
TraceWriter* json_trace_writer_ = nullptr;
std::unique_ptr<TraceWriter> json_trace_writer_;
bool exited_ = false;
};

Expand Down

0 comments on commit 6b58746

Please sign in to comment.