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


##########
cpp/src/arrow/util/io_util.cc:
##########
@@ -1867,5 +1878,44 @@ 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 0;
+  }
+  return static_cast<int64_t>(info.resident_size);
+
+#elif defined(__linux__) || defined(__linux) || defined(linux) || 
defined(__gnu_linux__)

Review Comment:
   ```suggestion
   #elif defined(__linux__)
   ```



##########
cpp/src/arrow/util/io_util_test.cc:
##########
@@ -719,5 +719,17 @@ TEST(SendSignal, ToThread) {
 #endif
 }
 
+TEST(Memory, GetRSS) {
+#if defined(_WIN32)
+  ASSERT_GT(GetCurrentRSS(), 0);
+#elif defined(__APPLE__)
+  ASSERT_GT(GetCurrentRSS(), 0);
+#elif defined(__linux__) || defined(__linux) || defined(linux) || 
defined(__gnu_linux__)

Review Comment:
   ```suggestion
   #elif defined(__linux__)
   ```



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