| Index: runtime/bin/process_android.cc
|
| diff --git a/runtime/bin/process_android.cc b/runtime/bin/process_android.cc
|
| index 9b307f3ed6fa57367db774cc5be6bb100de90a8d..66fc280523091c99fa593a120e872a8b9738e42e 100644
|
| --- a/runtime/bin/process_android.cc
|
| +++ b/runtime/bin/process_android.cc
|
| @@ -859,27 +859,25 @@ intptr_t Process::CurrentProcessId() {
|
| return static_cast<intptr_t>(getpid());
|
| }
|
|
|
| -static void SaveErrorAndClose(FILE* file) {
|
| - int actual_errno = errno;
|
| - fclose(file);
|
| - errno = actual_errno;
|
| -}
|
| -
|
| int64_t Process::CurrentRSS() {
|
| // The second value in /proc/self/statm is the current RSS in pages.
|
| - // It is not possible to use getrusage() because the interested fields are not
|
| - // implemented by the linux kernel.
|
| - FILE* statm = fopen("/proc/self/statm", "r");
|
| + File* statm = File::Open("/proc/self/statm", File::kRead);
|
| if (statm == NULL) {
|
| return -1;
|
| }
|
| + RefCntReleaseScope<File> releaser(statm);
|
| + const intptr_t statm_length = 1 * KB;
|
| + void* buffer = reinterpret_cast<void*>(Dart_ScopeAllocate(statm_length));
|
| + const intptr_t statm_read = statm->Read(buffer, statm_length);
|
| + if (statm_read <= 0) {
|
| + return -1;
|
| + }
|
| int64_t current_rss_pages = 0;
|
| - int matches = fscanf(statm, "%*s%" Pd64 "", ¤t_rss_pages);
|
| + int matches = sscanf(reinterpret_cast<char*>(buffer), "%*s%" Pd64 "",
|
| + ¤t_rss_pages);
|
| if (matches != 1) {
|
| - SaveErrorAndClose(statm);
|
| return -1;
|
| }
|
| - fclose(statm);
|
| return current_rss_pages * getpagesize();
|
| }
|
|
|
|
|