★ wanayoo — archive 1999 https://github.com/nodejs/node/commit/6b58746b2eNouvelle recherche | Portail wanayoo
Skip to content
Permalink
Browse files

src: use unique_ptr for internal JSON trace writer

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 Jul 18, 2018
1 parent ce48936 commit 6b58746b2e78aae4ea3c68db84bd516184b52708
Showing with 4 additions and 6 deletions.
  1. +3 −5 src/tracing/node_trace_writer.cc
  2. +1 −1 src/tracing/node_trace_writer.h
@@ -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;
}
}
@@ -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);
@@ -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();
@@ -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;
};

0 comments on commit 6b58746

Please sign in to comment.
You can’t perform that action at this time.