aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/ProcStats.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-03-17 10:24:49 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-03-17 10:24:49 -0700
commiteec84e324ee47f19b7e9c22d3454622d7a21da2e (patch)
tree313859b7cf059de32b6aa0a0c63dbde501294e77 /tools/ProcStats.cpp
parent5721c9b4a705839003ff6671aec0a0a88500a808 (diff)
Current RSS on linux and android too?
Diffstat (limited to 'tools/ProcStats.cpp')
-rw-r--r--tools/ProcStats.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/tools/ProcStats.cpp b/tools/ProcStats.cpp
index 1af71917bd..5c41213d4d 100644
--- a/tools/ProcStats.cpp
+++ b/tools/ProcStats.cpp
@@ -41,6 +41,23 @@
}
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;