1111#include < benchmark/benchmark.h>
1212#include < umf/memory_pool.h>
1313#include < umf/memory_provider.h>
14-
15- #include < benchmark/benchmark.h>
1614#include < umf/pools/pool_disjoint.h>
1715#include < umf/pools/pool_proxy.h>
1816
@@ -30,7 +28,7 @@ struct provider_interface {
3028 using params_ptr = std::unique_ptr<void , void (*)(void *)>;
3129
3230 umf_memory_provider_handle_t provider = NULL ;
33- virtual void SetUp (::benchmark::State &state) {
31+ void SetUp (::benchmark::State &state) {
3432 if (state.thread_index () != 0 ) {
3533 return ;
3634 }
@@ -42,7 +40,27 @@ struct provider_interface {
4240 }
4341 }
4442
45- virtual void TearDown ([[maybe_unused]] ::benchmark::State &state) {
43+ void preBench ([[maybe_unused]] ::benchmark::State &state) {
44+ if (state.thread_index () != 0 ) {
45+ return ;
46+ }
47+ umfCtlExec (" umf.provider.by_handle.stats.reset" , provider, NULL );
48+ }
49+
50+ void postBench ([[maybe_unused]] ::benchmark::State &state) {
51+ if (state.thread_index () != 0 ) {
52+ return ;
53+ }
54+ size_t arg;
55+ umf_result_t ret = umfCtlGet (
56+ " umf.provider.by_handle.stats.allocated_memory" , provider, &arg);
57+ if (ret == UMF_RESULT_SUCCESS) {
58+ state.counters [" provider_memory_allocated" ] =
59+ static_cast <double >(arg);
60+ }
61+ }
62+
63+ void TearDown ([[maybe_unused]] ::benchmark::State &state) {
4664 if (state.thread_index () != 0 ) {
4765 return ;
4866 }
@@ -53,9 +71,7 @@ struct provider_interface {
5371 }
5472
5573 virtual umf_memory_provider_ops_t *
56- getOps ([[maybe_unused]] ::benchmark::State &state) {
57- return nullptr ;
58- }
74+ getOps ([[maybe_unused]] ::benchmark::State &state) = 0 ;
5975
6076 virtual params_ptr getParams ([[maybe_unused]] ::benchmark::State &state) {
6177 return {nullptr , [](void *) {}};
@@ -68,7 +84,7 @@ template <typename T,
6884struct pool_interface {
6985 using params_ptr = std::unique_ptr<void , void (*)(void *)>;
7086
71- virtual void SetUp (::benchmark::State &state) {
87+ void SetUp (::benchmark::State &state) {
7288 provider.SetUp (state);
7389 if (state.thread_index () != 0 ) {
7490 return ;
@@ -80,7 +96,22 @@ struct pool_interface {
8096 state.SkipWithError (" umfPoolCreate() failed" );
8197 }
8298 }
83- virtual void TearDown ([[maybe_unused]] ::benchmark::State &state) {
99+
100+ void preBench ([[maybe_unused]] ::benchmark::State &state) {
101+ provider.preBench (state);
102+ if (state.thread_index () != 0 ) {
103+ return ;
104+ }
105+ }
106+
107+ void postBench ([[maybe_unused]] ::benchmark::State &state) {
108+ provider.postBench (state);
109+ if (state.thread_index () != 0 ) {
110+ return ;
111+ }
112+ }
113+
114+ void TearDown ([[maybe_unused]] ::benchmark::State &state) {
84115 if (state.thread_index () != 0 ) {
85116 return ;
86117 }
@@ -93,15 +124,17 @@ struct pool_interface {
93124 if (pool) {
94125 umfPoolDestroy (pool);
95126 }
127+
128+ provider.TearDown (state);
96129 };
97130
98131 virtual umf_memory_pool_ops_t *
99- getOps ([[maybe_unused]] ::benchmark::State &state) {
100- return nullptr ;
101- }
132+ getOps ([[maybe_unused]] ::benchmark::State &state) = 0 ;
133+
102134 virtual params_ptr getParams ([[maybe_unused]] ::benchmark::State &state) {
103135 return {nullptr , [](void *) {}};
104136 }
137+
105138 T provider;
106139 umf_memory_pool_handle_t pool;
107140};
@@ -110,6 +143,8 @@ class allocator_interface {
110143 public:
111144 virtual unsigned SetUp ([[maybe_unused]] ::benchmark::State &state,
112145 [[maybe_unused]] unsigned argPos) = 0;
146+ virtual void preBench ([[maybe_unused]] ::benchmark::State &state) = 0;
147+ virtual void postBench ([[maybe_unused]] ::benchmark::State &state) = 0;
113148 virtual void TearDown ([[maybe_unused]] ::benchmark::State &state) = 0;
114149 virtual void *benchAlloc (size_t size) = 0;
115150 virtual void benchFree (void *ptr, [[maybe_unused]] size_t size) = 0;
@@ -121,7 +156,9 @@ struct glibc_malloc : public allocator_interface {
121156 unsigned argPos) override {
122157 return argPos;
123158 }
124- void TearDown ([[maybe_unused]] ::benchmark::State &state) override {};
159+ void preBench ([[maybe_unused]] ::benchmark::State &state) override {}
160+ void postBench ([[maybe_unused]] ::benchmark::State &state) override {}
161+ void TearDown ([[maybe_unused]] ::benchmark::State &state) override {}
125162 void *benchAlloc (size_t size) override { return malloc (size); }
126163 void benchFree (void *ptr, [[maybe_unused]] size_t size) override {
127164 free (ptr);
@@ -163,7 +200,7 @@ struct fixed_provider : public provider_interface {
163200 char *mem = NULL ;
164201 const size_t size = 1024 * 1024 * 1024 ; // 1GB
165202 public:
166- virtual void SetUp (::benchmark::State &state) override {
203+ void SetUp (::benchmark::State &state) {
167204 if (state.thread_index () != 0 ) {
168205 return ;
169206 }
@@ -175,7 +212,7 @@ struct fixed_provider : public provider_interface {
175212 provider_interface::SetUp (state);
176213 }
177214
178- virtual void TearDown (::benchmark::State &state) override {
215+ void TearDown (::benchmark::State &state) {
179216 if (state.thread_index () != 0 ) {
180217 return ;
181218 }
@@ -295,7 +332,7 @@ struct jemalloc_pool : public pool_interface<Provider> {
295332#ifdef UMF_POOL_SCALABLE_ENABLED
296333template <typename Provider>
297334struct scalable_pool : public pool_interface <Provider> {
298- virtual umf_memory_pool_ops_t *
335+ umf_memory_pool_ops_t *
299336 getOps ([[maybe_unused]] ::benchmark::State &state) override {
300337 return umfScalablePoolOps ();
301338 }
0 commit comments