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...
Showing
with
4 additions
and
6 deletions.
-
+3
−5
src/tracing/node_trace_writer.cc
-
+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