| Index: base/trace_event/memory_usage_estimator.h
|
| diff --git a/base/trace_event/memory_usage_estimator.h b/base/trace_event/memory_usage_estimator.h
|
| index c089b0ee614d74910f849ac22fb9561a0027f42c..4f230c7b3890911c73c50d786a78514ac6ada83d 100644
|
| --- a/base/trace_event/memory_usage_estimator.h
|
| +++ b/base/trace_event/memory_usage_estimator.h
|
| @@ -92,6 +92,11 @@ template <class T, class D>
|
| size_t EstimateMemoryUsage(const std::unique_ptr<T[], D>& array,
|
| size_t array_length);
|
|
|
| +// std::shared_ptr
|
| +
|
| +template <class T>
|
| +size_t EstimateMemoryUsage(const std::shared_ptr<T>& ptr);
|
| +
|
| // Containers
|
|
|
| template <class F, class S>
|
| @@ -276,6 +281,28 @@ size_t EstimateMemoryUsage(const std::unique_ptr<T[], D>& array,
|
| return EstimateMemoryUsage(array.get(), array_length);
|
| }
|
|
|
| +// std::shared_ptr
|
| +
|
| +template <class T>
|
| +size_t EstimateMemoryUsage(const std::shared_ptr<T>& ptr) {
|
| + auto use_count = ptr.use_count();
|
| + if (use_count == 0) {
|
| + return 0;
|
| + }
|
| + // Model shared_ptr after libc++,
|
| + // see __shared_ptr_pointer from include/memory
|
| + struct SharedPointer {
|
| + void* vtbl;
|
| + long shared_owners;
|
| + long shared_weak_owners;
|
| + T* value;
|
| + };
|
| + // If object of size S shared N > S times we prefer to (potentially)
|
| + // overestimate than to return 0.
|
| + return sizeof(SharedPointer) +
|
| + (EstimateItemMemoryUsage(*ptr) + (use_count - 1)) / use_count;
|
| +}
|
| +
|
| // std::pair
|
|
|
| template <class F, class S>
|
|
|