Update keeprule benchmarks to output DEX.

D8 is used after a PG run to obtain dex code. The D8 run is not counted
in the PG compilation time. For these tests the main purpose it to see
the effect of keep rules on time and size.

Change-Id: I4c4a0ca4cb5d4d785d7db820c1eec671685fd0d7
diff --git a/tools/keeprule_benchmark.py b/tools/keeprule_benchmark.py
index 6594688..7e7f47c 100755
--- a/tools/keeprule_benchmark.py
+++ b/tools/keeprule_benchmark.py
@@ -10,6 +10,7 @@
 import time
 
 import jdk
+import toolhelper
 import utils
 
 SHRINKERS = ['r8', 'pg']
@@ -161,7 +162,7 @@
       INPUT_PROGRAM,
       '--lib', utils.RT_JAR,
       '--output', output,
-      '--classfile',
+      '--min-api', '10000',
       '--pg-conf', keepfile,
       ]
   elif shrinker == 'pg':
@@ -178,6 +179,18 @@
   else:
     assert False, "Unexpected shrinker " + shrinker
 
+def dex(input, output):
+  toolhelper.run(
+      'd8',
+      [
+        input,
+        '--lib', utils.RT_JAR,
+        '--min-api', '10000',
+        '--output', output
+      ],
+      build=False,
+      debug=False)
+
 def run_shrinker(options, temp):
   benchmarks = BENCHMARKS
   if options.benchmark:
@@ -206,7 +219,12 @@
       subprocess.check_output(cmd)
       t1 = time.time()
       benchmark_runs.append(t1 - t0)
-      benchmark_size = utils.uncompressed_size(out)
+      if options.shrinker == 'pg':
+        dexout = os.path.join(temp, '%s-out%d-dex.jar' % (name, i))
+        dex(out, dexout)
+        benchmark_size = utils.uncompressed_size(dexout)
+      else:
+        benchmark_size = utils.uncompressed_size(out)
     benchmark_results.append(
         BenchmarkResult(name, benchmark_size, benchmark_runs))