# Path: compiler_opt/tools/benchmark_report.py
# def _geomean(data: List[float]):
# def _stdev(data: List[float]):
#   def __init__(self, suite_name: str, json_data: BenchmarkRunResults,
#                counter_names: Iterable[str]):
#   def suite_name(self):
#   def values(self):
#   def names(self):
#   def counters(self):
#   def raw_measurements(self):
#   def counter_means(self, benchmark: str, counter: str) -> Tuple[float, float]:
#   def zero_counters(self):
#   def large_variation_counters(self, variation: float):
#   def _load_values(self, data: BenchmarkRunResults,
#                    names: Iterable[str]) -> PerBenchmarkResults:
#   def __init__(self, base_report: BenchmarkReport, exp_report: BenchmarkReport):
#   def suite_name(self):
#   def summarize(self) -> ABComparison:
#   def names(self):
#   def counters(self):
#   def total_improvement(self, counter: str):
# class BenchmarkReport:
# class BenchmarkComparison:


import csv
import json
import tensorflow.compat.v2 as tf
from typing import Sequence
from absl import app
from absl import flags
from compiler_opt.tools import benchmark_report






flags.DEFINE_string('suite_name', 'benchmark_suite',
                    'The name of the benchmark suite (for reporting).')
flags.DEFINE_string('base', None,
                    'JSON report produced by the base benchmark run.')
flags.DEFINE_string('exp', None,
                    'JSON report produced by the experiment benchmark run.')
flags.DEFINE_string('output', 'reports.csv', 'CSV output')
flags.DEFINE_multi_string(
    'counters', None,
    'Counter names. Should match exactly the names used when running the'
    'benchmark.')

FLAGS = flags.FLAGS


def main(argv: Sequence[str]) -> None:
  if len(argv) > 1:
    raise app.UsageError('Too many command-line arguments.')
  with tf.io.gfile.GFile(FLAGS.base, 'r') as b:
    with tf.io.gfile.GFile(FLAGS.exp, 'r') as e:
      b = benchmark_report.BenchmarkReport(FLAGS.suite_name, json.load(b),
                                           FLAGS.counters)
      e = benchmark_report.BenchmarkReport(FLAGS.suite_name, json.load(e),
                                           FLAGS.counters)

# Path: compiler_opt/tools/benchmark_report.py
# def _geomean(data: List[float]):
# def _stdev(data: List[float]):
#   def __init__(self, suite_name: str, json_data: BenchmarkRunResults,
#                counter_names: Iterable[str]):
#   def suite_name(self):
#   def values(self):
#   def names(self):
#   def counters(self):
#   def raw_measurements(self):
#   def counter_means(self, benchmark: str, counter: str) -> Tuple[float, float]:
#   def zero_counters(self):
#   def large_variation_counters(self, variation: float):
#   def _load_values(self, data: BenchmarkRunResults,
#                    names: Iterable[str]) -> PerBenchmarkResults:
#   def __init__(self, base_report: BenchmarkReport, exp_report: BenchmarkReport):
#   def suite_name(self):
#   def summarize(self) -> ABComparison:
#   def names(self):
#   def counters(self):
#   def total_improvement(self, counter: str):
# class BenchmarkReport:
# class BenchmarkComparison:


# Path: compiler_opt/tools/benchmark_report_converter.py
import csv
import json
import tensorflow.compat.v2 as tf
from typing import Sequence
from absl import app
from absl import flags
from compiler_opt.tools import benchmark_report







flags.DEFINE_string('suite_name', 'benchmark_suite',
                    'The name of the benchmark suite (for reporting).')
flags.DEFINE_string('base', None,
                    'JSON report produced by the base benchmark run.')
flags.DEFINE_string('exp', None,
                    'JSON report produced by the experiment benchmark run.')
flags.DEFINE_string('output', 'reports.csv', 'CSV output')
flags.DEFINE_multi_string(
    'counters', None,
    'Counter names. Should match exactly the names used when running the'
    'benchmark.')

FLAGS = flags.FLAGS


def main(argv: Sequence[str]) -> None:
  if len(argv) > 1:
    raise app.UsageError('Too many command-line arguments.')
  with tf.io.gfile.GFile(FLAGS.base, 'r') as b:
    with tf.io.gfile.GFile(FLAGS.exp, 'r') as e:
      b = benchmark_report.BenchmarkReport(FLAGS.suite_name, json.load(b),
                                           FLAGS.counters)
      e = benchmark_report.BenchmarkReport(FLAGS.suite_name, json.load(e),
                                           FLAGS.counters)

      comparison = benchmark_report.BenchmarkComparison(b, e)