From 66a9be95250139b88c618fe35bb33580af12bf7a Mon Sep 17 00:00:00 2001 From: Aaron Green Date: Fri, 2 Feb 2024 19:55:14 +0000 Subject: [PATCH] pw_allocator: Rename AllocatorMetricProxy to TrackingAllocator Change-Id: I25fe88891b0262c683d273f2bc32a06f9d104323 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/190230 Presubmit-Verified: CQ Bot Account Reviewed-by: Alexei Frolov Commit-Queue: Aaron Green --- pw_allocator/BUILD.bazel | 58 +++++++++---------- pw_allocator/BUILD.gn | 40 ++++++------- pw_allocator/CMakeLists.txt | 48 +++++++-------- pw_allocator/allocator_testing.cc | 12 ++-- pw_allocator/docs.rst | 18 +++--- .../public/pw_allocator/allocator_testing.h | 10 ++-- .../public/pw_allocator/fallback_allocator.h | 4 +- ...or_metric_proxy.h => tracking_allocator.h} | 14 ++--- pw_allocator/size_report/BUILD.bazel | 6 +- pw_allocator/size_report/BUILD.gn | 8 +-- .../size_report/split_free_list_allocator.cc | 22 +++---- ...oxy_test.cc => tracking_allocator_test.cc} | 36 ++++++------ 12 files changed, 135 insertions(+), 141 deletions(-) rename pw_allocator/public/pw_allocator/{allocator_metric_proxy.h => tracking_allocator.h} (86%) rename pw_allocator/{allocator_metric_proxy_test.cc => tracking_allocator_test.cc} (85%) diff --git a/pw_allocator/BUILD.bazel b/pw_allocator/BUILD.bazel index a8dc7b538b..61b8fe9e60 100644 --- a/pw_allocator/BUILD.bazel +++ b/pw_allocator/BUILD.bazel @@ -39,21 +39,6 @@ cc_library( ], ) -cc_library( - name = "allocator_metric_proxy", - hdrs = [ - "public/pw_allocator/allocator_metric_proxy.h", - ], - includes = ["public"], - deps = [ - ":allocator", - ":metrics", - "//pw_assert", - "//pw_metric:metric", - "//pw_status", - ], -) - cc_library( name = "block", srcs = ["block.cc"], @@ -87,8 +72,8 @@ cc_library( includes = ["public"], deps = [ ":allocator", - ":allocator_metric_proxy", ":metrics", + ":tracking_allocator", "//pw_metric:metric", "//pw_status", "//pw_tokenizer", @@ -229,6 +214,21 @@ cc_library( ], ) +cc_library( + name = "tracking_allocator", + hdrs = [ + "public/pw_allocator/tracking_allocator.h", + ], + includes = ["public"], + deps = [ + ":allocator", + ":metrics", + "//pw_assert", + "//pw_metric:metric", + "//pw_status", + ], +) + cc_library( name = "allocator_testing", testonly = True, @@ -241,10 +241,10 @@ cc_library( includes = ["public"], deps = [ ":allocator", - ":allocator_metric_proxy", ":block", ":buffer", ":simple_allocator", + ":tracking_allocator", "//pw_assert", "//pw_bytes", "//pw_status", @@ -300,18 +300,6 @@ pw_cc_test( ], ) -pw_cc_test( - name = "allocator_metric_proxy_test", - srcs = [ - "allocator_metric_proxy_test.cc", - ], - deps = [ - ":allocator_metric_proxy", - ":allocator_testing", - "//pw_unit_test", - ], -) - pw_cc_test( name = "block_test", srcs = [ @@ -444,6 +432,18 @@ pw_cc_test( ], ) +pw_cc_test( + name = "tracking_allocator_test", + srcs = [ + "tracking_allocator_test.cc", + ], + deps = [ + ":allocator_testing", + ":tracking_allocator", + "//pw_unit_test", + ], +) + pw_cc_test( name = "unique_ptr_test", srcs = [ diff --git a/pw_allocator/BUILD.gn b/pw_allocator/BUILD.gn index 30f9a428e6..7bb6dd551c 100644 --- a/pw_allocator/BUILD.gn +++ b/pw_allocator/BUILD.gn @@ -59,18 +59,6 @@ pw_source_set("allocator") { sources = [ "allocator.cc" ] } -pw_source_set("allocator_metric_proxy") { - public_configs = [ ":default_config" ] - public = [ "public/pw_allocator/allocator_metric_proxy.h" ] - public_deps = [ - ":allocator", - ":metrics", - dir_pw_metric, - dir_pw_status, - ] - deps = [ dir_pw_assert ] -} - pw_source_set("block") { public_configs = [ ":default_config", @@ -98,8 +86,8 @@ pw_source_set("fallback_allocator") { public = [ "public/pw_allocator/fallback_allocator.h" ] public_deps = [ ":allocator", - ":allocator_metric_proxy", ":metrics", + ":tracking_allocator", dir_pw_metric, dir_pw_status, dir_pw_tokenizer, @@ -207,6 +195,18 @@ pw_source_set("synchronized_allocator") { ] } +pw_source_set("tracking_allocator") { + public_configs = [ ":default_config" ] + public = [ "public/pw_allocator/tracking_allocator.h" ] + public_deps = [ + ":allocator", + ":metrics", + dir_pw_metric, + dir_pw_status, + ] + deps = [ dir_pw_assert ] +} + pw_size_diff("allocator_size_report") { title = "Sizes of various pw_allocator implementations" binaries = [ @@ -231,7 +231,6 @@ pw_size_diff("allocator_size_report") { pw_test_group("tests") { tests = [ ":allocator_test", - ":allocator_metric_proxy_test", ":synchronized_allocator_test", ":block_test", ":fallback_allocator_test", @@ -242,6 +241,7 @@ pw_test_group("tests") { ":null_allocator_test", ":simple_allocator_test", ":split_free_list_allocator_test", + ":tracking_allocator_test", ":unique_ptr_test", ] } @@ -250,11 +250,11 @@ pw_source_set("allocator_testing") { public = [ "public/pw_allocator/allocator_testing.h" ] public_deps = [ ":allocator", - ":allocator_metric_proxy", ":block", ":buffer", ":metrics", ":simple_allocator", + ":tracking_allocator", dir_pw_bytes, dir_pw_status, dir_pw_unit_test, @@ -295,11 +295,6 @@ pw_test("allocator_test") { sources = [ "allocator_test.cc" ] } -pw_test("allocator_metric_proxy_test") { - deps = [ ":allocator_testing" ] - sources = [ "allocator_metric_proxy_test.cc" ] -} - pw_test("block_test") { configs = [ ":enable_heap_poison" ] deps = [ @@ -395,6 +390,11 @@ pw_test("synchronized_allocator_test") { sources = [ "synchronized_allocator_test.cc" ] } +pw_test("tracking_allocator_test") { + deps = [ ":allocator_testing" ] + sources = [ "tracking_allocator_test.cc" ] +} + pw_test("unique_ptr_test") { deps = [ ":allocator_testing" ] sources = [ "unique_ptr_test.cc" ] diff --git a/pw_allocator/CMakeLists.txt b/pw_allocator/CMakeLists.txt index a8b7a3f39f..322fe51515 100644 --- a/pw_allocator/CMakeLists.txt +++ b/pw_allocator/CMakeLists.txt @@ -37,18 +37,6 @@ pw_add_library(pw_allocator.allocator STATIC allocator.cc ) -pw_add_library(pw_allocator.allocator_metric_proxy INTERFACE - HEADERS - public/pw_allocator/allocator_metric_proxy.h - PUBLIC_INCLUDES - public - PUBLIC_DEPS - pw_allocator.allocator - pw_allocator.metrics - pw_metric - pw_status -) - pw_add_library(pw_allocator.block STATIC PUBLIC_DEFINES ${enable_heap_poison} @@ -82,8 +70,8 @@ pw_add_library(pw_allocator.fallback_allocator INTERFACE public PUBLIC_DEPS pw_allocator.allocator - pw_allocator.allocator_metric_proxy pw_allocator.metrics + pw_allocator.tracking_allocator pw_metric pw_status pw_tokenizer @@ -206,6 +194,18 @@ pw_add_library(pw_allocator.synchronized_allocator INTERFACE pw_sync.borrow ) +pw_add_library(pw_allocator.tracking_allocator INTERFACE + HEADERS + public/pw_allocator/tracking_allocator.h + PUBLIC_INCLUDES + public + PUBLIC_DEPS + pw_allocator.allocator + pw_allocator.metrics + pw_metric + pw_status +) + pw_add_library(pw_allocator.allocator_testing STATIC HEADERS public/pw_allocator/allocator_testing.h @@ -213,10 +213,10 @@ pw_add_library(pw_allocator.allocator_testing STATIC public PUBLIC_DEPS pw_allocator.allocator - pw_allocator.allocator_metric_proxy pw_allocator.block pw_allocator.buffer pw_allocator.simple_allocator + pw_allocator.tracking_allocator pw_bytes pw_status pw_unit_test @@ -266,16 +266,6 @@ pw_add_test(pw_allocator.allocator_test pw_allocator ) -pw_add_test(pw_allocator.allocator_metric_proxy_test - SOURCES - allocator_metric_proxy_test.cc - PRIVATE_DEPS - pw_allocator.allocator_testing - GROUPS - modules - pw_allocator -) - pw_add_test(pw_allocator.block_test SOURCES block_test.cc @@ -399,6 +389,16 @@ pw_add_test(pw_allocator.synchronized_allocator_test pw_allocator ) +pw_add_test(pw_allocator.tracking_allocator_test + SOURCES + tracking_allocator_test.cc + PRIVATE_DEPS + pw_allocator.allocator_testing + GROUPS + modules + pw_allocator +) + pw_add_test(pw_allocator.unique_ptr_test SOURCES unique_ptr_test.cc diff --git a/pw_allocator/allocator_testing.cc b/pw_allocator/allocator_testing.cc index 13bc5fe403..0b043b0d3c 100644 --- a/pw_allocator/allocator_testing.cc +++ b/pw_allocator/allocator_testing.cc @@ -27,14 +27,14 @@ Status AllocatorForTestImpl::Init(ByteSpan bytes) { if (auto status = allocator_.Init(bytes); !status.ok()) { return status; } - proxy_.Init(allocator_); + tracker_.Init(allocator_); return OkStatus(); } void AllocatorForTestImpl::Exhaust() { for (auto* block : allocator_.blocks()) { block->MarkUsed(); - proxy_.metric_group().Update(0, block->InnerSize()); + tracker_.metric_group().Update(0, block->InnerSize()); } } @@ -57,25 +57,25 @@ void AllocatorForTestImpl::Reset() { } Status AllocatorForTestImpl::DoQuery(const void* ptr, Layout layout) const { - return proxy_.Query(ptr, layout); + return tracker_.Query(ptr, layout); } void* AllocatorForTestImpl::DoAllocate(Layout layout) { allocate_size_ = layout.size(); - return proxy_.Allocate(layout); + return tracker_.Allocate(layout); } void AllocatorForTestImpl::DoDeallocate(void* ptr, Layout layout) { deallocate_ptr_ = ptr; deallocate_size_ = layout.size(); - return proxy_.Deallocate(ptr, layout); + return tracker_.Deallocate(ptr, layout); } bool AllocatorForTestImpl::DoResize(void* ptr, Layout layout, size_t new_size) { resize_ptr_ = ptr; resize_old_size_ = layout.size(); resize_new_size_ = new_size; - return proxy_.Resize(ptr, layout, new_size); + return tracker_.Resize(ptr, layout, new_size); } } // namespace internal diff --git a/pw_allocator/docs.rst b/pw_allocator/docs.rst index b42b435fb5..0c059f6798 100644 --- a/pw_allocator/docs.rst +++ b/pw_allocator/docs.rst @@ -44,9 +44,6 @@ Other Implemetations -------------------- Provided implementations of the ``Allocator`` interface include: -- ``AllocatorMetricProxy``: Wraps another allocator and records its usage. -- ``AllocatorSyncProxy``: Synchronizes access to another allocator, allowing it - to be used by multiple threads. - ``FallbackAllocator``: Dispatches first to a primary allocator, and, if that fails, to a secondary alloator. - ``LibCAllocator``: Uses ``malloc``, ``realloc``, and ``free``. This should @@ -58,6 +55,9 @@ Provided implementations of the ``Allocator`` interface include: - ``SplitFreeListAllocator``: Tracks memory using ``Block``, and splits large and small allocations between the front and back, respectively, of it memory region in order to reduce fragmentation. +- ``SynchronizedAllocator``: Synchronizes access to another allocator, allowing it + to be used by multiple threads. +- ``TrackingAllocator``: Wraps another allocator and records its usage. UniquePtr ========= @@ -187,21 +187,17 @@ interface, whos costs are shown below. Metric collection ================= -Consumers can use an ``AllocatorMetricProxy`` to wrap an allocator and collect +Consumers can use an ``TrackingAllocator`` to wrap an allocator and collect usage statistics. These statistics are implemented using :ref:`module-pw_metric`. .. code-block:: cpp MyAllocator allocator; - AllocatorMetricProxy proxy(PW_TOKENIZE_STRING_EXPR("my allocator")); - proxy.Init(allocator); + TrackingAllocator tracker(PW_TOKENIZE_STRING_EXPR("my allocator")); + tracker.Init(allocator); // ...Perform various allocations and deallocations... - proxy.Dump(); + tracker.Dump(); Metric collection is controlled using the ``pw_allocator_COLLECT_METRICS`` build argument. If this is unset or ``false``, metric collection is skipped. - -To force metric collection regardless of the build argument, tests may include -the ``"pw_allocator/allocator_metric_proxy_for_tests.h"`` header file and depend -on the ``//pw_allocator:allocator_metric_proxy_for_tests`` target. diff --git a/pw_allocator/public/pw_allocator/allocator_testing.h b/pw_allocator/public/pw_allocator/allocator_testing.h index 92bfc27bb0..4a8c030d04 100644 --- a/pw_allocator/public/pw_allocator/allocator_testing.h +++ b/pw_allocator/public/pw_allocator/allocator_testing.h @@ -16,11 +16,11 @@ #include #include "pw_allocator/allocator.h" -#include "pw_allocator/allocator_metric_proxy.h" #include "pw_allocator/block.h" #include "pw_allocator/buffer.h" #include "pw_allocator/metrics.h" #include "pw_allocator/simple_allocator.h" +#include "pw_allocator/tracking_allocator.h" #include "pw_bytes/span.h" #include "pw_status/status.h" #include "pw_tokenizer/tokenize.h" @@ -39,12 +39,12 @@ class AllocatorForTestImpl : public AllocatorWithMetrics { public: using metrics_type = Metrics; - AllocatorForTestImpl() : proxy_(PW_TOKENIZE_STRING_EXPR("test")) {} + AllocatorForTestImpl() : tracker_(PW_TOKENIZE_STRING_EXPR("test")) {} ~AllocatorForTestImpl() override; - metrics_type& metric_group() override { return proxy_.metric_group(); } + metrics_type& metric_group() override { return tracker_.metric_group(); } const metrics_type& metric_group() const override { - return proxy_.metric_group(); + return tracker_.metric_group(); } size_t allocate_size() const { return allocate_size_; } @@ -89,7 +89,7 @@ class AllocatorForTestImpl : public AllocatorWithMetrics { bool DoResize(void* ptr, Layout layout, size_t new_size) override; SimpleAllocator allocator_; - AllocatorMetricProxyImpl proxy_; + TrackingAllocatorImpl tracker_; bool initialized_ = false; size_t allocate_size_ = 0; diff --git a/pw_allocator/public/pw_allocator/fallback_allocator.h b/pw_allocator/public/pw_allocator/fallback_allocator.h index 87f5b4f828..73785dc528 100644 --- a/pw_allocator/public/pw_allocator/fallback_allocator.h +++ b/pw_allocator/public/pw_allocator/fallback_allocator.h @@ -14,8 +14,8 @@ #pragma once #include "pw_allocator/allocator.h" -#include "pw_allocator/allocator_metric_proxy.h" #include "pw_allocator/metrics.h" +#include "pw_allocator/tracking_allocator.h" #include "pw_metric/metric.h" #include "pw_status/status.h" #include "pw_tokenizer/tokenize.h" @@ -85,7 +85,7 @@ class FallbackAllocatorImpl : public AllocatorWithMetrics { } Allocator* primary_ = nullptr; - AllocatorMetricProxyImpl secondary_; + TrackingAllocatorImpl secondary_; }; /// Fallback allocator that uses the default metrics implementation. diff --git a/pw_allocator/public/pw_allocator/allocator_metric_proxy.h b/pw_allocator/public/pw_allocator/tracking_allocator.h similarity index 86% rename from pw_allocator/public/pw_allocator/allocator_metric_proxy.h rename to pw_allocator/public/pw_allocator/tracking_allocator.h index c5aa2e600b..994a369e7b 100644 --- a/pw_allocator/public/pw_allocator/allocator_metric_proxy.h +++ b/pw_allocator/public/pw_allocator/tracking_allocator.h @@ -27,21 +27,21 @@ namespace pw::allocator { /// Metric collection is performed using the provided template parameter type. /// Callers can not instantiate this class directly, as it lacks a public /// constructor. Instead, callers should use derived classes which provide the -/// template parameter type, such as `AllocatorMetricProxy` which uses the -/// default metrics implementation, or `AllocatorMetricProxyForTest` which +/// template parameter type, such as `TrackingAllocator` which uses the +/// default metrics implementation, or `TrackingAllocatorForTest` which /// always uses the real metrics implementation. template -class AllocatorMetricProxyImpl : public AllocatorWithMetrics { +class TrackingAllocatorImpl : public AllocatorWithMetrics { public: using metrics_type = MetricsType; /// Constexpr constructor. Callers must explicitly call `Init`. - constexpr explicit AllocatorMetricProxyImpl(metric::Token token) + constexpr explicit TrackingAllocatorImpl(metric::Token token) : allocator_(nullptr), metrics_(token) {} /// Non-constexpr constructor that automatically invokes `Init`. - AllocatorMetricProxyImpl(metric::Token token, Allocator& allocator) - : AllocatorMetricProxyImpl(token) { + TrackingAllocatorImpl(metric::Token token, Allocator& allocator) + : TrackingAllocatorImpl(token) { Init(allocator); } @@ -103,6 +103,6 @@ class AllocatorMetricProxyImpl : public AllocatorWithMetrics { /// Depending on the value of the `pw_allocator_COLLECT_METRICS` build argument, /// the `internal::DefaultMetrics` type is an alias for either the real or stub /// metrics implementation. -using AllocatorMetricProxy = AllocatorMetricProxyImpl; +using TrackingAllocator = TrackingAllocatorImpl; } // namespace pw::allocator diff --git a/pw_allocator/size_report/BUILD.bazel b/pw_allocator/size_report/BUILD.bazel index 3f1e5345b6..886a26f03e 100644 --- a/pw_allocator/size_report/BUILD.bazel +++ b/pw_allocator/size_report/BUILD.bazel @@ -25,7 +25,6 @@ pw_cc_binary( name = "split_free_list_allocator", srcs = ["split_free_list_allocator.cc"], deps = [ - "//pw_allocator:allocator_metric_proxy", "//pw_allocator:split_free_list_allocator", "//pw_bloat:bloat_this_binary", ], @@ -36,7 +35,6 @@ pw_cc_binary( srcs = ["split_free_list_allocator.cc"], copts = ["-DSIZE_REPORT_UNIQUE_PTR=1"], deps = [ - "//pw_allocator:allocator_metric_proxy", "//pw_allocator:split_free_list_allocator", "//pw_bloat:bloat_this_binary", ], @@ -45,10 +43,10 @@ pw_cc_binary( pw_cc_binary( name = "split_free_list_allocator_with_metric_proxy", srcs = ["split_free_list_allocator.cc"], - copts = ["-DSIZE_REPORT_METRIC_PROXY=1"], + copts = ["-DSIZE_REPORT_WITH_METRICS=1"], deps = [ - "//pw_allocator:allocator_metric_proxy", "//pw_allocator:split_free_list_allocator", + "//pw_allocator:tracking_allocator", "//pw_bloat:bloat_this_binary", ], ) diff --git a/pw_allocator/size_report/BUILD.gn b/pw_allocator/size_report/BUILD.gn index 1f73b0a688..db75f10f61 100644 --- a/pw_allocator/size_report/BUILD.gn +++ b/pw_allocator/size_report/BUILD.gn @@ -17,19 +17,19 @@ import("//build_overrides/pigweed.gni") import("$dir_pw_build/target_types.gni") pw_executable("split_free_list_allocator") { + check_includes = false sources = [ "split_free_list_allocator.cc" ] deps = [ "$dir_pw_bloat:bloat_this_binary", - "..:allocator_metric_proxy", "..:split_free_list_allocator", ] } pw_executable("split_free_list_allocator_with_unique_ptr") { + check_includes = false sources = [ "split_free_list_allocator.cc" ] deps = [ "$dir_pw_bloat:bloat_this_binary", - "..:allocator_metric_proxy", "..:split_free_list_allocator", ] defines = [ "SIZE_REPORT_UNIQUE_PTR=1" ] @@ -39,8 +39,8 @@ pw_executable("split_free_list_allocator_with_metric_proxy") { sources = [ "split_free_list_allocator.cc" ] deps = [ "$dir_pw_bloat:bloat_this_binary", - "..:allocator_metric_proxy", "..:split_free_list_allocator", + "..:tracking_allocator", ] - defines = [ "SIZE_REPORT_METRIC_PROXY=1" ] + defines = [ "SIZE_REPORT_WITH_METRICS=1" ] } diff --git a/pw_allocator/size_report/split_free_list_allocator.cc b/pw_allocator/size_report/split_free_list_allocator.cc index cac2ecfdda..dbe9c8340f 100644 --- a/pw_allocator/size_report/split_free_list_allocator.cc +++ b/pw_allocator/size_report/split_free_list_allocator.cc @@ -23,17 +23,17 @@ #include "pw_bloat/bloat_this_binary.h" -#ifdef SIZE_REPORT_METRIC_PROXY -#include "pw_allocator/allocator_metric_proxy.h" -#endif // SIZE_REPORT_METRIC_PROXY +#ifdef SIZE_REPORT_WITH_METRICS +#include "pw_allocator/tracking_allocator.h" +#endif // SIZE_REPORT_WITH_METRICS namespace { pw::allocator::SplitFreeListAllocator allocator; -#ifdef SIZE_REPORT_METRIC_PROXY -pw::allocator::AllocatorMetricProxy proxy(0); -#endif // SIZE_REPORT_METRIC_PROXY +#ifdef SIZE_REPORT_WITH_METRICS +pw::allocator::TrackingAllocator tracker(0); +#endif // SIZE_REPORT_WITH_METRICS constexpr void* kFakeMemoryRegionStart = &allocator; constexpr size_t kFakeMemoryRegionSize = 4096; @@ -113,19 +113,19 @@ int main() { #endif // SIZE_REPORT_UNIQUE_PTR -#ifdef SIZE_REPORT_METRIC_PROXY - proxy.Init(allocator); +#ifdef SIZE_REPORT_WITH_METRICS + tracker.Init(allocator); Foo* foo2 = - static_cast(proxy.Allocate(pw::allocator::Layout::Of())); + static_cast(tracker.Allocate(pw::allocator::Layout::Of())); if (foo2 == nullptr) { return 1; } foo2->name[1] = 'a'; - proxy.Deallocate(foo2, pw::allocator::Layout::Of()); -#endif // SIZE_REPORT_METRIC_PROXY + tracker.Deallocate(foo2, pw::allocator::Layout::Of()); +#endif // SIZE_REPORT_WITH_METRICS return 0; } diff --git a/pw_allocator/allocator_metric_proxy_test.cc b/pw_allocator/tracking_allocator_test.cc similarity index 85% rename from pw_allocator/allocator_metric_proxy_test.cc rename to pw_allocator/tracking_allocator_test.cc index 94299eae95..970764ff6a 100644 --- a/pw_allocator/allocator_metric_proxy_test.cc +++ b/pw_allocator/tracking_allocator_test.cc @@ -12,7 +12,7 @@ // License for the specific language governing permissions and limitations under // the License. -#include "pw_allocator/allocator_metric_proxy.h" +#include "pw_allocator/tracking_allocator.h" #include "pw_allocator/allocator_testing.h" #include "pw_unit_test/framework.h" @@ -22,41 +22,41 @@ namespace { // These unit tests below use `AllocatorForTest`, which forwards // `Allocator` calls to a field of type -// `AllocatorMetricProxyImpl`. This is the same type as -// `AllocatorMetricProxy`, except that metrics are explicitly enabled. As a -// result, these unit tests do validate `AllocatorMetricProxy`, even when that +// `TrackingAllocatorImpl`. This is the same type as +// `TrackingAllocator`, except that metrics are explicitly enabled. As a +// result, these unit tests do validate `TrackingAllocator`, even when that // type never appears directly in a test. -TEST(AllocatorMetricProxyTest, ExplicitlyInitialized) { +TEST(TrackingAllocatorTest, ExplicitlyInitialized) { WithBuffer allocator; - AllocatorMetricProxyImpl proxy(test::kToken); + TrackingAllocatorImpl tracker(test::kToken); - metric::Group& group = proxy.metric_group(); + metric::Group& group = tracker.metric_group(); EXPECT_EQ(group.metrics().size(), 0U); EXPECT_EQ(group.children().size(), 0U); - proxy.Init(*allocator); + tracker.Init(*allocator); EXPECT_EQ(group.metrics().size(), 3U); EXPECT_EQ(group.children().size(), 0U); } -TEST(AllocatorMetricProxyTest, AutomaticallyInitialized) { +TEST(TrackingAllocatorTest, AutomaticallyInitialized) { WithBuffer allocator; - AllocatorMetricProxyImpl proxy(test::kToken, *allocator); + TrackingAllocatorImpl tracker(test::kToken, *allocator); - metric::Group& group = proxy.metric_group(); + metric::Group& group = tracker.metric_group(); EXPECT_EQ(group.metrics().size(), 3U); EXPECT_EQ(group.children().size(), 0U); } -TEST(AllocatorMetricProxyTest, InitiallyZero) { +TEST(TrackingAllocatorTest, InitiallyZero) { test::AllocatorForTest<256> allocator; EXPECT_EQ(allocator->used(), 0U); EXPECT_EQ(allocator->peak(), 0U); EXPECT_EQ(allocator->count(), 0U); } -TEST(AllocatorMetricProxyTest, AllocateDeallocate) { +TEST(TrackingAllocatorTest, AllocateDeallocate) { test::AllocatorForTest<256> allocator; constexpr Layout layout = Layout::Of(); void* ptr = allocator->Allocate(layout); @@ -71,7 +71,7 @@ TEST(AllocatorMetricProxyTest, AllocateDeallocate) { EXPECT_EQ(allocator->count(), 0U); } -TEST(AllocatorMetricProxyTest, AllocateFailure) { +TEST(TrackingAllocatorTest, AllocateFailure) { test::AllocatorForTest<256> allocator; constexpr Layout layout = Layout::Of(); void* ptr = allocator->Allocate(layout); @@ -81,7 +81,7 @@ TEST(AllocatorMetricProxyTest, AllocateFailure) { EXPECT_EQ(allocator->count(), 0U); } -TEST(AllocatorMetricProxyTest, AllocateDeallocateMultiple) { +TEST(TrackingAllocatorTest, AllocateDeallocateMultiple) { test::AllocatorForTest<256> allocator; constexpr Layout layout1 = Layout::Of(); void* ptr1 = allocator->Allocate(layout1); @@ -108,7 +108,7 @@ TEST(AllocatorMetricProxyTest, AllocateDeallocateMultiple) { EXPECT_EQ(allocator->count(), 0U); } -TEST(AllocatorMetricProxyTest, ResizeLarger) { +TEST(TrackingAllocatorTest, ResizeLarger) { test::AllocatorForTest<256> allocator; constexpr Layout old_layout = Layout::Of(); void* ptr = allocator->Allocate(old_layout); @@ -129,7 +129,7 @@ TEST(AllocatorMetricProxyTest, ResizeLarger) { EXPECT_EQ(allocator->count(), 0U); } -TEST(AllocatorMetricProxyTest, ResizeSmaller) { +TEST(TrackingAllocatorTest, ResizeSmaller) { test::AllocatorForTest<256> allocator; constexpr Layout old_layout = Layout::Of(); void* ptr = allocator->Allocate(old_layout); @@ -150,7 +150,7 @@ TEST(AllocatorMetricProxyTest, ResizeSmaller) { EXPECT_EQ(allocator->count(), 0U); } -TEST(AllocatorMetricProxyTest, Reallocate) { +TEST(TrackingAllocatorTest, Reallocate) { test::AllocatorForTest<256> allocator; constexpr Layout old_layout = Layout::Of(); void* ptr1 = allocator->Allocate(old_layout);