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

Side by Side Diff: components/sync/syncable/directory.cc

Issue 2949923004: Reland: [Sync] Record sync memory usage in histogram broken by datatypes (Closed)
Patch Set: Fix linker error Created 3 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 unified diff | Download patch
« no previous file with comments | « components/sync/syncable/directory.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <inttypes.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 } 980 }
981 } 981 }
982 982
983 if (store_) { 983 if (store_) {
984 std::string dump_name = 984 std::string dump_name =
985 base::StringPrintf("%s/store", dump_name_base.c_str()); 985 base::StringPrintf("%s/store", dump_name_base.c_str());
986 store_->ReportMemoryUsage(pmd, dump_name); 986 store_->ReportMemoryUsage(pmd, dump_name);
987 } 987 }
988 } 988 }
989 989
990 // Iterates over entries of |map|, sums memory usage estimate of entries whose
991 // entry type is |model_type|. Passing owning container will also include memory
992 // estimate of EntryKernel.
993 template <typename Container>
994 size_t EstimateFiteredMapMemoryUsage(const Container& map,
995 ModelType model_type) {
996 using base::trace_event::EstimateMemoryUsage;
997 size_t memory_usage = 0;
998 for (const auto& kv : map) {
999 const ModelType entry_type =
1000 GetModelTypeFromSpecifics(kv.second->ref(SPECIFICS));
1001 if (entry_type == model_type) {
1002 memory_usage += EstimateMemoryUsage(kv);
1003 }
1004 }
1005 return memory_usage;
1006 }
1007
1008 size_t Directory::EstimateMemoryUsageByType(ModelType model_type) {
1009 using base::trace_event::EstimateMemoryUsage;
1010 ReadTransaction trans(FROM_HERE, this);
1011 ScopedKernelLock lock(this);
1012
1013 size_t memory_usage = 0;
1014 memory_usage +=
1015 EstimateFiteredMapMemoryUsage(kernel_->metahandles_map, model_type);
1016 memory_usage += EstimateFiteredMapMemoryUsage(kernel_->ids_map, model_type);
1017 memory_usage +=
1018 EstimateFiteredMapMemoryUsage(kernel_->server_tags_map, model_type);
1019 memory_usage +=
1020 EstimateFiteredMapMemoryUsage(kernel_->client_tags_map, model_type);
1021 memory_usage += EstimateMemoryUsage(
1022 kernel_->persisted_info.download_progress[model_type]);
1023 return memory_usage;
1024 }
1025
990 void Directory::SetDownloadProgress( 1026 void Directory::SetDownloadProgress(
991 ModelType model_type, 1027 ModelType model_type,
992 const sync_pb::DataTypeProgressMarker& new_progress) { 1028 const sync_pb::DataTypeProgressMarker& new_progress) {
993 ScopedKernelLock lock(this); 1029 ScopedKernelLock lock(this);
994 kernel_->persisted_info.download_progress[model_type].CopyFrom(new_progress); 1030 kernel_->persisted_info.download_progress[model_type].CopyFrom(new_progress);
995 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY; 1031 kernel_->info_status = KERNEL_SHARE_INFO_DIRTY;
996 } 1032 }
997 1033
998 bool Directory::HasEmptyDownloadProgress(ModelType type) const { 1034 bool Directory::HasEmptyDownloadProgress(ModelType type) const {
999 ScopedKernelLock lock(this); 1035 ScopedKernelLock lock(this);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 std::vector<int64_t>* result) { 1203 std::vector<int64_t>* result) {
1168 ScopedKernelLock lock(this); 1204 ScopedKernelLock lock(this);
1169 GetMetaHandlesOfType(lock, trans, type, result); 1205 GetMetaHandlesOfType(lock, trans, type, result);
1170 } 1206 }
1171 1207
1172 void Directory::GetMetaHandlesOfType(const ScopedKernelLock& lock, 1208 void Directory::GetMetaHandlesOfType(const ScopedKernelLock& lock,
1173 BaseTransaction* trans, 1209 BaseTransaction* trans,
1174 ModelType type, 1210 ModelType type,
1175 std::vector<int64_t>* result) { 1211 std::vector<int64_t>* result) {
1176 result->clear(); 1212 result->clear();
1177 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); 1213 for (const auto& handle_and_kernel : kernel_->metahandles_map) {
1178 it != kernel_->metahandles_map.end(); ++it) { 1214 EntryKernel* entry = handle_and_kernel.second.get();
1179 EntryKernel* entry = it->second.get();
1180 const ModelType entry_type = 1215 const ModelType entry_type =
1181 GetModelTypeFromSpecifics(entry->ref(SPECIFICS)); 1216 GetModelTypeFromSpecifics(entry->ref(SPECIFICS));
1182 if (entry_type == type) 1217 if (entry_type == type)
1183 result->push_back(it->first); 1218 result->push_back(handle_and_kernel.first);
1184 } 1219 }
1185 } 1220 }
1186 1221
1187 void Directory::CollectMetaHandleCounts( 1222 void Directory::CollectMetaHandleCounts(
1188 std::vector<int>* num_entries_by_type, 1223 std::vector<int>* num_entries_by_type,
1189 std::vector<int>* num_to_delete_entries_by_type) { 1224 std::vector<int>* num_to_delete_entries_by_type) {
1190 syncable::ReadTransaction trans(FROM_HERE, this); 1225 syncable::ReadTransaction trans(FROM_HERE, this);
1191 ScopedKernelLock lock(this); 1226 ScopedKernelLock lock(this);
1192 1227
1193 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin(); 1228 for (MetahandlesMap::iterator it = kernel_->metahandles_map.begin();
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 Directory::Kernel* Directory::kernel() { 1666 Directory::Kernel* Directory::kernel() {
1632 return kernel_.get(); 1667 return kernel_.get();
1633 } 1668 }
1634 1669
1635 const Directory::Kernel* Directory::kernel() const { 1670 const Directory::Kernel* Directory::kernel() const {
1636 return kernel_.get(); 1671 return kernel_.get();
1637 } 1672 }
1638 1673
1639 } // namespace syncable 1674 } // namespace syncable
1640 } // namespace syncer 1675 } // namespace syncer
OLDNEW
« no previous file with comments | « components/sync/syncable/directory.h ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698