Index: runtime/bin/process_android.cc |
diff --git a/runtime/bin/process_android.cc b/runtime/bin/process_android.cc |
index 64ee4dc7497313f30de7c4e6b3a8551f2d162a8c..8107ee3dda951ac094940ce5016ac2da897ad7c3 100644 |
--- a/runtime/bin/process_android.cc |
+++ b/runtime/bin/process_android.cc |
@@ -20,8 +20,10 @@ |
#include "bin/dartutils.h" |
#include "bin/fdutils.h" |
+#include "bin/file.h" |
#include "bin/lockers.h" |
#include "bin/log.h" |
+#include "bin/reference_counting.h" |
#include "bin/thread.h" |
#include "platform/signal_blocker.h" |
@@ -887,6 +889,40 @@ intptr_t Process::CurrentProcessId() { |
} |
+int64_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; |
+ } |
+ int64_t current_rss_pages = 0; |
+ int matches = sscanf(reinterpret_cast<char*>(buffer), "%*s%" Pd64 "", |
+ ¤t_rss_pages); |
+ if (matches != 1) { |
+ return -1; |
+ } |
+ return current_rss_pages * getpagesize(); |
+} |
+ |
+ |
+int64_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; |