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
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index d66b308..920979c 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -476,7 +476,7 @@
if (FLAGS_mpd) {
fUseMPDs.push_back() = true;
}
-
+
// Prepare the images for decoding
for (int i = 0; i < FLAGS_images.count(); i++) {
const char* flag = FLAGS_images[i];
@@ -492,7 +492,7 @@
fImages.push_back() = flag;
}
}
-
+
// Choose the candidate color types for image decoding
const SkColorType colorTypes[] =
{ kN32_SkColorType, kRGB_565_SkColorType, kAlpha_8_SkColorType };
@@ -842,7 +842,7 @@
config = ""; // Only print the config if we run the same bench on more than one.
}
SkDebugf("%4dM\t%s\t%s\n"
- , sk_tools::getMaxResidentSetSizeMB()
+ , sk_tools::getBestResidentSetSizeMB()
, bench->getUniqueName()
, config);
} else if (FLAGS_verbose) {
@@ -858,7 +858,7 @@
} else {
const double stddev_percent = 100 * sqrt(stats.var) / stats.mean;
SkDebugf("%4dM\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n"
- , sk_tools::getMaxResidentSetSizeMB()
+ , sk_tools::getBestResidentSetSizeMB()
, loops
, HUMANIZE(stats.min)
, HUMANIZE(stats.median)
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 2734b75..2e41413 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -59,7 +59,7 @@
}
auto pending = sk_atomic_dec(&gPending)-1;
SkDebugf("%s(%4dMB %5d) %s\t%s %s %s%s", FLAGS_verbose ? "\n" : kSkOverwriteLine
- , sk_tools::getMaxResidentSetSizeMB()
+ , sk_tools::getBestResidentSetSizeMB()
, pending
, HumanizeMs(ms).c_str()
, config.c_str()
diff --git a/tools/ProcStats.cpp b/tools/ProcStats.cpp
index c9f9f3f..1af7191 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
diff --git a/tools/ProcStats.h b/tools/ProcStats.h
index 14b98b7..f085fe3 100644
--- a/tools/ProcStats.h
+++ b/tools/ProcStats.h
@@ -15,11 +15,27 @@
namespace sk_tools {
/**
- * If not implemented for this OS, returns -1. Otherwise, return
- * the maximum resident set size, as reported by getrusage().
+ * If implemented, returns the maximum resident set size in MB.
+ * If not, returns -1.
*/
int getMaxResidentSetSizeMB();
+/**
+ * If implemented, returns the current resident set size in MB.
+ * If not, returns -1.
+ */
+int getCurrResidentSetSizeMB();
+
+/**
+ * If implemented, returns getCurrResidentSetSizeMB().
+ * If not, if implemented, returns getMaxResidentSetSizeMB().
+ * If not, returns -1.
+ */
+inline int getBestResidentSetSizeMB() {
+ int mb = getCurrResidentSetSizeMB();
+ return mb >= 0 ? mb : getMaxResidentSetSizeMB();
+}
+
} // namespace sk_tools
#endif // ProcStats_DEFINED