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