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 "sync/syncable/directory.h" | 5 #include "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/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
17 #include "base/stl_util.h" | 18 #include "base/stl_util.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/process_memory_dump.h" | |
19 #include "base/trace_event/trace_event.h" | 23 #include "base/trace_event/trace_event.h" |
20 #include "sync/internal_api/public/base/attachment_id_proto.h" | 24 #include "sync/internal_api/public/base/attachment_id_proto.h" |
21 #include "sync/internal_api/public/base/unique_position.h" | 25 #include "sync/internal_api/public/base/unique_position.h" |
22 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" | 26 #include "sync/internal_api/public/util/unrecoverable_error_handler.h" |
23 #include "sync/syncable/entry.h" | 27 #include "sync/syncable/entry.h" |
24 #include "sync/syncable/entry_kernel.h" | 28 #include "sync/syncable/entry_kernel.h" |
25 #include "sync/syncable/in_memory_directory_backing_store.h" | 29 #include "sync/syncable/in_memory_directory_backing_store.h" |
26 #include "sync/syncable/model_neutral_mutable_entry.h" | 30 #include "sync/syncable/model_neutral_mutable_entry.h" |
27 #include "sync/syncable/on_disk_directory_backing_store.h" | 31 #include "sync/syncable/on_disk_directory_backing_store.h" |
28 #include "sync/syncable/scoped_kernel_lock.h" | 32 #include "sync/syncable/scoped_kernel_lock.h" |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
913 ScopedKernelLock lock(this); | 917 ScopedKernelLock lock(this); |
914 kernel_->persisted_info.download_progress[model_type].SerializeToString( | 918 kernel_->persisted_info.download_progress[model_type].SerializeToString( |
915 value_out); | 919 value_out); |
916 } | 920 } |
917 | 921 |
918 size_t Directory::GetEntriesCount() const { | 922 size_t Directory::GetEntriesCount() const { |
919 ScopedKernelLock lock(this); | 923 ScopedKernelLock lock(this); |
920 return kernel_->metahandles_map.size(); | 924 return kernel_->metahandles_map.size(); |
921 } | 925 } |
922 | 926 |
927 void Directory::OnMemoryDump(base::trace_event::ProcessMemoryDump* pmd) { | |
928 size_t total = 0; | |
929 static const size_t kEntryKernelSize = | |
930 sizeof(EntryKernel) + | |
931 PROTO_FIELDS_COUNT * sizeof(sync_pb::EntitySpecifics) + | |
stanisc
2016/06/24 21:44:35
This isn't correct. The actual number of EntitySpe
ssid
2016/07/01 22:46:52
I am not sure how do i find if the EntitySpecifics
| |
932 ATTACHMENT_METADATA_FIELDS_COUNT * sizeof(sync_pb::AttachmentMetadata); | |
933 { | |
934 ScopedKernelLock lock(this); | |
935 total += kernel_->metahandles_map.size() * kEntryKernelSize; | |
stanisc
2016/06/24 21:44:35
This doesn't take the map overhead into account.
ssid
2016/07/01 22:46:52
Um, I think its not really accurate to estimate th
| |
936 for (auto entry : kernel_->index_by_attachment_id) { | |
937 total += entry.first.size(); | |
938 total += entry.second.size() * sizeof(int64_t); | |
939 } | |
940 for (auto handle : kernel_->metahandles_map) { | |
stanisc
2016/06/24 21:44:35
Would be nice to add the cost of the map itself.
ssid
2016/07/01 22:46:52
Do you mean the overhead mentioned at line 935, or
| |
941 // Twice because the |ids_map| stores a copy of these strings. | |
942 for (unsigned i = ID_FIELDS_BEGIN; i < ID_FIELDS_END; ++i) | |
943 total += 2 * handle.second->ref(static_cast<IdField>(i)).value().size(); | |
stanisc
2016/06/24 21:44:35
The memory used by a string in memory isn't size()
ssid
2016/07/01 22:46:52
I have changed to capacity. Not sure I understand
| |
944 | |
945 for (unsigned i = STRING_FIELDS_BEGIN; i < STRING_FIELDS_END; ++i) { | |
946 if (i == UNIQUE_SERVER_TAG || i == UNIQUE_CLIENT_TAG) { | |
947 // These are stored again in tags_map. | |
948 total += 2 * handle.second->ref(static_cast<StringField>(i)).size(); | |
949 } else { | |
950 total += handle.second->ref(static_cast<StringField>(i)).size(); | |
951 } | |
952 } | |
953 for (unsigned i = PROTO_FIELDS_BEGIN; i < PROTO_FIELDS_END; ++i) | |
954 total += handle.second->ref(static_cast<ProtoField>(i)).ByteSize(); | |
955 for (unsigned i = ATTACHMENT_METADATA_FIELDS_BEGIN; | |
956 i < ATTACHMENT_METADATA_FIELDS_END; ++i) { | |
957 total += handle.second->ref(static_cast<AttachmentMetadataField>(i)) | |
958 .ByteSize(); | |
stanisc
2016/06/24 21:44:35
We've discussed this already. ByteSize is far from
ssid
2016/06/24 21:56:50
Yes I would prefer writing the visitor code / simi
ssid
2016/07/01 22:46:52
So, I have made this calculation by changing conve
| |
959 } | |
960 for (unsigned i = UNIQUE_POSITION_FIELDS_BEGIN; | |
961 i < UNIQUE_POSITION_FIELDS_END; ++i) { | |
962 total += handle.second->ref(static_cast<UniquePositionField>(i)) | |
963 .compressed_size(); | |
964 } | |
965 } | |
966 } | |
967 auto dump = pmd->CreateAllocatorDump(base::StringPrintf( | |
stanisc
2016/06/24 21:44:35
There are other maps which cost need to be added.
ssid
2016/07/01 22:46:52
I have added whatever I think is significant. Not
| |
968 "sync/0x%" PRIXPTR, reinterpret_cast<uintptr_t>(this))); | |
969 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, | |
970 base::trace_event::MemoryAllocatorDump::kUnitsBytes, total); | |
971 const char* system_allocator_name = | |
972 base::trace_event::MemoryDumpManager::GetInstance() | |
973 ->system_allocator_pool_name(); | |
974 if (system_allocator_name) { | |
975 pmd->AddSuballocation(dump->guid(), system_allocator_name); | |
976 } | |
977 } | |
978 | |
923 void Directory::SetDownloadProgress( | 979 void Directory::SetDownloadProgress( |
924 ModelType model_type, | 980 ModelType model_type, |
925 const sync_pb::DataTypeProgressMarker& new_progress) { | 981 const sync_pb::DataTypeProgressMarker& new_progress) { |
926 ScopedKernelLock lock(this); | 982 ScopedKernelLock lock(this); |
927 kernel_->persisted_info.download_progress[model_type].CopyFrom(new_progress); | 983 kernel_->persisted_info.download_progress[model_type].CopyFrom(new_progress); |
928 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; | 984 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; |
929 } | 985 } |
930 | 986 |
931 bool Directory::HasEmptyDownloadProgress(ModelType type) const { | 987 bool Directory::HasEmptyDownloadProgress(ModelType type) const { |
932 ScopedKernelLock lock(this); | 988 ScopedKernelLock lock(this); |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1579 Directory::Kernel* Directory::kernel() { | 1635 Directory::Kernel* Directory::kernel() { |
1580 return kernel_; | 1636 return kernel_; |
1581 } | 1637 } |
1582 | 1638 |
1583 const Directory::Kernel* Directory::kernel() const { | 1639 const Directory::Kernel* Directory::kernel() const { |
1584 return kernel_; | 1640 return kernel_; |
1585 } | 1641 } |
1586 | 1642 |
1587 } // namespace syncable | 1643 } // namespace syncable |
1588 } // namespace syncer | 1644 } // namespace syncer |
OLD | NEW |