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) || \ | 10 #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_ FOR_ANDROID) |
11 defined(SK_BUILD_FOR_MAC) || \ | |
12 defined(SK_BUILD_FOR_ANDROID) | |
13 | |
14 #include <sys/resource.h> | 11 #include <sys/resource.h> |
15 int sk_tools::getMaxResidentSetSizeMB() { | 12 int sk_tools::getMaxResidentSetSizeMB() { |
16 struct rusage ru; | 13 struct rusage ru; |
17 getrusage(RUSAGE_SELF, &ru); | 14 getrusage(RUSAGE_SELF, &ru); |
18 #if defined(SK_BUILD_FOR_MAC) | 15 #if defined(SK_BUILD_FOR_MAC) |
19 return static_cast<int>(ru.ru_maxrss / 1024 / 1024); // Darwin reports bytes. | 16 return static_cast<int>(ru.ru_maxrss / 1024 / 1024); // Darwin reports bytes. |
20 #else | 17 #else |
21 return static_cast<int>(ru.ru_maxrss / 1024); // Linux reports kilobyte s. | 18 return static_cast<int>(ru.ru_maxrss / 1024); // Linux reports kilobyte s. |
22 #endif | 19 #endif |
23 } | 20 } |
24 | |
25 #elif defined(SK_BUILD_FOR_WIN32) | 21 #elif defined(SK_BUILD_FOR_WIN32) |
26 #include <windows.h> | 22 #include <windows.h> |
27 #include <psapi.h> | 23 #include <psapi.h> |
28 int sk_tools::getMaxResidentSetSizeMB() { | 24 int sk_tools::getMaxResidentSetSizeMB() { |
29 PROCESS_MEMORY_COUNTERS info; | 25 PROCESS_MEMORY_COUNTERS info; |
30 GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info)); | 26 GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info)); |
31 return static_cast<int>(info.PeakWorkingSetSize / 1024 / 1024); // Wind ows reports bytes. | 27 return static_cast<int>(info.PeakWorkingSetSize / 1024 / 1024); // Wind ows reports bytes. |
32 } | 28 } |
29 #else | |
30 int sk_tools::getMaxResidentSetSizeMB() { return -1; } | |
31 #endif | |
33 | 32 |
33 #if defined(SK_BUILD_FOR_MAC) | |
34 #include <mach/mach.h> | |
35 int sk_tools::getCurrResidentSetSizeMB() { | |
36 mach_task_basic_info info; | |
37 mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT; | |
38 if (KERN_SUCCESS != | |
39 task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)& info, &count)) { | |
40 return -1; | |
41 } | |
42 return info.resident_size / 1024 / 1024; // Darwin reports bytes. | |
43 } | |
44 #elif defined(SK_BUILD_FOR_WIN32) | |
45 int sk_tools::getCurrResidentSetSizeMB() { | |
46 PROCESS_MEMORY_COUNTERS info; | |
47 GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info)); | |
48 return static_cast<int>(info.WorkingSetSize / 1024 / 1024); // Windows reports bytes. | |
49 } | |
34 #else | 50 #else |
hal.canary
2015/03/16 17:22:34
#ifdef __linux
#include <unistd.h>
#includ
| |
35 int sk_tools::getMaxResidentSetSizeMB() { | 51 int sk_tools::getCurrResidentSetSizeMB() { return -1; } |
36 return -1; | |
37 } | |
38 | |
39 #endif | 52 #endif |
OLD | NEW |