Commit ea1fd31a authored by dskiba's avatar dskiba Committed by Commit bot

[tracing] Use EstimateMemoryUsage() in deduplicators.

Both type name and stack deduplicators need to estimate their memory
overhead. Previously they were using simplistic models and estimated
only half of their actual memory usage. This CL changes estimation
methods to use EstimateMemoryUsage(), resulting in better accuracy.

Review-Url: https://codereview.chromium.org/2514913002
Cr-Commit-Position: refs/heads/master@{#434728}
parent d94cd17e
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <utility> #include <utility>
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/trace_event/memory_usage_estimator.h"
#include "base/trace_event/trace_event_argument.h" #include "base/trace_event/trace_event_argument.h"
#include "base/trace_event/trace_event_memory_overhead.h" #include "base/trace_event/trace_event_memory_overhead.h"
...@@ -23,6 +24,10 @@ StackFrameDeduplicator::FrameNode::FrameNode(StackFrame frame, ...@@ -23,6 +24,10 @@ StackFrameDeduplicator::FrameNode::FrameNode(StackFrame frame,
StackFrameDeduplicator::FrameNode::FrameNode(const FrameNode& other) = default; StackFrameDeduplicator::FrameNode::FrameNode(const FrameNode& other) = default;
StackFrameDeduplicator::FrameNode::~FrameNode() {} StackFrameDeduplicator::FrameNode::~FrameNode() {}
size_t StackFrameDeduplicator::FrameNode::EstimateMemoryUsage() const {
return base::trace_event::EstimateMemoryUsage(children);
}
StackFrameDeduplicator::StackFrameDeduplicator() {} StackFrameDeduplicator::StackFrameDeduplicator() {}
StackFrameDeduplicator::~StackFrameDeduplicator() {} StackFrameDeduplicator::~StackFrameDeduplicator() {}
...@@ -116,19 +121,10 @@ void StackFrameDeduplicator::AppendAsTraceFormat(std::string* out) const { ...@@ -116,19 +121,10 @@ void StackFrameDeduplicator::AppendAsTraceFormat(std::string* out) const {
void StackFrameDeduplicator::EstimateTraceMemoryOverhead( void StackFrameDeduplicator::EstimateTraceMemoryOverhead(
TraceEventMemoryOverhead* overhead) { TraceEventMemoryOverhead* overhead) {
// The sizes here are only estimates; they fail to take into account the size_t memory_usage =
// overhead of the tree nodes for the map, but as an estimate this should be EstimateMemoryUsage(frames_) + EstimateMemoryUsage(roots_);
// fine.
size_t maps_size = roots_.size() * sizeof(std::pair<StackFrame, int>);
size_t frames_allocated = frames_.capacity() * sizeof(FrameNode);
size_t frames_resident = frames_.size() * sizeof(FrameNode);
for (const FrameNode& node : frames_)
maps_size += node.children.size() * sizeof(std::pair<StackFrame, int>);
overhead->Add("StackFrameDeduplicator", overhead->Add("StackFrameDeduplicator",
sizeof(StackFrameDeduplicator) + maps_size + frames_allocated, sizeof(StackFrameDeduplicator) + memory_usage);
sizeof(StackFrameDeduplicator) + maps_size + frames_resident);
} }
} // namespace trace_event } // namespace trace_event
......
...@@ -34,6 +34,8 @@ class BASE_EXPORT StackFrameDeduplicator : public ConvertableToTraceFormat { ...@@ -34,6 +34,8 @@ class BASE_EXPORT StackFrameDeduplicator : public ConvertableToTraceFormat {
FrameNode(const FrameNode& other); FrameNode(const FrameNode& other);
~FrameNode(); ~FrameNode();
size_t EstimateMemoryUsage() const;
StackFrame frame; StackFrame frame;
// The index of the parent stack frame in |frames_|, or -1 if there is no // The index of the parent stack frame in |frames_|, or -1 if there is no
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/json/string_escape.h" #include "base/json/string_escape.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/trace_event/memory_usage_estimator.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_event_memory_overhead.h" #include "base/trace_event/trace_event_memory_overhead.h"
...@@ -105,12 +106,9 @@ void TypeNameDeduplicator::AppendAsTraceFormat(std::string* out) const { ...@@ -105,12 +106,9 @@ void TypeNameDeduplicator::AppendAsTraceFormat(std::string* out) const {
void TypeNameDeduplicator::EstimateTraceMemoryOverhead( void TypeNameDeduplicator::EstimateTraceMemoryOverhead(
TraceEventMemoryOverhead* overhead) { TraceEventMemoryOverhead* overhead) {
// The size here is only an estimate; it fails to take into account the size size_t memory_usage = EstimateMemoryUsage(type_ids_);
// of the tree nodes for the map, but as an estimate this should be fine.
size_t map_size = type_ids_.size() * sizeof(std::pair<const char*, int>);
overhead->Add("TypeNameDeduplicator", overhead->Add("TypeNameDeduplicator",
sizeof(TypeNameDeduplicator) + map_size); sizeof(TypeNameDeduplicator) + memory_usage);
} }
} // namespace trace_event } // namespace trace_event
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment