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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #if !defined(DART_IO_DISABLED) 5 #if !defined(DART_IO_DISABLED)
6 6
7 #include "platform/globals.h" 7 #include "platform/globals.h"
8 #if defined(HOST_OS_ANDROID) 8 #if defined(HOST_OS_ANDROID)
9 9
10 #include "bin/process.h" 10 #include "bin/process.h"
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 void Process::TerminateExitCodeHandler() { 880 void Process::TerminateExitCodeHandler() {
881 ExitCodeHandler::TerminateExitCodeThread(); 881 ExitCodeHandler::TerminateExitCodeThread();
882 } 882 }
883 883
884 884
885 intptr_t Process::CurrentProcessId() { 885 intptr_t Process::CurrentProcessId() {
886 return static_cast<intptr_t>(getpid()); 886 return static_cast<intptr_t>(getpid());
887 } 887 }
888 888
889 889
890 intptr_t Process::CurrentRSS() {
891 // The second value in /proc/self/statm is the current RSS in pages.
892 File* statm = File::Open("/proc/self/statm", File::kRead);
893 if (statm == NULL) {
894 return -1;
895 }
896 RefCntReleaseScope<File> releaser(statm);
897 const intptr_t statm_length = 1 * KB;
898 void* buffer = reinterpret_cast<void*>(Dart_ScopeAllocate(statm_length));
899 const intptr_t statm_read = statm->Read(buffer, statm_length);
900 if (statm_read <= 0) {
901 return -1;
902 }
903 intptr_t current_rss_pages = 0;
904 int matches =
905 sscanf(reinterpret_cast<char*>(buffer), "%*s%" Pu "", &current_rss_pages);
906 if (matches != 1) {
907 return -1;
908 }
909 return current_rss_pages * getpagesize();
910 }
911
912
913 intptr_t Process::MaxRSS() {
914 struct rusage usage;
915 usage.ru_maxrss = 0;
916 int r = getrusage(RUSAGE_SELF, &usage);
917 if (r < 0) {
918 return -1;
919 }
920 return usage.ru_maxrss * KB;
921 }
922
923
890 static Mutex* signal_mutex = new Mutex(); 924 static Mutex* signal_mutex = new Mutex();
891 static SignalInfo* signal_handlers = NULL; 925 static SignalInfo* signal_handlers = NULL;
892 static const int kSignalsCount = 7; 926 static const int kSignalsCount = 7;
893 static const int kSignals[kSignalsCount] = { 927 static const int kSignals[kSignalsCount] = {
894 SIGHUP, SIGINT, SIGTERM, SIGUSR1, SIGUSR2, SIGWINCH, 928 SIGHUP, SIGINT, SIGTERM, SIGUSR1, SIGUSR2, SIGWINCH,
895 SIGQUIT // Allow VMService to listen on SIGQUIT. 929 SIGQUIT // Allow VMService to listen on SIGQUIT.
896 }; 930 };
897 931
898 932
899 SignalInfo::~SignalInfo() { 933 SignalInfo::~SignalInfo() {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); 1030 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL));
997 } 1031 }
998 } 1032 }
999 1033
1000 } // namespace bin 1034 } // namespace bin
1001 } // namespace dart 1035 } // namespace dart
1002 1036
1003 #endif // defined(HOST_OS_ANDROID) 1037 #endif // defined(HOST_OS_ANDROID)
1004 1038
1005 #endif // !defined(DART_IO_DISABLED) 1039 #endif // !defined(DART_IO_DISABLED)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698