Chromium Code Reviews| 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 843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 int64_t Process::CurrentRSS() { | 862 int64_t Process::CurrentRSS() { |
| 863 // 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. |
| 864 File* statm = File::Open("/proc/self/statm", File::kRead); | 864 // It is not possible to use getrusage() because the interested fields are not |
| 865 // implemented by the linux kernel. | |
| 866 FILE* statm = fopen("/proc/self/statm", "r"); | |
| 865 if (statm == NULL) { | 867 if (statm == NULL) { |
| 866 return -1; | 868 return -1; |
| 867 } | 869 } |
| 868 RefCntReleaseScope<File> releaser(statm); | |
| 869 const intptr_t statm_length = 1 * KB; | |
| 870 void* buffer = reinterpret_cast<void*>(Dart_ScopeAllocate(statm_length)); | |
| 871 const intptr_t statm_read = statm->Read(buffer, statm_length); | |
| 872 if (statm_read <= 0) { | |
| 873 return -1; | |
| 874 } | |
| 875 int64_t current_rss_pages = 0; | 870 int64_t current_rss_pages = 0; |
| 876 int matches = sscanf(reinterpret_cast<char*>(buffer), "%*s%" Pd64 "", | 871 int matches = fscanf(statm, "%*s%" Pd64 "", |
| 877 ¤t_rss_pages); | 872 ¤t_rss_pages); |
|
zra
2017/08/10 22:19:50
It looks like this will fit on the line above.
cbernaschina
2017/08/12 00:29:42
Done.
| |
| 873 fclose(statm); | |
|
zra
2017/08/10 22:19:50
This will blow away errno from fscanf when there i
cbernaschina
2017/08/10 22:40:28
If matches is 1 it means that the value was succes
zra
2017/08/10 22:49:47
If this function returns -1, the caller will make
cbernaschina
2017/08/12 00:29:42
Done.
| |
| 878 if (matches != 1) { | 874 if (matches != 1) { |
| 879 return -1; | 875 return -1; |
| 880 } | 876 } |
| 881 return current_rss_pages * getpagesize(); | 877 return current_rss_pages * getpagesize(); |
| 882 } | 878 } |
| 883 | 879 |
| 884 int64_t Process::MaxRSS() { | 880 int64_t Process::MaxRSS() { |
| 885 struct rusage usage; | 881 struct rusage usage; |
| 886 usage.ru_maxrss = 0; | 882 usage.ru_maxrss = 0; |
| 887 int r = getrusage(RUSAGE_SELF, &usage); | 883 int r = getrusage(RUSAGE_SELF, &usage); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 999 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); | 995 VOID_NO_RETRY_EXPECTED(sigaction(signal, &act, NULL)); |
| 1000 } | 996 } |
| 1001 } | 997 } |
| 1002 | 998 |
| 1003 } // namespace bin | 999 } // namespace bin |
| 1004 } // namespace dart | 1000 } // namespace dart |
| 1005 | 1001 |
| 1006 #endif // defined(HOST_OS_ANDROID) | 1002 #endif // defined(HOST_OS_ANDROID) |
| 1007 | 1003 |
| 1008 #endif // !defined(DART_IO_DISABLED) | 1004 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |