Commit eb791c02 authored by Leif Walsh's avatar Leif Walsh Committed by Yoni Fogel

refs #5368 clean up toku_os_get_*rss


git-svn-id: file:///svn/toku/tokudb@48339 c7de825b-a66e-492c-adef-691d508d4ae1
parent 2e7d2d44
...@@ -192,21 +192,20 @@ toku_os_initialize_settings(int UU(verbosity)) { ...@@ -192,21 +192,20 @@ toku_os_initialize_settings(int UU(verbosity)) {
int int
toku_os_get_max_rss(int64_t *maxrss) { toku_os_get_max_rss(int64_t *maxrss) {
int r;
char statusname[100]; char statusname[100];
sprintf(statusname, "/proc/%d/status", getpid()); sprintf(statusname, "/proc/%d/status", getpid());
FILE *f = fopen(statusname, "r"); FILE *f = fopen(statusname, "r");
if (f == NULL) { if (f == NULL) {
#if defined(HAVE_SYS_RESOURCE_H)
// try getrusage instead
struct rusage rusage; struct rusage rusage;
getrusage(RUSAGE_SELF, &rusage); r = getrusage(RUSAGE_SELF, &rusage);
if (r != 0) {
return get_error_errno();
}
*maxrss = rusage.ru_maxrss * 1024; // ru_maxrss is in kB *maxrss = rusage.ru_maxrss * 1024; // ru_maxrss is in kB
return 0; return 0;
#else
return get_error_errno();
#endif
} }
int r = ENOENT; r = ENOENT;
char line[100]; char line[100];
while (fgets(line, sizeof line, f)) { while (fgets(line, sizeof line, f)) {
r = sscanf(line, "VmHWM:\t%lld kB\n", (long long *) maxrss); r = sscanf(line, "VmHWM:\t%lld kB\n", (long long *) maxrss);
...@@ -222,21 +221,20 @@ toku_os_get_max_rss(int64_t *maxrss) { ...@@ -222,21 +221,20 @@ toku_os_get_max_rss(int64_t *maxrss) {
int int
toku_os_get_rss(int64_t *rss) { toku_os_get_rss(int64_t *rss) {
int r;
char statusname[100]; char statusname[100];
sprintf(statusname, "/proc/%d/status", getpid()); sprintf(statusname, "/proc/%d/status", getpid());
FILE *f = fopen(statusname, "r"); FILE *f = fopen(statusname, "r");
if (f == NULL) { if (f == NULL) {
#if defined(HAVE_SYS_RESOURCE_H)
// try getrusage instead
struct rusage rusage; struct rusage rusage;
getrusage(RUSAGE_SELF, &rusage); r = getrusage(RUSAGE_SELF, &rusage);
if (r != 0) {
return get_error_errno();
}
*rss = (rusage.ru_idrss + rusage.ru_ixrss + rusage.ru_isrss) * 1024; *rss = (rusage.ru_idrss + rusage.ru_ixrss + rusage.ru_isrss) * 1024;
return 0; return 0;
#else
return get_error_errno();
#endif
} }
int r = ENOENT; r = ENOENT;
char line[100]; char line[100];
while (fgets(line, sizeof line, f)) { while (fgets(line, sizeof line, f)) {
r = sscanf(line, "VmRSS:\t%lld kB\n", (long long *) rss); r = sscanf(line, "VmRSS:\t%lld kB\n", (long long *) rss);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment