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

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

Powered by Google App Engine
This is Rietveld 408576698