11
11
#include < benchmark/benchmark.h>
12
12
#include < umf/memory_pool.h>
13
13
#include < umf/memory_provider.h>
14
-
15
- #include < benchmark/benchmark.h>
16
14
#include < umf/pools/pool_disjoint.h>
17
15
#include < umf/pools/pool_proxy.h>
18
16
@@ -30,7 +28,7 @@ struct provider_interface {
30
28
using params_ptr = std::unique_ptr<void , void (*)(void *)>;
31
29
32
30
umf_memory_provider_handle_t provider = NULL ;
33
- virtual void SetUp (::benchmark::State &state) {
31
+ void SetUp (::benchmark::State &state) {
34
32
if (state.thread_index () != 0 ) {
35
33
return ;
36
34
}
@@ -42,7 +40,27 @@ struct provider_interface {
42
40
}
43
41
}
44
42
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) {
46
64
if (state.thread_index () != 0 ) {
47
65
return ;
48
66
}
@@ -53,9 +71,7 @@ struct provider_interface {
53
71
}
54
72
55
73
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 ;
59
75
60
76
virtual params_ptr getParams ([[maybe_unused]] ::benchmark::State &state) {
61
77
return {nullptr , [](void *) {}};
@@ -68,7 +84,7 @@ template <typename T,
68
84
struct pool_interface {
69
85
using params_ptr = std::unique_ptr<void , void (*)(void *)>;
70
86
71
- virtual void SetUp (::benchmark::State &state) {
87
+ void SetUp (::benchmark::State &state) {
72
88
provider.SetUp (state);
73
89
if (state.thread_index () != 0 ) {
74
90
return ;
@@ -80,7 +96,22 @@ struct pool_interface {
80
96
state.SkipWithError (" umfPoolCreate() failed" );
81
97
}
82
98
}
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) {
84
115
if (state.thread_index () != 0 ) {
85
116
return ;
86
117
}
@@ -93,15 +124,17 @@ struct pool_interface {
93
124
if (pool) {
94
125
umfPoolDestroy (pool);
95
126
}
127
+
128
+ provider.TearDown (state);
96
129
};
97
130
98
131
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
+
102
134
virtual params_ptr getParams ([[maybe_unused]] ::benchmark::State &state) {
103
135
return {nullptr , [](void *) {}};
104
136
}
137
+
105
138
T provider;
106
139
umf_memory_pool_handle_t pool;
107
140
};
@@ -110,6 +143,8 @@ class allocator_interface {
110
143
public:
111
144
virtual unsigned SetUp ([[maybe_unused]] ::benchmark::State &state,
112
145
[[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;
113
148
virtual void TearDown ([[maybe_unused]] ::benchmark::State &state) = 0;
114
149
virtual void *benchAlloc (size_t size) = 0;
115
150
virtual void benchFree (void *ptr, [[maybe_unused]] size_t size) = 0;
@@ -121,7 +156,9 @@ struct glibc_malloc : public allocator_interface {
121
156
unsigned argPos) override {
122
157
return argPos;
123
158
}
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 {}
125
162
void *benchAlloc (size_t size) override { return malloc (size); }
126
163
void benchFree (void *ptr, [[maybe_unused]] size_t size) override {
127
164
free (ptr);
@@ -163,7 +200,7 @@ struct fixed_provider : public provider_interface {
163
200
char *mem = NULL ;
164
201
const size_t size = 1024 * 1024 * 1024 ; // 1GB
165
202
public:
166
- virtual void SetUp (::benchmark::State &state) override {
203
+ void SetUp (::benchmark::State &state) {
167
204
if (state.thread_index () != 0 ) {
168
205
return ;
169
206
}
@@ -175,7 +212,7 @@ struct fixed_provider : public provider_interface {
175
212
provider_interface::SetUp (state);
176
213
}
177
214
178
- virtual void TearDown (::benchmark::State &state) override {
215
+ void TearDown (::benchmark::State &state) {
179
216
if (state.thread_index () != 0 ) {
180
217
return ;
181
218
}
@@ -295,7 +332,7 @@ struct jemalloc_pool : public pool_interface<Provider> {
295
332
#ifdef UMF_POOL_SCALABLE_ENABLED
296
333
template <typename Provider>
297
334
struct scalable_pool : public pool_interface <Provider> {
298
- virtual umf_memory_pool_ops_t *
335
+ umf_memory_pool_ops_t *
299
336
getOps ([[maybe_unused]] ::benchmark::State &state) override {
300
337
return umfScalablePoolOps ();
301
338
}
0 commit comments