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

Unified Diff: runtime/bin/process_linux.cc

Issue 2822943002: [dart:io] Adds ProcessInfo.{max,current}Rss. Adds OS::MaxRSS on Fuchsia. (Closed)
Patch Set: Fix Fuchsia build 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_linux.cc
diff --git a/runtime/bin/process_linux.cc b/runtime/bin/process_linux.cc
index 29e6044db842f13718872b2873d214bbd15bd105..4e1ae8c73d749e5fdaff01fe7e2c35ce36dd7b6b 100644
--- a/runtime/bin/process_linux.cc
+++ b/runtime/bin/process_linux.cc
@@ -15,13 +15,16 @@
#include <stdio.h> // NOLINT
#include <stdlib.h> // NOLINT
#include <string.h> // NOLINT
+#include <sys/resource.h> // NOLINT
#include <sys/wait.h> // NOLINT
#include <unistd.h> // NOLINT
#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 +890,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 "",
+ &current_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;

Powered by Google App Engine
This is Rietveld 408576698