lidavidm commented on code in PR #12702:
URL: https://github.com/apache/arrow/pull/12702#discussion_r857607333


##########
cpp/src/arrow/util/io_util.cc:
##########
@@ -1867,5 +1879,45 @@ uint64_t GetOptionalThreadId() {
   return (tid == 0) ? tid - 1 : tid;
 }
 
+// Returns the current resident set size (physical memory use) measured
+// in bytes, or zero if the value cannot be determined on this OS.
+int64_t GetCurrentRSS() {
+#if defined(_WIN32)
+  // Windows --------------------------------------------------
+  PROCESS_MEMORY_COUNTERS info;
+  GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
+  return static_cast<int64_t>(info.WorkingSetSize);
+
+#elif defined(__APPLE__)
+  // OSX ------------------------------------------------------
+  struct mach_task_basic_info info;
+  mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT;
+  if (task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&info, 
&infoCount) !=
+      KERN_SUCCESS) {
+    ARROW_LOG(WARNING) << "Can't resolve RSS value";
+    return static_cast<int64_t>(0L);
+  }
+  return static_cast<int64_t>(info.resident_size);
+
+#elif defined(__linux__) || defined(__linux) || defined(linux) || 
defined(__gnu_linux__)
+  // Linux ----------------------------------------------------
+  int64_t rss = 0L;
+
+  std::ifstream fp("/proc/self/statm");
+  if (fp.is_open()) {
+    fp >> rss;
+  } else {
+    ARROW_LOG(WARNING) << "Can't resolve RSS value from /proc/self/statm";
+    return static_cast<int64_t>(0L);
+  }
+  if (fp.is_open()) fp.close();
+  return static_cast<int64_t>(rss) * 
static_cast<int64_t>(sysconf(_SC_PAGESIZE));
+
+#else
+  // AIX, BSD, Solaris, and Unknown OS ------------------------
+  return static_cast<int64_t>(0L);  // Unsupported.

Review Comment:
   @AlvinJ15 there's still unaddressed feedback, can you make sure everything 
is addressed?



-- 
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