aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/ProcStats.cpp
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-03-12 08:24:21 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-03-12 08:24:21 -0700
commit95553d917c73ef333ede967521560957a5b6a0ad (patch)
tree4eb0fb4979869525deb73a7fa37f79e54a661461 /tools/ProcStats.cpp
parent01cbf6c4673b805ab80e2b37e35eb4c89b135a1b (diff)
DM: display current memory usage (instead of peak) when available.
Seems strictly more useful. This implements Mac and Windows, which seemed easy. Don't know how to do this on Linux yet. BUG=skia: CQ_EXTRA_TRYBOTS=client.skia:Test-Mac10.9-MacMini6.2-HD4000-x86_64-Debug-Trybot NOTREECHECKS=true TBR=halcanary@google.com Review URL: https://codereview.chromium.org/990723002
Diffstat (limited to 'tools/ProcStats.cpp')
-rw-r--r--tools/ProcStats.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/tools/ProcStats.cpp b/tools/ProcStats.cpp
index c9f9f3f6c5..1af71917bd 100644
--- a/tools/ProcStats.cpp
+++ b/tools/ProcStats.cpp
@@ -7,10 +7,7 @@
#include "ProcStats.h"
-#if defined(SK_BUILD_FOR_UNIX) || \
- defined(SK_BUILD_FOR_MAC) || \
- defined(SK_BUILD_FOR_ANDROID)
-
+#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_ANDROID)
#include <sys/resource.h>
int sk_tools::getMaxResidentSetSizeMB() {
struct rusage ru;
@@ -21,7 +18,6 @@
return static_cast<int>(ru.ru_maxrss / 1024); // Linux reports kilobytes.
#endif
}
-
#elif defined(SK_BUILD_FOR_WIN32)
#include <windows.h>
#include <psapi.h>
@@ -30,10 +26,27 @@
GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
return static_cast<int>(info.PeakWorkingSetSize / 1024 / 1024); // Windows reports bytes.
}
-
#else
- int sk_tools::getMaxResidentSetSizeMB() {
- return -1;
- }
+ int sk_tools::getMaxResidentSetSizeMB() { return -1; }
+#endif
+#if defined(SK_BUILD_FOR_MAC)
+ #include <mach/mach.h>
+ int sk_tools::getCurrResidentSetSizeMB() {
+ mach_task_basic_info info;
+ mach_msg_type_number_t count = MACH_TASK_BASIC_INFO_COUNT;
+ if (KERN_SUCCESS !=
+ task_info(mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&info, &count)) {
+ return -1;
+ }
+ return info.resident_size / 1024 / 1024; // Darwin reports bytes.
+ }
+#elif defined(SK_BUILD_FOR_WIN32)
+ int sk_tools::getCurrResidentSetSizeMB() {
+ PROCESS_MEMORY_COUNTERS info;
+ GetProcessMemoryInfo(GetCurrentProcess(), &info, sizeof(info));
+ return static_cast<int>(info.WorkingSetSize / 1024 / 1024); // Windows reports bytes.
+ }
+#else
+ int sk_tools::getCurrResidentSetSizeMB() { return -1; }
#endif