Read statistics into std::string
| 269 | |
| 270 | // Read statistics into std::string |
| 271 | ASSERT_OK_AND_ASSIGN(std::string stats, jemalloc_stats_string("Jax")); |
| 272 | |
| 273 | // Read statistics into std::string with a lambda |
| 274 | std::string stats2; |
| 275 | auto write_cb = [&stats2](const char* str) { stats2.append(str); }; |
| 276 | ASSERT_OK(jemalloc_stats_print(write_cb, "Jax")); |
| 277 | |
| 278 | ASSERT_EQ(stats.rfind("{\"jemalloc\":{\"version\"", 0), 0); |
| 279 | ASSERT_EQ(stats2.rfind("{\"jemalloc\":{\"version\"", 0), 0); |
| 280 | ASSERT_EQ(stats.substr(0, 100), stats2.substr(0, 100)); |
| 281 | #else |
| 282 | std::string stats; |
| 283 | auto write_cb = [&stats](const char* str) { stats.append(str); }; |
| 284 | ASSERT_RAISES(NotImplemented, jemalloc_get_stat("thread.peak.read")); |
| 285 | ASSERT_RAISES(NotImplemented, jemalloc_get_stat("stats.allocated")); |
| 286 | ASSERT_RAISES(NotImplemented, jemalloc_get_stat("stats.allocated")); |
| 287 | ASSERT_RAISES(NotImplemented, jemalloc_get_stat("stats.allocatedp")); |
| 288 | ASSERT_RAISES(NotImplemented, jemalloc_peak_reset()); |
| 289 | ASSERT_RAISES(NotImplemented, jemalloc_stats_print(write_cb, "Jax")); |
| 290 | ASSERT_RAISES(NotImplemented, jemalloc_stats_print("ax")); |
| 291 | #endif |
| 292 | } |
| 293 | |
| 294 | class TestCappedMemoryPool : public ::arrow::TestMemoryPoolBase { |
| 295 | public: |
| 296 | MemoryPool* memory_pool() override { return InitPool(/*limit=*/1'000'000'000LL); } |
| 297 | |
| 298 | MemoryPool* InitPool(int64_t limit) { |
| 299 | proxy_memory_pool_ = std::make_shared<ProxyMemoryPool>(default_memory_pool()); |
| 300 | capped_memory_pool_ = |
| 301 | std::make_shared<CappedMemoryPool>(proxy_memory_pool_.get(), limit); |
| 302 | return capped_memory_pool_.get(); |
| 303 | } |
| 304 | |
| 305 | protected: |
| 306 | std::shared_ptr<MemoryPool> proxy_memory_pool_; |
| 307 | std::shared_ptr<CappedMemoryPool> capped_memory_pool_; |
| 308 | }; |
| 309 | |
| 310 | TEST_F(TestCappedMemoryPool, MemoryTracking) { this->TestMemoryTracking(); } |
| 311 | |
| 312 | TEST_F(TestCappedMemoryPool, OOM) { |
| 313 | // CappedMemoryPool rejects the huge allocation without hitting the underlying |
no test coverage detected