| 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 49a235051c0731fd930bd7a897fc793cb867ab40..4c283093b014f911f8db5d7925bdfaaebefa5bb6 100644
|
| --- a/base/trace_event/heap_profiler_stack_frame_deduplicator.cc
|
| +++ b/base/trace_event/heap_profiler_stack_frame_deduplicator.cc
|
| @@ -19,7 +19,7 @@ namespace trace_event {
|
|
|
| StackFrameDeduplicator::FrameNode::FrameNode(StackFrame frame,
|
| int parent_frame_index)
|
| - : frame(frame), parent_frame_index(parent_frame_index) {}
|
| + : frame(frame), parent_frame_index(parent_frame_index), indexed(false) {}
|
| StackFrameDeduplicator::FrameNode::FrameNode(const FrameNode& other) = default;
|
| StackFrameDeduplicator::FrameNode::~FrameNode() {}
|
|
|
| @@ -59,10 +59,82 @@ int StackFrameDeduplicator::Insert(const StackFrame* beginFrame,
|
| nodes = &frames_[frame_index].children;
|
| }
|
|
|
| + if (frame_index != -1) {
|
| + frames_[frame_index].indexed = true;
|
| + }
|
| +
|
| return frame_index;
|
| }
|
|
|
| void StackFrameDeduplicator::AppendAsTraceFormat(std::string* out) const {
|
| +#if defined(NEW_TRACE_FORMAT)
|
| + std::string stringify_buffer;
|
| + std::unique_ptr<TracedValue> traced_value(new TracedValue);
|
| +
|
| + std::map<StackFrame, size_t> unique_frame_indexes;
|
| + traced_value->BeginDictionary("hierarchy");
|
| + {
|
| + std::function<void(const std::map<StackFrame, int>&)> append_level =
|
| + [&](const std::map<StackFrame, int>& level) {
|
| + for (const auto& frame_and_index: level) {
|
| + int node_index = frame_and_index.second;
|
| + const FrameNode& node = frames_[node_index];
|
| +
|
| + size_t unique_index = unique_frame_indexes.insert(
|
| + {node.frame, unique_frame_indexes.size()}).first->second;
|
| + SStringPrintf(&stringify_buffer, "%zu", unique_index);
|
| + traced_value->BeginDictionaryWithCopiedName(stringify_buffer);
|
| +
|
| + if (node.indexed) {
|
| + SStringPrintf(&stringify_buffer, "%d", node_index);
|
| + traced_value->SetString("bt", stringify_buffer);
|
| + }
|
| +
|
| + append_level(node.children);
|
| +
|
| + traced_value->EndDictionary();
|
| + }
|
| + };
|
| +
|
| + append_level(roots_);
|
| + }
|
| + traced_value->EndDictionary();
|
| +
|
| + traced_value->BeginArray("names");
|
| + {
|
| + std::vector<StackFrame> unique_frames;
|
| + unique_frames.resize(unique_frame_indexes.size());
|
| + for (const auto& frame_and_index: unique_frame_indexes) {
|
| + DCHECK(frame_and_index.second < unique_frames.size());
|
| + unique_frames[frame_and_index.second] = frame_and_index.first;
|
| + }
|
| + for (const auto& frame: unique_frames) {
|
| + switch (frame.type) {
|
| + case StackFrame::Type::TRACE_EVENT_NAME:
|
| + traced_value->AppendString(static_cast<const char*>(frame.value));
|
| + break;
|
| + case StackFrame::Type::THREAD_NAME:
|
| + SStringPrintf(&stringify_buffer,
|
| + "[Thread: %s]",
|
| + static_cast<const char*>(frame.value));
|
| + traced_value->AppendString(stringify_buffer);
|
| + break;
|
| + case StackFrame::Type::PROGRAM_COUNTER:
|
| + SStringPrintf(&stringify_buffer,
|
| + "pc:%" PRIxPTR,
|
| + reinterpret_cast<uintptr_t>(frame.value));
|
| + traced_value->AppendString(stringify_buffer);
|
| + break;
|
| + }
|
| + }
|
| + }
|
| + traced_value->EndArray();
|
| +
|
| + std::string trace;
|
| + traced_value->AppendAsTraceFormat(out);
|
| +
|
| +#else // !defined(NEW_TRACE_FORMAT)
|
| +
|
| out->append("{"); // Begin the |stackFrames| dictionary.
|
|
|
| int i = 0;
|
| @@ -112,6 +184,8 @@ void StackFrameDeduplicator::AppendAsTraceFormat(std::string* out) const {
|
| }
|
|
|
| out->append("}"); // End the |stackFrames| dictionary.
|
| +
|
| +#endif // defined(NEW_TRACE_FORMAT)
|
| }
|
|
|
| void StackFrameDeduplicator::EstimateTraceMemoryOverhead(
|
|
|