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

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: 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 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"
11 11
12 #include <errno.h> // NOLINT 12 #include <errno.h> // NOLINT
13 #include <fcntl.h> // NOLINT 13 #include <fcntl.h> // NOLINT
14 #include <poll.h> // NOLINT 14 #include <poll.h> // NOLINT
15 #include <stdio.h> // NOLINT 15 #include <stdio.h> // NOLINT
16 #include <stdlib.h> // NOLINT 16 #include <stdlib.h> // NOLINT
17 #include <string.h> // NOLINT 17 #include <string.h> // NOLINT
18 #include <sys/wait.h> // NOLINT 18 #include <sys/wait.h> // NOLINT
19 #include <unistd.h> // NOLINT 19 #include <unistd.h> // NOLINT
20 20
21 #include "bin/dartutils.h" 21 #include "bin/dartutils.h"
22 #include "bin/fdutils.h" 22 #include "bin/fdutils.h"
23 #include "bin/file.h"
23 #include "bin/lockers.h" 24 #include "bin/lockers.h"
24 #include "bin/log.h" 25 #include "bin/log.h"
26 #include "bin/reference_counting.h"
25 #include "bin/thread.h" 27 #include "bin/thread.h"
26 28
27 #include "platform/signal_blocker.h" 29 #include "platform/signal_blocker.h"
28 #include "platform/utils.h" 30 #include "platform/utils.h"
29 31
30 extern char** environ; 32 extern char** environ;
31 33
32 namespace dart { 34 namespace dart {
33 namespace bin { 35 namespace bin {
34 36
(...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 void Process::TerminateExitCodeHandler() { 882 void Process::TerminateExitCodeHandler() {
881 ExitCodeHandler::TerminateExitCodeThread(); 883 ExitCodeHandler::TerminateExitCodeThread();
882 } 884 }
883 885
884 886
885 intptr_t Process::CurrentProcessId() { 887 intptr_t Process::CurrentProcessId() {
886 return static_cast<intptr_t>(getpid()); 888 return static_cast<intptr_t>(getpid());
887 } 889 }
888 890
889 891
892 int64_t Process::CurrentRSS() {
893 // The second value in /proc/self/statm is the current RSS in pages.
894 File* statm = File::Open("/proc/self/statm", File::kRead);
895 if (statm == NULL) {
896 return -1;
897 }
898 RefCntReleaseScope<File> releaser(statm);
899 const intptr_t statm_length = 1 * KB;
900 void* buffer = reinterpret_cast<void*>(Dart_ScopeAllocate(statm_length));
901 const intptr_t statm_read = statm->Read(buffer, statm_length);
902 if (statm_read <= 0) {
903 return -1;
904 }
905 int64_t current_rss_pages = 0;
906 int matches = sscanf(reinterpret_cast<char*>(buffer), "%*s%" Pd64 "",
907 &current_rss_pages);
908 if (matches != 1) {
909 return -1;
910 }
911 return current_rss_pages * getpagesize();
912 }
913
914
915 int64_t Process::MaxRSS() {
916 struct rusage usage;
917 usage.ru_maxrss = 0;
918 int r = getrusage(RUSAGE_SELF, &usage);
919 if (r < 0) {
920 return -1;
921 }
922 return usage.ru_maxrss * KB;
923 }
924
925
890 static Mutex* signal_mutex = new Mutex(); 926 static Mutex* signal_mutex = new Mutex();
891 static SignalInfo* signal_handlers = NULL; 927 static SignalInfo* signal_handlers = NULL;
892 static const int kSignalsCount = 7; 928 static const int kSignalsCount = 7;
893 static const int kSignals[kSignalsCount] = { 929 static const int kSignals[kSignalsCount] = {
894 SIGHUP, SIGINT, SIGTERM, SIGUSR1, SIGUSR2, SIGWINCH, 930 SIGHUP, SIGINT, SIGTERM, SIGUSR1, SIGUSR2, SIGWINCH,
895 SIGQUIT // Allow VMService to listen on SIGQUIT. 931 SIGQUIT // Allow VMService to listen on SIGQUIT.
896 }; 932 };
897 933
898 934
899 SignalInfo::~SignalInfo() { 935 SignalInfo::~SignalInfo() {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); 1032 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL));
997 } 1033 }
998 } 1034 }
999 1035
1000 } // namespace bin 1036 } // namespace bin
1001 } // namespace dart 1037 } // namespace dart
1002 1038
1003 #endif // defined(HOST_OS_ANDROID) 1039 #endif // defined(HOST_OS_ANDROID)
1004 1040
1005 #endif // !defined(DART_IO_DISABLED) 1041 #endif // !defined(DART_IO_DISABLED)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698