add memory via to ok

Just like the time via, but instead of printing how long the thing took
to run it prints how much memory was used by the process at peak.

When ok runs in (default) process-per-task mode, this is quite handy.

Change-Id: I331d446e39363a44c545278d7153fa7548e2add0
Reviewed-on: https://skia-review.googlesource.com/20261
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
diff --git a/tools/ok_vias.cpp b/tools/ok_vias.cpp
index 50db49f..37d371f 100644
--- a/tools/ok_vias.cpp
+++ b/tools/ok_vias.cpp
@@ -9,6 +9,7 @@
 #include "SkOSFile.h"
 #include "SkPictureRecorder.h"
 #include "SkPngEncoder.h"
+#include "ProcStats.h"
 #include "Timer.h"
 #include "ok.h"
 #include <chrono>
@@ -156,6 +157,28 @@
         return target->image();
     }
 };
-static Register _time{"time",
-                      "print wall run time",
-                      Time::Create};
+static Register _time{"time", "print wall run time", Time::Create};
+
+struct Memory : Dst {
+    std::unique_ptr<Dst> target;
+
+    static std::unique_ptr<Dst> Create(Options options, std::unique_ptr<Dst> dst) {
+        Memory via;
+        via.target = std::move(dst);
+        return move_unique(via);
+    }
+
+    Status draw(Src* src) override {
+        Status status = target->draw(src);
+
+        auto msg = SkStringPrintf("%dMB", sk_tools::getMaxResidentSetSizeMB());
+        ok_log(msg.c_str());
+
+        return status;
+    }
+
+    sk_sp<SkImage> image() override {
+        return target->image();
+    }
+};
+static Register memory{"memory", "print process maximum memory usage", Memory::Create};