Current RSS on linux and android too?
authormtklein <mtklein@chromium.org>
Tue, 17 Mar 2015 17:24:49 +0000 (10:24 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 17 Mar 2015 17:24:49 +0000 (10:24 -0700)
BUG=skia:

Review URL: https://codereview.chromium.org/1009313003

tools/ProcStats.cpp

index 1af7191..5c41213 100644 (file)
         }
         return info.resident_size / 1024 / 1024;  // Darwin reports bytes.
     }
+#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID)  // N.B. /proc is Linux-only.
+    #include <unistd.h>
+    #include <stdio.h>
+    int sk_tools::getCurrResidentSetSizeMB() {
+        const long pageSize = sysconf(_SC_PAGESIZE);
+        long rssPages = 0;
+        if (FILE* statm = fopen("/proc/self/statm", "r")) {
+            // statm contains: program-size rss shared text lib data dirty, all in page counts.
+            int rc = fscanf(statm, "%*d %ld", &rssPages);
+            fclose(statm);
+            if (rc != 1) {
+                return -1;
+            }
+        }
+        return rssPages * pageSize / 1024 / 1024;
+    }
+
 #elif defined(SK_BUILD_FOR_WIN32)
     int sk_tools::getCurrResidentSetSizeMB() {
         PROCESS_MEMORY_COUNTERS info;