Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1163)

Unified Diff: base/trace_event/heap_profiler_stack_frame_deduplicator.cc

Issue 2052803002: Alternative heap dumping scheme. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: New stackFrames format Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/trace_event/heap_profiler_stack_frame_deduplicator.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(
« no previous file with comments | « base/trace_event/heap_profiler_stack_frame_deduplicator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698