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

Unified Diff: components/sync/syncable/entry_kernel.cc

Issue 2837513002: [sync] Properly estimate EntryKernel memory usage. (Closed)
Patch Set: Created 3 years, 8 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/sync/syncable/entry_kernel.cc
diff --git a/components/sync/syncable/entry_kernel.cc b/components/sync/syncable/entry_kernel.cc
index 591ef927065b2ff68a849edabda2fb7c2c6992f6..383d04cb08eb419f8e04eaf81048519713d34db9 100644
--- a/components/sync/syncable/entry_kernel.cc
+++ b/components/sync/syncable/entry_kernel.cc
@@ -149,6 +149,21 @@ base::Value* AttachmentMetadataToValue(const sync_pb::AttachmentMetadata& a) {
return new base::Value(a.SerializeAsString());
}
+// Estimates memory usage of ProtoValuePtr<T> arrays where consecutive
+// elements can share the same value.
+template <class T, size_t N>
+size_t EstimateSharedMemoryUsage(ProtoValuePtr<T> const (&ptrs)[N]) {
+ size_t memory_usage = 0;
+ const T* last_value = nullptr;
+ for (const auto& ptr : ptrs) {
+ if (last_value != &ptr.value()) {
+ memory_usage += EstimateMemoryUsage(ptr);
+ last_value = &ptr.value();
+ }
+ }
+ return memory_usage;
+}
+
} // namespace
base::DictionaryValue* EntryKernel::ToValue(
@@ -216,10 +231,10 @@ size_t EntryKernel::EstimateMemoryUsage() const {
if (memory_usage_ == kMemoryUsageUnknown) {
using base::trace_event::EstimateMemoryUsage;
memory_usage_ = EstimateMemoryUsage(string_fields) +
- EstimateMemoryUsage(specifics_fields) +
+ EstimateSharedMemoryUsage(specifics_fields) +
EstimateMemoryUsage(id_fields) +
EstimateMemoryUsage(unique_position_fields) +
- EstimateMemoryUsage(attachment_metadata_fields);
+ EstimateSharedMemoryUsage(attachment_metadata_fields);
}
return memory_usage_;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698