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