| OLD | NEW |
| 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 #include "base/trace_event/memory_usage_estimator.h" | 5 #include "base/trace_event/memory_usage_estimator.h" |
| 6 | 6 |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 } | 218 } |
| 219 | 219 |
| 220 TEST(EstimateMemoryUsageTest, UnorderedMultiMap) { | 220 TEST(EstimateMemoryUsageTest, UnorderedMultiMap) { |
| 221 std::unordered_multimap<Data, short, Data::Hasher> map; | 221 std::unordered_multimap<Data, short, Data::Hasher> map; |
| 222 for (int i = 0; i != 1000; ++i) { | 222 for (int i = 0; i != 1000; ++i) { |
| 223 map.insert({Data(i), static_cast<short>(i)}); | 223 map.insert({Data(i), static_cast<short>(i)}); |
| 224 } | 224 } |
| 225 EXPECT_EQ_32_64(515540u, 531580u, EstimateMemoryUsage(map)); | 225 EXPECT_EQ_32_64(515540u, 531580u, EstimateMemoryUsage(map)); |
| 226 } | 226 } |
| 227 | 227 |
| 228 TEST(EstimateMemoryUsageTest, Deque) { |
| 229 std::deque<Data> deque; |
| 230 |
| 231 // Pick a large value so that platform-specific accounting |
| 232 // for deque's blocks is small compared to usage of all items. |
| 233 constexpr size_t kDataSize = 100000; |
| 234 for (int i = 0; i != 1500; ++i) { |
| 235 deque.push_back(Data(kDataSize)); |
| 236 } |
| 237 |
| 238 // Compare against a reasonable minimum (i.e. no overhead). |
| 239 size_t min_expected_usage = deque.size() * (sizeof(Data) + kDataSize); |
| 240 EXPECT_LE(min_expected_usage, EstimateMemoryUsage(deque)); |
| 241 } |
| 242 |
| 228 } // namespace trace_event | 243 } // namespace trace_event |
| 229 } // namespace base | 244 } // namespace base |
| OLD | NEW |