Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Unified Diff: runtime/bin/process_android.cc

Issue 2822943002: [dart:io] Adds ProcessInfo.{max,current}Rss. Adds OS::MaxRSS on Fuchsia. (Closed)
Patch Set: Cleanup Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 "", &current_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;

Powered by Google App Engine
This is Rietveld 408576698