OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/sync/syncable/directory.h" | 5 #include "components/sync/syncable/directory.h" |
6 | 6 |
| 7 #include <inttypes.h> |
| 8 |
7 #include <algorithm> | 9 #include <algorithm> |
8 #include <iterator> | 10 #include <iterator> |
9 #include <utility> | 11 #include <utility> |
10 | 12 |
11 #include "base/base64.h" | 13 #include "base/base64.h" |
12 #include "base/guid.h" | 14 #include "base/guid.h" |
13 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
14 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
15 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/stringprintf.h" |
| 19 #include "base/trace_event/memory_dump_manager.h" |
| 20 #include "base/trace_event/memory_usage_estimator.h" |
| 21 #include "base/trace_event/process_memory_dump.h" |
16 #include "base/trace_event/trace_event.h" | 22 #include "base/trace_event/trace_event.h" |
17 #include "components/sync/base/attachment_id_proto.h" | 23 #include "components/sync/base/attachment_id_proto.h" |
18 #include "components/sync/base/unique_position.h" | 24 #include "components/sync/base/unique_position.h" |
19 #include "components/sync/base/unrecoverable_error_handler.h" | 25 #include "components/sync/base/unrecoverable_error_handler.h" |
| 26 #include "components/sync/protocol/proto_memory_estimations.h" |
20 #include "components/sync/syncable/in_memory_directory_backing_store.h" | 27 #include "components/sync/syncable/in_memory_directory_backing_store.h" |
21 #include "components/sync/syncable/model_neutral_mutable_entry.h" | 28 #include "components/sync/syncable/model_neutral_mutable_entry.h" |
22 #include "components/sync/syncable/on_disk_directory_backing_store.h" | 29 #include "components/sync/syncable/on_disk_directory_backing_store.h" |
23 #include "components/sync/syncable/scoped_kernel_lock.h" | 30 #include "components/sync/syncable/scoped_kernel_lock.h" |
24 #include "components/sync/syncable/scoped_parent_child_index_updater.h" | 31 #include "components/sync/syncable/scoped_parent_child_index_updater.h" |
25 #include "components/sync/syncable/syncable_base_transaction.h" | 32 #include "components/sync/syncable/syncable_base_transaction.h" |
26 #include "components/sync/syncable/syncable_changes_version.h" | 33 #include "components/sync/syncable/syncable_changes_version.h" |
27 #include "components/sync/syncable/syncable_read_transaction.h" | 34 #include "components/sync/syncable/syncable_read_transaction.h" |
28 #include "components/sync/syncable/syncable_util.h" | 35 #include "components/sync/syncable/syncable_util.h" |
29 #include "components/sync/syncable/syncable_write_transaction.h" | 36 #include "components/sync/syncable/syncable_write_transaction.h" |
(...skipping 29 matching lines...) Expand all Loading... |
59 download_progress[model_type].set_token(""); | 66 download_progress[model_type].set_token(""); |
60 } | 67 } |
61 | 68 |
62 bool Directory::PersistedKernelInfo::HasEmptyDownloadProgress( | 69 bool Directory::PersistedKernelInfo::HasEmptyDownloadProgress( |
63 ModelType model_type) { | 70 ModelType model_type) { |
64 const sync_pb::DataTypeProgressMarker& progress_marker = | 71 const sync_pb::DataTypeProgressMarker& progress_marker = |
65 download_progress[model_type]; | 72 download_progress[model_type]; |
66 return progress_marker.token().empty(); | 73 return progress_marker.token().empty(); |
67 } | 74 } |
68 | 75 |
| 76 size_t Directory::PersistedKernelInfo::EstimateMemoryUsage() const { |
| 77 using base::trace_event::EstimateMemoryUsage; |
| 78 return EstimateMemoryUsage(store_birthday) + |
| 79 EstimateMemoryUsage(bag_of_chips) + |
| 80 EstimateMemoryUsage(datatype_context); |
| 81 } |
| 82 |
69 Directory::SaveChangesSnapshot::SaveChangesSnapshot() | 83 Directory::SaveChangesSnapshot::SaveChangesSnapshot() |
70 : kernel_info_status(KERNEL_SHARE_INFO_INVALID) {} | 84 : kernel_info_status(KERNEL_SHARE_INFO_INVALID) {} |
71 | 85 |
72 Directory::SaveChangesSnapshot::~SaveChangesSnapshot() {} | 86 Directory::SaveChangesSnapshot::~SaveChangesSnapshot() {} |
73 | 87 |
74 bool Directory::SaveChangesSnapshot::HasUnsavedMetahandleChanges() const { | 88 bool Directory::SaveChangesSnapshot::HasUnsavedMetahandleChanges() const { |
75 return !dirty_metas.empty() || !metahandles_to_purge.empty() || | 89 return !dirty_metas.empty() || !metahandles_to_purge.empty() || |
76 !delete_journals.empty() || !delete_journals_to_purge.empty(); | 90 !delete_journals.empty() || !delete_journals_to_purge.empty(); |
77 } | 91 } |
78 | 92 |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 ScopedKernelLock lock(this); | 892 ScopedKernelLock lock(this); |
879 kernel_->persisted_info.download_progress[model_type].SerializeToString( | 893 kernel_->persisted_info.download_progress[model_type].SerializeToString( |
880 value_out); | 894 value_out); |
881 } | 895 } |
882 | 896 |
883 size_t Directory::GetEntriesCount() const { | 897 size_t Directory::GetEntriesCount() const { |
884 ScopedKernelLock lock(this); | 898 ScopedKernelLock lock(this); |
885 return kernel_->metahandles_map.size(); | 899 return kernel_->metahandles_map.size(); |
886 } | 900 } |
887 | 901 |
| 902 void Directory::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) { |
| 903 std::string dump_name_base = |
| 904 base::StringPrintf("sync/0x%" PRIXPTR, reinterpret_cast<uintptr_t>(this)); |
| 905 |
| 906 size_t kernel_memory_usage; |
| 907 { |
| 908 using base::trace_event::EstimateMemoryUsage; |
| 909 |
| 910 ReadTransaction trans(FROM_HERE, this); |
| 911 ScopedKernelLock lock(this); |
| 912 kernel_memory_usage = |
| 913 EstimateMemoryUsage(kernel_->name) + |
| 914 EstimateMemoryUsage(kernel_->metahandles_map) + |
| 915 EstimateMemoryUsage(kernel_->ids_map) + |
| 916 EstimateMemoryUsage(kernel_->server_tags_map) + |
| 917 EstimateMemoryUsage(kernel_->client_tags_map) + |
| 918 EstimateMemoryUsage(kernel_->parent_child_index) + |
| 919 EstimateMemoryUsage(kernel_->index_by_attachment_id) + |
| 920 EstimateMemoryUsage(kernel_->unapplied_update_metahandles) + |
| 921 EstimateMemoryUsage(kernel_->unsynced_metahandles) + |
| 922 EstimateMemoryUsage(kernel_->dirty_metahandles) + |
| 923 EstimateMemoryUsage(kernel_->metahandles_to_purge) + |
| 924 EstimateMemoryUsage(kernel_->persisted_info) + |
| 925 EstimateMemoryUsage(kernel_->cache_guid); |
| 926 } |
| 927 |
| 928 { |
| 929 std::string dump_name = |
| 930 base::StringPrintf("%s/kernel", dump_name_base.c_str()); |
| 931 |
| 932 auto* dump = pmd->CreateAllocatorDump(dump_name); |
| 933 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, |
| 934 base::trace_event::MemoryAllocatorDump::kUnitsBytes, |
| 935 kernel_memory_usage); |
| 936 const char* system_allocator_name = |
| 937 base::trace_event::MemoryDumpManager::GetInstance() |
| 938 ->system_allocator_pool_name(); |
| 939 if (system_allocator_name) { |
| 940 pmd->AddSuballocation(dump->guid(), system_allocator_name); |
| 941 } |
| 942 } |
| 943 |
| 944 if (store_) { |
| 945 std::string dump_name = |
| 946 base::StringPrintf("%s/store", dump_name_base.c_str()); |
| 947 auto* dump = pmd->CreateAllocatorDump(dump_name); |
| 948 store_->ReportMemoryUsage(dump); |
| 949 } |
| 950 } |
| 951 |
888 void Directory::SetDownloadProgress( | 952 void Directory::SetDownloadProgress( |
889 ModelType model_type, | 953 ModelType model_type, |
890 const sync_pb::DataTypeProgressMarker& new_progress) { | 954 const sync_pb::DataTypeProgressMarker& new_progress) { |
891 ScopedKernelLock lock(this); | 955 ScopedKernelLock lock(this); |
892 kernel_->persisted_info.download_progress[model_type].CopyFrom(new_progress); | 956 kernel_->persisted_info.download_progress[model_type].CopyFrom(new_progress); |
893 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; | 957 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; |
894 } | 958 } |
895 | 959 |
896 bool Directory::HasEmptyDownloadProgress(ModelType type) const { | 960 bool Directory::HasEmptyDownloadProgress(ModelType type) const { |
897 ScopedKernelLock lock(this); | 961 ScopedKernelLock lock(this); |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 Directory::Kernel* Directory::kernel() { | 1593 Directory::Kernel* Directory::kernel() { |
1530 return kernel_; | 1594 return kernel_; |
1531 } | 1595 } |
1532 | 1596 |
1533 const Directory::Kernel* Directory::kernel() const { | 1597 const Directory::Kernel* Directory::kernel() const { |
1534 return kernel_; | 1598 return kernel_; |
1535 } | 1599 } |
1536 | 1600 |
1537 } // namespace syncable | 1601 } // namespace syncable |
1538 } // namespace syncer | 1602 } // namespace syncer |
OLD | NEW |