summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorprimiano <primiano@chromium.org>2015-06-11 14:40:10 -0700
committerCommit bot <commit-bot@chromium.org>2015-06-11 21:40:57 +0000
commit9882cf349a569b8a25041fe77e2ed38a63c1307f (patch)
treeb92e2c7aa3a942590e7b5d685ecea2d0fce5f073
parent21b01f101388377240d2fa780c04ca41a9e11524 (diff)
downloadchromium_src-9882cf349a569b8a25041fe77e2ed38a63c1307f.zip
chromium_src-9882cf349a569b8a25041fe77e2ed38a63c1307f.tar.gz
chromium_src-9882cf349a569b8a25041fe77e2ed38a63c1307f.tar.bz2
Add a Pickle::GetTotalAllocatedSize() to estimate its memory usage
Add a method to query the allocated memory size of a pickle. The driving motivation for this is to estimate the memory used by the chrome tracing infrastructure (which uses pickles under the hod) in order to discount the tracing overhead from the actual memory used by Chrome. BUG=495628 Review URL: https://codereview.chromium.org/1179693008 Cr-Commit-Position: refs/heads/master@{#334040}
-rw-r--r--base/pickle.cc12
-rw-r--r--base/pickle.h8
-rw-r--r--base/trace_event/trace_event_argument.cc2
3 files changed, 16 insertions, 6 deletions
diff --git a/base/pickle.cc b/base/pickle.cc
index 09d42c9..cf4a865 100644
--- a/base/pickle.cc
+++ b/base/pickle.cc
@@ -317,13 +317,17 @@ void Pickle::Reserve(size_t length) {
}
void Pickle::Resize(size_t new_capacity) {
- new_capacity = AlignInt(new_capacity, kPayloadUnit);
-
CHECK_NE(capacity_after_header_, kCapacityReadOnly);
- void* p = realloc(header_, header_size_ + new_capacity);
+ capacity_after_header_ = AlignInt(new_capacity, kPayloadUnit);
+ void* p = realloc(header_, GetTotalAllocatedSize());
CHECK(p);
header_ = reinterpret_cast<Header*>(p);
- capacity_after_header_ = new_capacity;
+}
+
+size_t Pickle::GetTotalAllocatedSize() const {
+ if (capacity_after_header_ == kCapacityReadOnly)
+ return 0;
+ return header_size_ + capacity_after_header_;
}
// static
diff --git a/base/pickle.h b/base/pickle.h
index 7a6b0c8..c9fef71 100644
--- a/base/pickle.h
+++ b/base/pickle.h
@@ -153,12 +153,18 @@ class BASE_EXPORT Pickle {
// Performs a deep copy.
Pickle& operator=(const Pickle& other);
- // Returns the size of the Pickle's data.
+ // Returns the number of bytes written in the Pickle, including the header.
size_t size() const { return header_size_ + header_->payload_size; }
// Returns the data for this Pickle.
const void* data() const { return header_; }
+ // Returns the effective memory capacity of this Pickle, that is, the total
+ // number of bytes currently dynamically allocated or 0 in the case of a
+ // read-only Pickle. This should be used only for diagnostic / profiling
+ // purposes.
+ size_t GetTotalAllocatedSize() const;
+
// Methods for adding to the payload of the Pickle. These values are
// appended to the end of the Pickle's payload. When reading values from a
// Pickle, it is important to read them in the order in which they were added
diff --git a/base/trace_event/trace_event_argument.cc b/base/trace_event/trace_event_argument.cc
index 37df6ef..14504ac 100644
--- a/base/trace_event/trace_event_argument.cc
+++ b/base/trace_event/trace_event_argument.cc
@@ -453,7 +453,7 @@ void TracedValue::AppendAsTraceFormat(std::string* out) const {
void TracedValue::EstimateTraceMemoryOverhead(
TraceEventMemoryOverhead* overhead) {
- overhead->Add("TracedValue", pickle_.size());
+ overhead->Add("TracedValue", pickle_.GetTotalAllocatedSize());
}
} // namespace trace_event