Skip to content
Snippets Groups Projects
Commit 91caf63c authored by Rye Mutt's avatar Rye Mutt :bread:
Browse files

Merge branch 'getCurrentRSS' into 'main'

refactor ugly getCurrentRSS for linux

See merge request alchemy/alchemy-next!119
parents 0ad56dc8 ff94f0a9
No related branches found
No related tags found
2 merge requests!3Update to main branch,!2Rebase onto current main branch
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#elif LL_LINUX #elif LL_LINUX
# include <unistd.h> # include <unistd.h>
# include <sys/sysinfo.h> # include <sys/sysinfo.h>
# include <sys/resource.h>
#endif #endif
#include "llmemory.h" #include "llmemory.h"
...@@ -290,33 +291,16 @@ U64 LLMemory::getCurrentRSS() ...@@ -290,33 +291,16 @@ U64 LLMemory::getCurrentRSS()
U64 LLMemory::getCurrentRSS() U64 LLMemory::getCurrentRSS()
{ {
static const char statPath[] = "/proc/self/stat"; struct rusage usage;
LLFILE *fp = LLFile::fopen(statPath, "r");
U64 rss = 0;
if (fp == NULL) if (getrusage(RUSAGE_SELF, &usage) != 0) {
{ // Error handling code
LL_WARNS() << "couldn't open " << statPath << LL_ENDL;
return 0; return 0;
} }
// Eee-yew! See Documentation/filesystems/proc.txt in your // ru_maxrss (since Linux 2.6.32)
// nearest friendly kernel tree for details. // This is the maximum resident set size used (in kilobytes).
return usage.ru_maxrss * 1024;
{
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;
} }
#else #else
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment