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_LINUX) | 8 #if defined(HOST_OS_LINUX) |
| 9 | 9 |
| 10 #include "bin/process.h" | 10 #include "bin/process.h" |
| (...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 int64_t Process::CurrentRSS() { | 863 int64_t Process::CurrentRSS() { |
| 864 // 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. |
| 865 File* statm = File::Open("/proc/self/statm", File::kRead); | 865 // It is not possible to use getrusage() because the interested fields are not |
| 866 // implemented by the linux kernel. | |
| 867 FILE* statm = fopen("/proc/self/statm", "r"); | |
| 866 if (statm == NULL) { | 868 if (statm == NULL) { |
| 867 return -1; | 869 return -1; |
| 868 } | 870 } |
| 869 RefCntReleaseScope<File> releaser(statm); | |
| 870 const intptr_t statm_length = 1 * KB; | |
| 871 void* buffer = reinterpret_cast<void*>(Dart_ScopeAllocate(statm_length)); | |
| 872 const intptr_t statm_read = statm->Read(buffer, statm_length); | |
| 873 if (statm_read <= 0) { | |
| 874 return -1; | |
| 875 } | |
| 876 int64_t current_rss_pages = 0; | 871 int64_t current_rss_pages = 0; |
| 877 int matches = sscanf(reinterpret_cast<char*>(buffer), "%*s%" Pd64 "", | 872 int matches = fscanf(statm, "%*s%" Pd64 "", |
| 878 ¤t_rss_pages); | 873 ¤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.
| |
| 874 fclose(statm); | |
|
zra
2017/08/10 22:19:50
ditto
cbernaschina
2017/08/12 00:29:42
Done.
| |
| 879 if (matches != 1) { | 875 if (matches != 1) { |
| 880 return -1; | 876 return -1; |
| 881 } | 877 } |
| 882 return current_rss_pages * getpagesize(); | 878 return current_rss_pages * getpagesize(); |
| 883 } | 879 } |
| 884 | 880 |
| 885 int64_t Process::MaxRSS() { | 881 int64_t Process::MaxRSS() { |
| 886 struct rusage usage; | 882 struct rusage usage; |
| 887 usage.ru_maxrss = 0; | 883 usage.ru_maxrss = 0; |
| 888 int r = getrusage(RUSAGE_SELF, &usage); | 884 int r = getrusage(RUSAGE_SELF, &usage); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 997 sigaction(signal, &act, NULL); | 993 sigaction(signal, &act, NULL); |
| 998 } | 994 } |
| 999 } | 995 } |
| 1000 | 996 |
| 1001 } // namespace bin | 997 } // namespace bin |
| 1002 } // namespace dart | 998 } // namespace dart |
| 1003 | 999 |
| 1004 #endif // defined(HOST_OS_LINUX) | 1000 #endif // defined(HOST_OS_LINUX) |
| 1005 | 1001 |
| 1006 #endif // !defined(DART_IO_DISABLED) | 1002 #endif // !defined(DART_IO_DISABLED) |
| OLD | NEW |