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