| OLD | NEW |
| 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 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 } | 852 } |
| 853 | 853 |
| 854 void Process::TerminateExitCodeHandler() { | 854 void Process::TerminateExitCodeHandler() { |
| 855 ExitCodeHandler::TerminateExitCodeThread(); | 855 ExitCodeHandler::TerminateExitCodeThread(); |
| 856 } | 856 } |
| 857 | 857 |
| 858 intptr_t Process::CurrentProcessId() { | 858 intptr_t Process::CurrentProcessId() { |
| 859 return static_cast<intptr_t>(getpid()); | 859 return static_cast<intptr_t>(getpid()); |
| 860 } | 860 } |
| 861 | 861 |
| 862 static void SaveErrorAndClose(FILE* file) { | |
| 863 int actual_errno = errno; | |
| 864 fclose(file); | |
| 865 errno = actual_errno; | |
| 866 } | |
| 867 | |
| 868 int64_t Process::CurrentRSS() { | 862 int64_t Process::CurrentRSS() { |
| 869 // The second value in /proc/self/statm is the current RSS in pages. | 863 // The second value in /proc/self/statm is the current RSS in pages. |
| 870 // It is not possible to use getrusage() because the interested fields are not | 864 File* statm = File::Open("/proc/self/statm", File::kRead); |
| 871 // implemented by the linux kernel. | |
| 872 FILE* statm = fopen("/proc/self/statm", "r"); | |
| 873 if (statm == NULL) { | 865 if (statm == NULL) { |
| 874 return -1; | 866 return -1; |
| 875 } | 867 } |
| 876 int64_t current_rss_pages = 0; | 868 RefCntReleaseScope<File> releaser(statm); |
| 877 int matches = fscanf(statm, "%*s%" Pd64 "", ¤t_rss_pages); | 869 const intptr_t statm_length = 1 * KB; |
| 878 if (matches != 1) { | 870 void* buffer = reinterpret_cast<void*>(Dart_ScopeAllocate(statm_length)); |
| 879 SaveErrorAndClose(statm); | 871 const intptr_t statm_read = statm->Read(buffer, statm_length); |
| 872 if (statm_read <= 0) { |
| 880 return -1; | 873 return -1; |
| 881 } | 874 } |
| 882 fclose(statm); | 875 int64_t current_rss_pages = 0; |
| 876 int matches = sscanf(reinterpret_cast<char*>(buffer), "%*s%" Pd64 "", |
| 877 ¤t_rss_pages); |
| 878 if (matches != 1) { |
| 879 return -1; |
| 880 } |
| 883 return current_rss_pages * getpagesize(); | 881 return current_rss_pages * getpagesize(); |
| 884 } | 882 } |
| 885 | 883 |
| 886 int64_t Process::MaxRSS() { | 884 int64_t Process::MaxRSS() { |
| 887 struct rusage usage; | 885 struct rusage usage; |
| 888 usage.ru_maxrss = 0; | 886 usage.ru_maxrss = 0; |
| 889 int r = getrusage(RUSAGE_SELF, &usage); | 887 int r = getrusage(RUSAGE_SELF, &usage); |
| 890 if (r < 0) { | 888 if (r < 0) { |
| 891 return -1; | 889 return -1; |
| 892 } | 890 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); | 999 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); |
| 1002 } | 1000 } |
| 1003 } | 1001 } |
| 1004 | 1002 |
| 1005 } // namespace bin | 1003 } // namespace bin |
| 1006 } // namespace dart | 1004 } // namespace dart |
| 1007 | 1005 |
| 1008 #endif // defined(HOST_OS_ANDROID) | 1006 #endif // defined(HOST_OS_ANDROID) |
| 1009 | 1007 |
| 1010 #endif // !defined(DART_IO_DISABLED) | 1008 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |