Support for writing benchmark result to json and overriding iterations

Change-Id: I2dc1482a36d3479f0fba7ee65ef850a93e1b9b83
diff --git a/tools/run_benchmark.py b/tools/run_benchmark.py
index 3962d59..8948df7 100755
--- a/tools/run_benchmark.py
+++ b/tools/run_benchmark.py
@@ -63,6 +63,12 @@
                         help='Enable assertions when running',
                         default=False,
                         action='store_true')
+    result.add_argument('--iterations',
+                        '-i',
+                        help='Number of iterations to run',
+                        type=int)
+    result.add_argument('--output',
+                        help='Output path where to write the result')
     result.add_argument('--print-times',
                         help='Print timing information from r8',
                         default=False,
@@ -81,8 +87,12 @@
 def main(argv, temp):
     (options, args) = parse_options(argv)
 
+    if options.output:
+        options.output = os.path.abspath(options.output)
+
     if options.temp:
         temp = options.temp
+        os.makedirs(temp, exist_ok=True)
 
     if options.golem:
         options.no_build = True
@@ -139,6 +149,10 @@
             f'-DTEST_DATA_LOCATION={utils.REPO_ROOT}/d8_r8/test_modules/tests_java_8/build/classes/java/test',
             f'-DTESTBASE_DATA_LOCATION={utils.REPO_ROOT}/d8_r8/test_modules/testbase/build/classes/java/main',
         ])
+    if options.iterations:
+        cmd.append(f'-DBENCHMARK_ITERATIONS={options.iterations}')
+    if options.output:
+        cmd.append(f'-DBENCHMARK_OUTPUT={options.output}')
     cmd.extend(['-cp', ':'.join([r8jar] + testjars)])
     cmd.extend([
         'com.android.tools.r8.benchmarks.BenchmarkMainEntryRunner',