OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "ProcStats.h" | 8 #include "ProcStats.h" |
9 | 9 |
10 #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_
FOR_ANDROID) | 10 #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_
FOR_ANDROID) |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include <mach/mach.h> | 34 #include <mach/mach.h> |
35 int sk_tools::getCurrResidentSetSizeMB() { | 35 int sk_tools::getCurrResidentSetSizeMB() { |
36 mach_task_basic_info info; | 36 mach_task_basic_info info; |
37 mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT; | 37 mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT; |
38 if (KERN_SUCCESS != | 38 if (KERN_SUCCESS != |
39 task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&
info, &count)) { | 39 task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&
info, &count)) { |
40 return -1; | 40 return -1; |
41 } | 41 } |
42 return info.resident_size / 1024 / 1024; // Darwin reports bytes. | 42 return info.resident_size / 1024 / 1024; // Darwin reports bytes. |
43 } | 43 } |
| 44 #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_ANDROID) // N.B. /proc
is Linux-only. |
| 45 #include <unistd.h> |
| 46 #include <stdio.h> |
| 47 int sk_tools::getCurrResidentSetSizeMB() { |
| 48 const long pageSize = sysconf(_SC_PAGESIZE); |
| 49 long rssPages = 0; |
| 50 if (FILE* statm = fopen("/proc/self/statm", "r")) { |
| 51 // statm contains: program-size rss shared text lib data dirty, all
in page counts. |
| 52 int rc = fscanf(statm, "%*d %ld", &rssPages); |
| 53 fclose(statm); |
| 54 if (rc != 1) { |
| 55 return -1; |
| 56 } |
| 57 } |
| 58 return rssPages * pageSize / 1024 / 1024; |
| 59 } |
| 60 |
44 #elif defined(SK_BUILD_FOR_WIN32) | 61 #elif defined(SK_BUILD_FOR_WIN32) |
45 int sk_tools::getCurrResidentSetSizeMB() { | 62 int sk_tools::getCurrResidentSetSizeMB() { |
46 PROCESS_MEMORY_COUNTERS info; | 63 PROCESS_MEMORY_COUNTERS info; |
47 GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info)); | 64 GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info)); |
48 return static_cast<int>(info.WorkingSetSize / 1024 / 1024); // Windows
reports bytes. | 65 return static_cast<int>(info.WorkingSetSize / 1024 / 1024); // Windows
reports bytes. |
49 } | 66 } |
50 #else | 67 #else |
51 int sk_tools::getCurrResidentSetSizeMB() { return -1; } | 68 int sk_tools::getCurrResidentSetSizeMB() { return -1; } |
52 #endif | 69 #endif |
OLD | NEW |