szaszm commented on a change in pull request #845:
URL: https://github.com/apache/nifi-minifi-cpp/pull/845#discussion_r459425267
##########
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:
+1 for no `long`. If you need a 64 bit integer, why not make it explicit
by using `int64_t`?
https://google.github.io/styleguide/cppguide.html#Integer_Types
Other issue: I believe `statm` doesn't make a difference between normal
pages and hugepages, so while the number may be correct as the number of pages,
multiplying it with the default page size might yield an incorrect "memory
usage".
https://stackoverflow.com/questions/1558402/memory-usage-of-current-process-in-c#comment93410400_7212248
----------------------------------------------------------------
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]