| 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/debug/thread_heap_usage_tracker.h" | 5 #include "base/debug/thread_heap_usage_tracker.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/allocator/allocator_shim.h" | 9 #include "base/allocator/allocator_shim.h" |
| 10 #include "base/allocator/features.h" | 10 #include "base/allocator/features.h" |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 { | 199 { |
| 200 &ThreadHeapUsageTrackerTest::OnAllocFn, // alloc_function | 200 &ThreadHeapUsageTrackerTest::OnAllocFn, // alloc_function |
| 201 &ThreadHeapUsageTrackerTest:: | 201 &ThreadHeapUsageTrackerTest:: |
| 202 OnAllocZeroInitializedFn, // alloc_zero_initialized_function | 202 OnAllocZeroInitializedFn, // alloc_zero_initialized_function |
| 203 &ThreadHeapUsageTrackerTest:: | 203 &ThreadHeapUsageTrackerTest:: |
| 204 OnAllocAlignedFn, // alloc_aligned_function | 204 OnAllocAlignedFn, // alloc_aligned_function |
| 205 &ThreadHeapUsageTrackerTest::OnReallocFn, // realloc_function | 205 &ThreadHeapUsageTrackerTest::OnReallocFn, // realloc_function |
| 206 &ThreadHeapUsageTrackerTest::OnFreeFn, // free_function | 206 &ThreadHeapUsageTrackerTest::OnFreeFn, // free_function |
| 207 &ThreadHeapUsageTrackerTest:: | 207 &ThreadHeapUsageTrackerTest:: |
| 208 OnGetSizeEstimateFn, // get_size_estimate_function | 208 OnGetSizeEstimateFn, // get_size_estimate_function |
| 209 nullptr, // batch_malloc |
| 210 nullptr, // batch_free |
| 211 nullptr, // free_definite_size_function |
| 209 nullptr, // next | 212 nullptr, // next |
| 210 }; | 213 }; |
| 211 | 214 |
| 212 } // namespace | 215 } // namespace |
| 213 | 216 |
| 214 TEST_F(ThreadHeapUsageTrackerTest, SimpleUsageWithExactSizeFunction) { | 217 TEST_F(ThreadHeapUsageTrackerTest, SimpleUsageWithExactSizeFunction) { |
| 215 set_size_function_kind(EXACT_SIZE_FUNCTION); | 218 set_size_function_kind(EXACT_SIZE_FUNCTION); |
| 216 | 219 |
| 217 ThreadHeapUsageTracker usage_tracker; | 220 ThreadHeapUsageTracker usage_tracker; |
| 218 usage_tracker.Start(); | 221 usage_tracker.Start(); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 532 ASSERT_TRUE(estimate == 0 || estimate >= kAllocSize); | 535 ASSERT_TRUE(estimate == 0 || estimate >= kAllocSize); |
| 533 | 536 |
| 534 alloc = MockRealloc(alloc, kAllocSize); | 537 alloc = MockRealloc(alloc, kAllocSize); |
| 535 estimate = MockGetSizeEstimate(alloc); | 538 estimate = MockGetSizeEstimate(alloc); |
| 536 ASSERT_TRUE(estimate == 0 || estimate >= kAllocSize); | 539 ASSERT_TRUE(estimate == 0 || estimate >= kAllocSize); |
| 537 MockFree(alloc); | 540 MockFree(alloc); |
| 538 } | 541 } |
| 539 | 542 |
| 540 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | 543 #if BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) |
| 541 TEST(ThreadHeapUsageShimTest, HooksIntoMallocWhenShimAvailable) { | 544 TEST(ThreadHeapUsageShimTest, HooksIntoMallocWhenShimAvailable) { |
| 545 #if defined(OS_MACOSX) |
| 546 allocator::InitializeAllocatorShim(); |
| 547 #endif |
| 548 |
| 542 ASSERT_FALSE(ThreadHeapUsageTracker::IsHeapTrackingEnabled()); | 549 ASSERT_FALSE(ThreadHeapUsageTracker::IsHeapTrackingEnabled()); |
| 543 | 550 |
| 544 ThreadHeapUsageTracker::EnableHeapTracking(); | 551 ThreadHeapUsageTracker::EnableHeapTracking(); |
| 545 | 552 |
| 546 ASSERT_TRUE(ThreadHeapUsageTracker::IsHeapTrackingEnabled()); | 553 ASSERT_TRUE(ThreadHeapUsageTracker::IsHeapTrackingEnabled()); |
| 547 | 554 |
| 548 const size_t kAllocSize = 9993; | 555 const size_t kAllocSize = 9993; |
| 549 // This test verifies that the scoped heap data is affected by malloc & | 556 // This test verifies that the scoped heap data is affected by malloc & |
| 550 // free only when the shim is available. | 557 // free only when the shim is available. |
| 551 ThreadHeapUsageTracker usage_tracker; | 558 ThreadHeapUsageTracker usage_tracker; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 575 EXPECT_LE(u2.free_ops + 1, u3.free_ops); | 582 EXPECT_LE(u2.free_ops + 1, u3.free_ops); |
| 576 | 583 |
| 577 TestingThreadHeapUsageTracker::DisableHeapTrackingForTesting(); | 584 TestingThreadHeapUsageTracker::DisableHeapTrackingForTesting(); |
| 578 | 585 |
| 579 ASSERT_FALSE(ThreadHeapUsageTracker::IsHeapTrackingEnabled()); | 586 ASSERT_FALSE(ThreadHeapUsageTracker::IsHeapTrackingEnabled()); |
| 580 } | 587 } |
| 581 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | 588 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) |
| 582 | 589 |
| 583 } // namespace debug | 590 } // namespace debug |
| 584 } // namespace base | 591 } // namespace base |
| OLD | NEW |