Chromium Code Reviews| Index: base/trace_event/heap_profiler_stack_frame_deduplicator.cc |
| diff --git a/base/trace_event/heap_profiler_stack_frame_deduplicator.cc b/base/trace_event/heap_profiler_stack_frame_deduplicator.cc |
| index fc5da0d1dde9ed15498e1d03574d737c5f004460..d565aaab4c9935e169fd9670b9a1a58f355b86f9 100644 |
| --- a/base/trace_event/heap_profiler_stack_frame_deduplicator.cc |
| +++ b/base/trace_event/heap_profiler_stack_frame_deduplicator.cc |
| @@ -28,7 +28,7 @@ size_t StackFrameDeduplicator::FrameNode::EstimateMemoryUsage() const { |
| return base::trace_event::EstimateMemoryUsage(children); |
| } |
| -StackFrameDeduplicator::StackFrameDeduplicator() {} |
| +StackFrameDeduplicator::StackFrameDeduplicator() : last_appended_index_(0) {} |
| StackFrameDeduplicator::~StackFrameDeduplicator() {} |
| int StackFrameDeduplicator::Insert(const StackFrame* beginFrame, |
| @@ -67,56 +67,40 @@ int StackFrameDeduplicator::Insert(const StackFrame* beginFrame, |
| return frame_index; |
| } |
| -void StackFrameDeduplicator::AppendAsTraceFormat(std::string* out) const { |
| - out->append("{"); // Begin the |stackFrames| dictionary. |
| - |
| - int i = 0; |
| - auto frame_node = begin(); |
| - auto it_end = end(); |
| +void StackFrameDeduplicator::AppendIncrementally(TracedValue* traced_value) { |
| std::string stringify_buffer; |
| - while (frame_node != it_end) { |
| - // The |stackFrames| format is a dictionary, not an array, so the |
| - // keys are stringified indices. Write the index manually, then use |
| - // |TracedValue| to format the object. This is to avoid building the |
| - // entire dictionary as a |TracedValue| in memory. |
| - SStringPrintf(&stringify_buffer, "\"%d\":", i); |
| - out->append(stringify_buffer); |
| + for (; last_appended_index_ < frames_.size(); ++last_appended_index_) { |
| + const auto& frame_node = frames_[last_appended_index_]; |
| + traced_value->BeginDictionary(); |
| + |
| + traced_value->SetInteger("id", last_appended_index_); |
| - std::unique_ptr<TracedValue> frame_node_value(new TracedValue); |
| - const StackFrame& frame = frame_node->frame; |
| + const StackFrame& frame = frame_node.frame; |
| switch (frame.type) { |
| case StackFrame::Type::TRACE_EVENT_NAME: |
| - frame_node_value->SetString( |
| - "name", static_cast<const char*>(frame.value)); |
| + traced_value->SetString("name", static_cast<const char*>(frame.value)); |
| break; |
| case StackFrame::Type::THREAD_NAME: |
| SStringPrintf(&stringify_buffer, |
| "[Thread: %s]", |
| static_cast<const char*>(frame.value)); |
| - frame_node_value->SetString("name", stringify_buffer); |
| + traced_value->SetString("name", stringify_buffer); |
| break; |
| case StackFrame::Type::PROGRAM_COUNTER: |
| SStringPrintf(&stringify_buffer, |
| "pc:%" PRIxPTR, |
| reinterpret_cast<uintptr_t>(frame.value)); |
| - frame_node_value->SetString("name", stringify_buffer); |
| + traced_value->SetString("name", stringify_buffer); |
| break; |
| } |
| - if (frame_node->parent_frame_index >= 0) { |
| - SStringPrintf(&stringify_buffer, "%d", frame_node->parent_frame_index); |
| - frame_node_value->SetString("parent", stringify_buffer); |
| - } |
| - frame_node_value->AppendAsTraceFormat(out); |
| - i++; |
| - frame_node++; |
| + if (frame_node.parent_frame_index >= 0) { |
| + traced_value->SetInteger("parent", frame_node.parent_frame_index); |
|
Primiano Tucci (use gerrit)
2017/02/17 17:07:05
do we have the guarantee that the parent is always
DmitrySkiba
2017/02/23 07:17:19
Yes, because we dump nodes_ sequentially, and in t
|
| + } |
| - if (frame_node != it_end) |
| - out->append(","); |
| + traced_value->EndDictionary(); |
| } |
| - |
| - out->append("}"); // End the |stackFrames| dictionary. |
| } |
| void StackFrameDeduplicator::EstimateTraceMemoryOverhead( |