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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/syncable/parent_child_index.h" 5 #include "sync/syncable/parent_child_index.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 8
9 #include "sync/syncable/entry_kernel.h" 9 #include "sync/syncable/entry_kernel.h"
10 #include "sync/syncable/syncable_id.h" 10 #include "sync/syncable/syncable_id.h"
11 11
12 namespace syncer { 12 namespace syncer {
13 namespace syncable { 13 namespace syncable {
14 14
15 namespace {
16
17 template <typename Key, typename Value>
18 size_t GetRbTreeMemoryUsgae(size_t num_nodes) {
19 // 4 pointers are stored for value, left, right and parent nodes in most
20 // implementations.
21 return (sizeof(std::pair<Key, Value>) + 4 * sizeof(void*)) * num_nodes;
22 }
23 }
24
15 bool ChildComparator::operator()(const EntryKernel* a, 25 bool ChildComparator::operator()(const EntryKernel* a,
16 const EntryKernel* b) const { 26 const EntryKernel* b) const {
17 const UniquePosition& a_pos = a->ref(UNIQUE_POSITION); 27 const UniquePosition& a_pos = a->ref(UNIQUE_POSITION);
18 const UniquePosition& b_pos = b->ref(UNIQUE_POSITION); 28 const UniquePosition& b_pos = b->ref(UNIQUE_POSITION);
19 29
20 if (a_pos.IsValid() && b_pos.IsValid()) { 30 if (a_pos.IsValid() && b_pos.IsValid()) {
21 // Position is important to this type. 31 // Position is important to this type.
22 return a_pos.LessThan(b_pos); 32 return a_pos.LessThan(b_pos);
23 } else if (a_pos.IsValid() && !b_pos.IsValid()) { 33 } else if (a_pos.IsValid() && !b_pos.IsValid()) {
24 // TODO(rlarocque): Remove this case. 34 // TODO(rlarocque): Remove this case.
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 } 196 }
187 197
188 const OrderedChildSet* ParentChildIndex::GetSiblings(EntryKernel* e) const { 198 const OrderedChildSet* ParentChildIndex::GetSiblings(EntryKernel* e) const {
189 // This implies the entry is in the index. 199 // This implies the entry is in the index.
190 DCHECK(Contains(e)); 200 DCHECK(Contains(e));
191 const OrderedChildSet* siblings = GetChildSet(e); 201 const OrderedChildSet* siblings = GetChildSet(e);
192 DCHECK(siblings && !siblings->empty()); 202 DCHECK(siblings && !siblings->empty());
193 return siblings; 203 return siblings;
194 } 204 }
195 205
206 size_t ParentChildIndex::MemoryUsage() const {
207 size_t total = model_type_root_ids_.capacity() * sizeof(std::string) +
208 sizeof(this) + type_root_child_sets_.size() * sizeof(void*);
209 for (const auto& id : model_type_root_ids_)
210 total += id.value().capacity() + 1;
211 total += GetRbTreeMemoryUsgae<Id, void*>(parent_children_map_.size());
212 for (const auto& entry : parent_children_map_)
213 total += entry.first.value().capacity() + 1;
214 for (const auto& child_set : type_root_child_sets_) {
215 if (child_set)
216 total += GetRbTreeMemoryUsgae<void*, void*>(child_set->size());
217 }
218 return total;
219 }
220
196 /* static */ 221 /* static */
197 bool ParentChildIndex::ShouldUseParentId(const Id& parent_id, 222 bool ParentChildIndex::ShouldUseParentId(const Id& parent_id,
198 ModelType model_type) { 223 ModelType model_type) {
199 // For compatibility with legacy unit tests, in addition to hierarchical 224 // For compatibility with legacy unit tests, in addition to hierarchical
200 // entries, this returns true any entries directly under root and for entries 225 // entries, this returns true any entries directly under root and for entries
201 // of UNSPECIFIED model type. 226 // of UNSPECIFIED model type.
202 return parent_id.IsRoot() || TypeSupportsHierarchy(model_type) || 227 return parent_id.IsRoot() || TypeSupportsHierarchy(model_type) ||
203 !syncer::IsRealDataType(model_type); 228 !syncer::IsRealDataType(model_type);
204 } 229 }
205 230
(...skipping 24 matching lines...) Expand all
230 type_root_child_sets_[model_type] = new OrderedChildSet(); 255 type_root_child_sets_[model_type] = new OrderedChildSet();
231 return type_root_child_sets_[model_type]; 256 return type_root_child_sets_[model_type];
232 } 257 }
233 258
234 const Id& ParentChildIndex::GetModelTypeRootId(ModelType model_type) const { 259 const Id& ParentChildIndex::GetModelTypeRootId(ModelType model_type) const {
235 return model_type_root_ids_[model_type]; 260 return model_type_root_ids_[model_type];
236 } 261 }
237 262
238 } // namespace syncable 263 } // namespace syncable
239 } // namespace syncer 264 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698