On Valgrind bots, print a message every 20 minutes

I believe that the timeout failure on the Valgrind bot occurs
because we skip many tests consecutively without printing any
output.  Skipping these tests requires non-trivial work.

Printing a message every 20 minutes will avoid timeouts.

BUG=skia:4740
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1554193002

Review URL: https://codereview.chromium.org/1554193002
diff --git a/bench/nanobench.cpp b/bench/nanobench.cpp
index 638477e..b785898 100644
--- a/bench/nanobench.cpp
+++ b/bench/nanobench.cpp
@@ -38,6 +38,7 @@
 #include "SkString.h"
 #include "SkSurface.h"
 #include "SkTaskGroup.h"
+#include "SkThreadUtils.h"
 
 #include <stdlib.h>
 
@@ -106,6 +107,7 @@
 DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each test.");
 DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?");
 DEFINE_bool(gpuStatsDump, false, "Dump GPU states after each benchmark to json");
+DEFINE_bool(keepAlive, false, "Print a message every so often so that we don't time out");
 
 static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
 
@@ -972,6 +974,26 @@
     int fCurrentAnimSKP;
 };
 
+// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
+// This prints something every once in a while so that it knows we're still working.
+static void start_keepalive() {
+    struct Loop {
+        static void forever(void*) {
+            for (;;) {
+                static const int kSec = 1200;
+            #if defined(SK_BUILD_FOR_WIN)
+                Sleep(kSec * 1000);
+            #else
+                sleep(kSec);
+            #endif
+                SkDebugf("\nBenchmarks still running...\n");
+            }
+        }
+    };
+    static SkThread* intentionallyLeaked = new SkThread(Loop::forever);
+    intentionallyLeaked->start();
+}
+
 int nanobench_main();
 int nanobench_main() {
     SetupCrashHandler();
@@ -1042,6 +1064,10 @@
     SkTDArray<Config> configs;
     create_configs(&configs);
 
+    if (FLAGS_keepAlive) {
+        start_keepalive();
+    }
+
     int runs = 0;
     BenchmarkStream benchStream;
     while (Benchmark* b = benchStream.next()) {