You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/07/22 13:54:42 UTC

[GitHub] [nifi-minifi-cpp] adam-markovics commented on a change in pull request #845: MINIFICPP-1277 - Create cross-platform API for querying memory usage

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



##########
File path: libminifi/include/utils/OsUtils.h
##########
@@ -31,6 +31,12 @@ namespace OsUtils {
  */
 extern std::string userIdToUsername(const std::string &uid);
 
+/**
+ * Returns memory usage in bytes
+ */
+
+unsigned long long getMemoryUsage();

Review comment:
       Done.

##########
File path: libminifi/src/utils/OsUtils.cpp
##########
@@ -154,6 +160,80 @@ std::string OsUtils::userIdToUsername(const std::string &uid) {
   return name;
 }
 
+unsigned long long OsUtils::getMemoryUsage() {
+#ifdef __linux__
+  long resPages;
+  long sharedPages;
+  {
+    std::string ignore;
+    std::ifstream ifs("/proc/self/statm");
+    ifs >> ignore >> resPages >> sharedPages;
+  }
+
+  if (sharedPages > resPages) {
+    throw std::range_error("Shared memory page count ("
+      + std::to_string(sharedPages)
+      + ") should not be larger than resident set size ("
+      + std::to_string(resPages)
+      + "), that includes it"
+    );
+  }
+
+  const long ownPages = resPages - sharedPages;

Review comment:
       This code is Linux-only. Man says values in /proc/self/statm will be long: https://man7.org/linux/man-pages/man5/proc.5.html. Page size is usually 4096, memory usage value should definitely fit 64 bytes even after multiplication.




----------------------------------------------------------------
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:
users@infra.apache.org