pitrou commented on code in PR #13516:
URL: https://github.com/apache/arrow/pull/13516#discussion_r972786764


##########
cpp/src/arrow/memory_pool_jemalloc.cc:
##########
@@ -153,4 +154,52 @@ Status jemalloc_set_decay_ms(int ms) {
 
 #undef RETURN_IF_JEMALLOC_ERROR
 
+#ifdef ARROW_JEMALLOC
+Result<uint64_t> jemalloc_get_stat(const char* name) {
+  size_t sz = sizeof(uint64_t);
+  int err;
+  uint64_t value;
+
+  if (std::strcmp(name, "stats.allocated") == 0 ||
+      std::strcmp(name, "stats.active") == 0 ||
+      std::strcmp(name, "stats.metadata") == 0 ||
+      std::strcmp(name, "stats.resident") == 0 ||
+      std::strcmp(name, "stats.mapped") == 0 ||
+      std::strcmp(name, "stats.retained") == 0) {
+    uint64_t epoch;
+    mallctl("epoch", &epoch, &sz, &epoch, sz);
+  }
+
+  err = mallctl(name, &value, &sz, NULLPTR, 0);
+
+  if (err) {
+    return arrow::internal::IOErrorFromErrno(err, "Failed retrieving ", &name);
+  }
+
+  return value;
+}
+
+Status jemalloc_peak_reset() {
+  int err = mallctl("thread.peak.reset", NULLPTR, NULLPTR, NULLPTR, 0);
+  return err ? arrow::internal::IOErrorFromErrno(err, "Failed resetting 
thread.peak.")
+             : Status::OK();
+}
+
+Result<std::string> jemalloc_stats_print(const char* opts) {
+  std::string stats;
+  auto write_cb = [](void* opaque, const char* str) {
+    reinterpret_cast<std::string*>(opaque)->append(str);
+  };
+  malloc_stats_print(write_cb, &stats, opts);
+  return stats;
+}
+
+Status jemalloc_stats_print(std::function<void(void* opaque, const char* 
buf)>* write_cb,
+                            void* cbopaque, const char* opts) {
+  malloc_stats_print(reinterpret_cast<void (*)(void*, const char*)>(write_cb), 
cbopaque,

Review Comment:
   ?? You cannot blindly cast a `std::function` to a plain function pointer.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to