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

Side by Side Diff: base/trace_event/heap_profiler_stack_frame_deduplicator.cc

Issue 2514913002: [tracing] Use EstimateMemoryUsage() in deduplicators. (Closed)
Patch Set: git cl format Created 4 years 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" 5 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "base/trace_event/memory_usage_estimator.h"
14 #include "base/trace_event/trace_event_argument.h" 15 #include "base/trace_event/trace_event_argument.h"
15 #include "base/trace_event/trace_event_memory_overhead.h" 16 #include "base/trace_event/trace_event_memory_overhead.h"
16 17
17 namespace base { 18 namespace base {
18 namespace trace_event { 19 namespace trace_event {
19 20
20 StackFrameDeduplicator::FrameNode::FrameNode(StackFrame frame, 21 StackFrameDeduplicator::FrameNode::FrameNode(StackFrame frame,
21 int parent_frame_index) 22 int parent_frame_index)
22 : frame(frame), parent_frame_index(parent_frame_index) {} 23 : frame(frame), parent_frame_index(parent_frame_index) {}
23 StackFrameDeduplicator::FrameNode::FrameNode(const FrameNode& other) = default; 24 StackFrameDeduplicator::FrameNode::FrameNode(const FrameNode& other) = default;
24 StackFrameDeduplicator::FrameNode::~FrameNode() {} 25 StackFrameDeduplicator::FrameNode::~FrameNode() {}
25 26
27 size_t StackFrameDeduplicator::FrameNode::EstimateMemoryUsage() const {
28 return base::trace_event::EstimateMemoryUsage(children);
29 }
30
26 StackFrameDeduplicator::StackFrameDeduplicator() {} 31 StackFrameDeduplicator::StackFrameDeduplicator() {}
27 StackFrameDeduplicator::~StackFrameDeduplicator() {} 32 StackFrameDeduplicator::~StackFrameDeduplicator() {}
28 33
29 int StackFrameDeduplicator::Insert(const StackFrame* beginFrame, 34 int StackFrameDeduplicator::Insert(const StackFrame* beginFrame,
30 const StackFrame* endFrame) { 35 const StackFrame* endFrame) {
31 int frame_index = -1; 36 int frame_index = -1;
32 std::map<StackFrame, int>* nodes = &roots_; 37 std::map<StackFrame, int>* nodes = &roots_;
33 38
34 // Loop through the frames, early out when a frame is null. 39 // Loop through the frames, early out when a frame is null.
35 for (const StackFrame* it = beginFrame; it != endFrame; it++) { 40 for (const StackFrame* it = beginFrame; it != endFrame; it++) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 114
110 if (frame_node != it_end) 115 if (frame_node != it_end)
111 out->append(","); 116 out->append(",");
112 } 117 }
113 118
114 out->append("}"); // End the |stackFrames| dictionary. 119 out->append("}"); // End the |stackFrames| dictionary.
115 } 120 }
116 121
117 void StackFrameDeduplicator::EstimateTraceMemoryOverhead( 122 void StackFrameDeduplicator::EstimateTraceMemoryOverhead(
118 TraceEventMemoryOverhead* overhead) { 123 TraceEventMemoryOverhead* overhead) {
119 // The sizes here are only estimates; they fail to take into account the 124 size_t memory_usage =
120 // overhead of the tree nodes for the map, but as an estimate this should be 125 EstimateMemoryUsage(frames_) + EstimateMemoryUsage(roots_);
121 // fine.
122 size_t maps_size = roots_.size() * sizeof(std::pair<StackFrame, int>);
123 size_t frames_allocated = frames_.capacity() * sizeof(FrameNode);
124 size_t frames_resident = frames_.size() * sizeof(FrameNode);
125
126 for (const FrameNode& node : frames_)
127 maps_size += node.children.size() * sizeof(std::pair<StackFrame, int>);
128
129 overhead->Add("StackFrameDeduplicator", 126 overhead->Add("StackFrameDeduplicator",
130 sizeof(StackFrameDeduplicator) + maps_size + frames_allocated, 127 sizeof(StackFrameDeduplicator) + memory_usage);
131 sizeof(StackFrameDeduplicator) + maps_size + frames_resident);
132 } 128 }
133 129
134 } // namespace trace_event 130 } // namespace trace_event
135 } // namespace base 131 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/heap_profiler_stack_frame_deduplicator.h ('k') | base/trace_event/heap_profiler_type_name_deduplicator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698