halcanary | 0d154ee | 2014-08-11 11:33:51 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "ProcStats.h" |
| 9 | |
| 10 | #if defined(SK_BUILD_FOR_UNIX) || \ |
| 11 | defined(SK_BUILD_FOR_MAC) || \ |
| 12 | defined(SK_BUILD_FOR_ANDROID) |
| 13 | |
| 14 | #include <sys/resource.h> |
mtklein | afb4379 | 2014-08-19 15:55:55 -0700 | [diff] [blame] | 15 | int sk_tools::getMaxResidentSetSizeMB() { |
halcanary | 0d154ee | 2014-08-11 11:33:51 -0700 | [diff] [blame] | 16 | struct rusage ru; |
| 17 | getrusage(RUSAGE_SELF, &ru); |
| 18 | #if defined(SK_BUILD_FOR_MAC) |
mtklein | afb4379 | 2014-08-19 15:55:55 -0700 | [diff] [blame] | 19 | return static_cast<int>(ru.ru_maxrss / 1024 / 1024); // Darwin reports bytes. |
halcanary | 0d154ee | 2014-08-11 11:33:51 -0700 | [diff] [blame] | 20 | #else |
mtklein | afb4379 | 2014-08-19 15:55:55 -0700 | [diff] [blame] | 21 | return static_cast<int>(ru.ru_maxrss / 1024); // Linux reports kilobytes. |
halcanary | 0d154ee | 2014-08-11 11:33:51 -0700 | [diff] [blame] | 22 | #endif |
| 23 | } |
| 24 | |
mtklein | 9abf4f8 | 2014-10-21 12:23:12 -0700 | [diff] [blame] | 25 | #elif defined(SK_BUILD_FOR_WIN32) |
| 26 | #include <windows.h> |
| 27 | #include <psapi.h> |
| 28 | int sk_tools::getMaxResidentSetSizeMB() { |
| 29 | PROCESS_MEMORY_COUNTERS info; |
| 30 | GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info)); |
| 31 | return static_cast<int>(info.PeakWorkingSetSize / 1024 / 1024); // Windows reports bytes. |
| 32 | } |
halcanary | 0d154ee | 2014-08-11 11:33:51 -0700 | [diff] [blame] | 33 | |
mtklein | 9abf4f8 | 2014-10-21 12:23:12 -0700 | [diff] [blame] | 34 | #else |
mtklein | afb4379 | 2014-08-19 15:55:55 -0700 | [diff] [blame] | 35 | int sk_tools::getMaxResidentSetSizeMB() { |
halcanary | 0d154ee | 2014-08-11 11:33:51 -0700 | [diff] [blame] | 36 | return -1; |
| 37 | } |
| 38 | |
| 39 | #endif |