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

Unified Diff: sync/syncable/parent_child_index.cc

Issue 2084243004: [WIP][tracing] Add memory dump provider for sync Directory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes. Created 4 years, 5 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
Index: sync/syncable/parent_child_index.cc
diff --git a/sync/syncable/parent_child_index.cc b/sync/syncable/parent_child_index.cc
index bf6e03fbd2044f55ea01d7b47ea2aa3b1b552c83..18c196b526ad40baf5e15c5e8a00c4d16d8b5638 100644
--- a/sync/syncable/parent_child_index.cc
+++ b/sync/syncable/parent_child_index.cc
@@ -12,6 +12,16 @@
namespace syncer {
namespace syncable {
+namespace {
+
+template <typename Key, typename Value>
+size_t GetRbTreeMemoryUsgae(size_t num_nodes) {
+ // 4 pointers are stored for value, left, right and parent nodes in most
+ // implementations.
+ return (sizeof(std::pair<Key, Value>) + 4 * sizeof(void*)) * num_nodes;
+}
+}
+
bool ChildComparator::operator()(const EntryKernel* a,
const EntryKernel* b) const {
const UniquePosition& a_pos = a->ref(UNIQUE_POSITION);
@@ -193,6 +203,21 @@ const OrderedChildSet* ParentChildIndex::GetSiblings(EntryKernel* e) const {
return siblings;
}
+size_t ParentChildIndex::MemoryUsage() const {
+ size_t total = model_type_root_ids_.capacity() * sizeof(std::string) +
+ sizeof(this) + type_root_child_sets_.size() * sizeof(void*);
+ for (const auto& id : model_type_root_ids_)
+ total += id.value().capacity() + 1;
+ total += GetRbTreeMemoryUsgae<Id, void*>(parent_children_map_.size());
+ for (const auto& entry : parent_children_map_)
+ total += entry.first.value().capacity() + 1;
+ for (const auto& child_set : type_root_child_sets_) {
+ if (child_set)
+ total += GetRbTreeMemoryUsgae<void*, void*>(child_set->size());
+ }
+ return total;
+}
+
/* static */
bool ParentChildIndex::ShouldUseParentId(const Id& parent_id,
ModelType model_type) {

Powered by Google App Engine
This is Rietveld 408576698