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

Side by Side Diff: base/trace_event/memory_usage_estimator.h

Issue 2452713003: [Sync] Implement MemoryDumpProvider. (Closed)
Patch Set: Fix presumit; fix Windows; git cl format Created 4 years, 1 month 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 | components/sync/BUILD.gn » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef BASE_TRACE_EVENT_MEMORY_USAGE_ESTIMATOR_H_ 5 #ifndef BASE_TRACE_EVENT_MEMORY_USAGE_ESTIMATOR_H_
6 #define BASE_TRACE_EVENT_MEMORY_USAGE_ESTIMATOR_H_ 6 #define BASE_TRACE_EVENT_MEMORY_USAGE_ESTIMATOR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <array> 10 #include <array>
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 // std::unique_ptr 86 // std::unique_ptr
87 87
88 template <class T, class D> 88 template <class T, class D>
89 size_t EstimateMemoryUsage(const std::unique_ptr<T, D>& ptr); 89 size_t EstimateMemoryUsage(const std::unique_ptr<T, D>& ptr);
90 90
91 template <class T, class D> 91 template <class T, class D>
92 size_t EstimateMemoryUsage(const std::unique_ptr<T[], D>& array, 92 size_t EstimateMemoryUsage(const std::unique_ptr<T[], D>& array,
93 size_t array_length); 93 size_t array_length);
94 94
95 // std::shared_ptr
96
97 template <class T>
98 size_t EstimateMemoryUsage(const std::shared_ptr<T>& ptr);
99
95 // Containers 100 // Containers
96 101
97 template <class F, class S> 102 template <class F, class S>
98 size_t EstimateMemoryUsage(const std::pair<F, S>& pair); 103 size_t EstimateMemoryUsage(const std::pair<F, S>& pair);
99 104
100 template <class T, class A> 105 template <class T, class A>
101 size_t EstimateMemoryUsage(const std::vector<T, A>& vector); 106 size_t EstimateMemoryUsage(const std::vector<T, A>& vector);
102 107
103 template <class T, class A> 108 template <class T, class A>
104 size_t EstimateMemoryUsage(const std::list<T, A>& list); 109 size_t EstimateMemoryUsage(const std::list<T, A>& list);
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 size_t EstimateMemoryUsage(const std::unique_ptr<T, D>& ptr) { 274 size_t EstimateMemoryUsage(const std::unique_ptr<T, D>& ptr) {
270 return ptr ? (sizeof(T) + EstimateItemMemoryUsage(*ptr)) : 0; 275 return ptr ? (sizeof(T) + EstimateItemMemoryUsage(*ptr)) : 0;
271 } 276 }
272 277
273 template <class T, class D> 278 template <class T, class D>
274 size_t EstimateMemoryUsage(const std::unique_ptr<T[], D>& array, 279 size_t EstimateMemoryUsage(const std::unique_ptr<T[], D>& array,
275 size_t array_length) { 280 size_t array_length) {
276 return EstimateMemoryUsage(array.get(), array_length); 281 return EstimateMemoryUsage(array.get(), array_length);
277 } 282 }
278 283
284 // std::shared_ptr
285
286 template <class T>
287 size_t EstimateMemoryUsage(const std::shared_ptr<T>& ptr) {
288 auto use_count = ptr.use_count();
289 if (use_count == 0) {
290 return 0;
291 }
292 // Model shared_ptr after libc++,
293 // see __shared_ptr_pointer from include/memory
294 struct SharedPointer {
295 void* vtbl;
296 long shared_owners;
297 long shared_weak_owners;
298 T* value;
299 };
300 // If object of size S shared N > S times we prefer to (potentially)
301 // overestimate than to return 0.
302 return sizeof(SharedPointer) +
303 (EstimateItemMemoryUsage(*ptr) + (use_count - 1)) / use_count;
304 }
305
279 // std::pair 306 // std::pair
280 307
281 template <class F, class S> 308 template <class F, class S>
282 size_t EstimateMemoryUsage(const std::pair<F, S>& pair) { 309 size_t EstimateMemoryUsage(const std::pair<F, S>& pair) {
283 return EstimateItemMemoryUsage(pair.first) + 310 return EstimateItemMemoryUsage(pair.first) +
284 EstimateItemMemoryUsage(pair.second); 311 EstimateItemMemoryUsage(pair.second);
285 } 312 }
286 313
287 // std::vector 314 // std::vector
288 315
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 typename std::unordered_multimap<K, V, H, KE, A>::value_type; 436 typename std::unordered_multimap<K, V, H, KE, A>::value_type;
410 return EstimateHashMapMemoryUsage<value_type>(map.bucket_count(), 437 return EstimateHashMapMemoryUsage<value_type>(map.bucket_count(),
411 map.size()) + 438 map.size()) +
412 EstimateIterableMemoryUsage(map); 439 EstimateIterableMemoryUsage(map);
413 } 440 }
414 441
415 } // namespace trace_event 442 } // namespace trace_event
416 } // namespace base 443 } // namespace base
417 444
418 #endif // BASE_TRACE_EVENT_MEMORY_USAGE_ESTIMATOR_H_ 445 #endif // BASE_TRACE_EVENT_MEMORY_USAGE_ESTIMATOR_H_
OLDNEW
« no previous file with comments | « no previous file | components/sync/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698