szaszm commented on a change in pull request #845:
URL: https://github.com/apache/nifi-minifi-cpp/pull/845#discussion_r463076019



##########
File path: libminifi/src/utils/OsUtils.cpp
##########
@@ -154,6 +164,41 @@ std::string OsUtils::userIdToUsername(const std::string 
&uid) {
   return name;
 }
 
+uint64_t OsUtils::getMemoryUsage() {
+#ifdef __linux__
+  static const std::string linePrefix = "VmRSS:";
+  std::ifstream statusFile("/proc/self/status");
+  std::string line;
+
+  while (std::getline(statusFile, line)) {
+    // if line begins with "VmRSS:"
+    if (line.rfind(linePrefix, 0) == 0) {
+      std::istringstream valuableLine(line.substr(linePrefix.length()));
+      uint64_t kByteValue;
+      valuableLine >> kByteValue;
+      return kByteValue * 1024;
+    }
+  }
+
+  throw std::runtime_error("Could not get memory info for current process");
+#endif
+
+#ifdef __APPLE__
+  task_basic_info tInfo;
+  mach_msg_type_number_t tInfoCount = TASK_BASIC_INFO_COUNT;
+  if (KERN_SUCCESS != task_info(mach_task_self(), TASK_BASIC_INFO, 
(task_info_t)&tInfo, &tInfoCount))
+    throw std::runtime_error("Could not get memory info for current process");
+  return tInfo.resident_size;
+#endif
+
+#ifdef _WIN32
+  PROCESS_MEMORY_COUNTERS pmc;
+  if (!GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)))
+    throw std::runtime_error("Could not get memory info for current process");
+  return pmc.WorkingSetSize;
+#endif
+}

Review comment:
       ea9ef69 is about right but incorrectly indented




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

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


Reply via email to