summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
authorMiezhiko <Miezhiko@gmail.com>2023-10-31 10:58:09 +0400
committerAndrey Lihatskiy <alihatskiy@productengine.com>2023-11-20 18:30:32 +0200
commit9bd1ef1cf82d7fcbbcd8d942cc355d47b1fbe47f (patch)
tree7b0544704e0383649fd3756f0e0d5fbd9741bc52 /indra/llcommon
parent6abeb9983e0f8a937c84f67a17a6dcc4d6484698 (diff)
llmemory: use getrusage for getCurrentRSS on linux
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/llmemory.cpp30
1 files changed, 7 insertions, 23 deletions
diff --git a/indra/llcommon/llmemory.cpp b/indra/llcommon/llmemory.cpp
index d6ae1284d3..aa6519ea44 100644
--- a/indra/llcommon/llmemory.cpp
+++ b/indra/llcommon/llmemory.cpp
@@ -37,6 +37,7 @@
# include <mach/mach_init.h>
#elif LL_LINUX
# include <unistd.h>
+# include <sys/resource.h>
#endif
#include "llmemory.h"
@@ -228,33 +229,16 @@ U64 LLMemory::getCurrentRSS()
U64 LLMemory::getCurrentRSS()
{
- static const char statPath[] = "/proc/self/stat";
- LLFILE *fp = LLFile::fopen(statPath, "r");
- U64 rss = 0;
+ struct rusage usage;
- if (fp == NULL)
- {
- LL_WARNS() << "couldn't open " << statPath << LL_ENDL;
+ if (getrusage(RUSAGE_SELF, &usage) != 0) {
+ // Error handling code could be here
return 0;
}
- // Eee-yew! See Documentation/filesystems/proc.txt in your
- // nearest friendly kernel tree for details.
-
- {
- int ret = fscanf(fp, "%*d (%*[^)]) %*c %*d %*d %*d %*d %*d %*d %*d "
- "%*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %*d %Lu",
- &rss);
- if (ret != 1)
- {
- LL_WARNS() << "couldn't parse contents of " << statPath << LL_ENDL;
- rss = 0;
- }
- }
-
- fclose(fp);
-
- return rss;
+ // ru_maxrss (since Linux 2.6.32)
+ // This is the maximum resident set size used (in kilobytes).
+ return usage.ru_maxrss * 1024;
}
#else