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

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

Issue 2837513002: [sync] Properly estimate EntryKernel memory usage. (Closed)
Patch Set: Created 3 years, 8 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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/sync/syncable/entry_kernel.h" 5 #include "components/sync/syncable/entry_kernel.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/json/string_escape.h" 9 #include "base/json/string_escape.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 } 142 }
143 143
144 base::Value* UniquePositionToValue(const UniquePosition& pos) { 144 base::Value* UniquePositionToValue(const UniquePosition& pos) {
145 return new base::Value(pos.ToDebugString()); 145 return new base::Value(pos.ToDebugString());
146 } 146 }
147 147
148 base::Value* AttachmentMetadataToValue(const sync_pb::AttachmentMetadata& a) { 148 base::Value* AttachmentMetadataToValue(const sync_pb::AttachmentMetadata& a) {
149 return new base::Value(a.SerializeAsString()); 149 return new base::Value(a.SerializeAsString());
150 } 150 }
151 151
152 // Estimates memory usage of ProtoValuePtr<T> arrays where consecutive
153 // elements can share the same value.
154 template <class T, size_t N>
155 size_t EstimateSharedMemoryUsage(ProtoValuePtr<T> const (&ptrs)[N]) {
156 size_t memory_usage = 0;
157 const T* last_value = nullptr;
158 for (const auto& ptr : ptrs) {
159 if (last_value != &ptr.value()) {
160 memory_usage += EstimateMemoryUsage(ptr);
161 last_value = &ptr.value();
162 }
163 }
164 return memory_usage;
165 }
166
152 } // namespace 167 } // namespace
153 168
154 base::DictionaryValue* EntryKernel::ToValue( 169 base::DictionaryValue* EntryKernel::ToValue(
155 Cryptographer* cryptographer) const { 170 Cryptographer* cryptographer) const {
156 base::DictionaryValue* kernel_info = new base::DictionaryValue(); 171 base::DictionaryValue* kernel_info = new base::DictionaryValue();
157 kernel_info->SetBoolean("isDirty", is_dirty()); 172 kernel_info->SetBoolean("isDirty", is_dirty());
158 ModelType dataType = GetServerModelType(); 173 ModelType dataType = GetServerModelType();
159 if (!IsRealDataType(dataType)) 174 if (!IsRealDataType(dataType))
160 dataType = GetModelType(); 175 dataType = GetModelType();
161 kernel_info->Set("modelType", ModelTypeToValue(dataType)); 176 kernel_info->Set("modelType", ModelTypeToValue(dataType));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 SetFieldValues(*this, kernel_info, &GetBitTempString, &BooleanToValue, 224 SetFieldValues(*this, kernel_info, &GetBitTempString, &BooleanToValue,
210 BIT_TEMPS_BEGIN, BIT_TEMPS_END - 1); 225 BIT_TEMPS_BEGIN, BIT_TEMPS_END - 1);
211 226
212 return kernel_info; 227 return kernel_info;
213 } 228 }
214 229
215 size_t EntryKernel::EstimateMemoryUsage() const { 230 size_t EntryKernel::EstimateMemoryUsage() const {
216 if (memory_usage_ == kMemoryUsageUnknown) { 231 if (memory_usage_ == kMemoryUsageUnknown) {
217 using base::trace_event::EstimateMemoryUsage; 232 using base::trace_event::EstimateMemoryUsage;
218 memory_usage_ = EstimateMemoryUsage(string_fields) + 233 memory_usage_ = EstimateMemoryUsage(string_fields) +
219 EstimateMemoryUsage(specifics_fields) + 234 EstimateSharedMemoryUsage(specifics_fields) +
220 EstimateMemoryUsage(id_fields) + 235 EstimateMemoryUsage(id_fields) +
221 EstimateMemoryUsage(unique_position_fields) + 236 EstimateMemoryUsage(unique_position_fields) +
222 EstimateMemoryUsage(attachment_metadata_fields); 237 EstimateSharedMemoryUsage(attachment_metadata_fields);
223 } 238 }
224 return memory_usage_; 239 return memory_usage_;
225 } 240 }
226 241
227 std::unique_ptr<base::ListValue> EntryKernelMutationMapToValue( 242 std::unique_ptr<base::ListValue> EntryKernelMutationMapToValue(
228 const EntryKernelMutationMap& mutations) { 243 const EntryKernelMutationMap& mutations) {
229 std::unique_ptr<base::ListValue> list(new base::ListValue()); 244 std::unique_ptr<base::ListValue> list(new base::ListValue());
230 for (EntryKernelMutationMap::const_iterator it = mutations.begin(); 245 for (EntryKernelMutationMap::const_iterator it = mutations.begin();
231 it != mutations.end(); ++it) { 246 it != mutations.end(); ++it) {
232 list->Append(EntryKernelMutationToValue(it->second)); 247 list->Append(EntryKernelMutationToValue(it->second));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 os << "TempFlags: "; 301 os << "TempFlags: ";
287 for (; i < BIT_TEMPS_END; ++i) { 302 for (; i < BIT_TEMPS_END; ++i) {
288 if (kernel->ref(static_cast<BitTemp>(i))) 303 if (kernel->ref(static_cast<BitTemp>(i)))
289 os << "#" << i - BIT_TEMPS_BEGIN << ", "; 304 os << "#" << i - BIT_TEMPS_BEGIN << ", ";
290 } 305 }
291 return os; 306 return os;
292 } 307 }
293 308
294 } // namespace syncable 309 } // namespace syncable
295 } // namespace syncer 310 } // namespace syncer
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698