Index: runtime/bin/process_android.cc |
diff --git a/runtime/bin/process_android.cc b/runtime/bin/process_android.cc |
index 64ee4dc7497313f30de7c4e6b3a8551f2d162a8c..4da1a7aa455e4ddf61dece64aa1ae53feebf3021 100644 |
--- a/runtime/bin/process_android.cc |
+++ b/runtime/bin/process_android.cc |
@@ -887,6 +887,40 @@ intptr_t Process::CurrentProcessId() { |
} |
+intptr_t Process::CurrentRSS() { |
+ // The second value in /proc/self/statm is the current RSS in pages. |
+ File* statm = File::Open("/proc/self/statm", File::kRead); |
+ if (statm == NULL) { |
+ return -1; |
+ } |
+ RefCntReleaseScope<File> releaser(statm); |
+ const intptr_t statm_length = 1 * KB; |
+ void* buffer = reinterpret_cast<void*>(Dart_ScopeAllocate(statm_length)); |
+ const intptr_t statm_read = statm->Read(buffer, statm_length); |
+ if (statm_read <= 0) { |
+ return -1; |
+ } |
+ intptr_t current_rss_pages = 0; |
+ int matches = |
+ sscanf(reinterpret_cast<char*>(buffer), "%*s%" Pu "", ¤t_rss_pages); |
+ if (matches != 1) { |
+ return -1; |
+ } |
+ return current_rss_pages * getpagesize(); |
+} |
+ |
+ |
+intptr_t Process::MaxRSS() { |
+ struct rusage usage; |
+ usage.ru_maxrss = 0; |
+ int r = getrusage(RUSAGE_SELF, &usage); |
+ if (r < 0) { |
+ return -1; |
+ } |
+ return usage.ru_maxrss * KB; |
+} |
+ |
+ |
static Mutex* signal_mutex = new Mutex(); |
static SignalInfo* signal_handlers = NULL; |
static const int kSignalsCount = 7; |