Dump profile info after running test

Bug: 20824843

Not really a proper "benchmark mode" but it turns out
we already have reasonably good profile data, so tweak
the test app to spit it out after a run.

Change-Id: Iaee9c0d61b5508daf282fe5f95d0b37ee419a8f1
diff --git a/libs/hwui/tests/main.cpp b/libs/hwui/tests/main.cpp
index 62782af..aca7c52 100644
--- a/libs/hwui/tests/main.cpp
+++ b/libs/hwui/tests/main.cpp
@@ -14,8 +14,6 @@
  * limitations under the License.
  */
 
-#include <stdio.h>
-
 #include <cutils/log.h>
 #include <gui/Surface.h>
 #include <ui/PixelFormat.h>
@@ -28,6 +26,9 @@
 
 #include "TestContext.h"
 
+#include <stdio.h>
+#include <unistd.h>
+
 using namespace android;
 using namespace android::uirenderer;
 using namespace android::uirenderer::renderthread;
@@ -93,16 +94,27 @@
         animation.createContent(width, height, renderer);
         endRecording(renderer, rootNode);
 
-        for (int i = 0; i < animation.getFrameCount(); i++) {
-#if !HWUI_NULL_GPU
+        // Do a few cold runs then reset the stats so that the caches are all hot
+        for (int i = 0; i < 3; i++) {
             testContext.waitForVsync();
-#endif
+            proxy->syncAndDrawFrame();
+        }
+        proxy->resetProfileInfo();
 
+        for (int i = 0; i < animation.getFrameCount(); i++) {
+            testContext.waitForVsync();
+
+            // workaround b/20853441
+            proxy->fence();
             ATRACE_NAME("UI-Draw Frame");
+            nsecs_t vsync = systemTime(CLOCK_MONOTONIC);
+            UiFrameInfoBuilder(proxy->frameInfo())
+                    .setVsync(vsync, vsync);
             animation.doFrame(i);
             proxy->syncAndDrawFrame();
         }
 
+        proxy->dumpProfileInfo(STDOUT_FILENO, 0);
         rootNode->decStrong(nullptr);
     }
 };