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

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: Add visitors for memory. Created 4 years, 6 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..43e1e3c91b9c594bfafacbe4d86b69391ba9fd5d 100644
--- a/sync/syncable/parent_child_index.cc
+++ b/sync/syncable/parent_child_index.cc
@@ -43,6 +43,8 @@ ParentChildIndex::ParentChildIndex() {
// Pre-allocate these two vectors to the number of model types.
model_type_root_ids_.resize(MODEL_TYPE_COUNT);
type_root_child_sets_.resize(MODEL_TYPE_COUNT);
+ bytes_used_ =
+ MODEL_TYPE_COUNT * (sizeof(Id) + sizeof(OrderedChildSet*)) + sizeof(this);
}
ParentChildIndex::~ParentChildIndex() {
@@ -83,6 +85,7 @@ bool ParentChildIndex::Insert(EntryKernel* entry) {
} else {
siblings = new OrderedChildSet();
parent_children_map_.insert(std::make_pair(parent_id, siblings));
+ bytes_used_ += parent_id.value().capacity() + sizeof(OrderedChildSet);
stanisc 2016/07/06 21:50:32 I would prefer to not mix the code for the size es
ssid 2016/07/19 22:10:35 counting the usage on demand.
}
} else {
// Non-hierarchical type, return a pre-defined collection by type.
@@ -111,6 +114,8 @@ bool ParentChildIndex::Insert(EntryKernel* entry) {
// in the map under the new ID below so it is safe to simply erase
// the entry here.
DCHECK_EQ(it->second, GetModelTypeChildSet(model_type));
+ bytes_used_ -=
+ 2 * it->first.value().capacity() + sizeof(OrderedChildSet*);
parent_children_map_.erase(it);
}
}
@@ -119,9 +124,12 @@ bool ParentChildIndex::Insert(EntryKernel* entry) {
model_type_root_ids_[model_type] = type_root_id;
parent_children_map_.insert(
std::make_pair(type_root_id, GetOrCreateModelTypeChildSet(model_type)));
+ bytes_used_ +=
+ 2 * type_root_id.value().capacity() + sizeof(OrderedChildSet*);
stanisc 2016/07/06 21:50:32 This doesn't take into account sizeof(Id) which sh
ssid 2016/07/19 22:10:35 Oh the 2 is multiplied not for the encoding. It is
}
// Finally, insert the entry in the child set.
+ bytes_used_ += sizeof(EntryKernel*);
stanisc 2016/07/06 21:50:32 This is a bit simplistic. See this: http://info.pr
ssid 2016/07/19 22:10:35 Fixed with more accurate values.
return siblings->insert(entry).second;
}
@@ -152,10 +160,12 @@ void ParentChildIndex::Remove(EntryKernel* e) {
// Erase the entry from the child set.
siblings->erase(j);
+ bytes_used_ -= sizeof(EntryKernel*);
// If the set is now empty and isn't shareable with |type_root_child_sets_|,
// erase it from the map.
if (siblings->empty() && should_erase) {
delete siblings;
+ bytes_used_ -= it->first.value().capacity() + sizeof(OrderedChildSet);
parent_children_map_.erase(it);
}
}

Powered by Google App Engine
This is Rietveld 408576698