import json
import collections


def getBenchmarksFromJsonFile( jsonFile ):
    """
    Return an ordered dictionary containing the benchmarks from the benchmark file.
    
    The keys are the benchmark names and the values are lists of benchmark repetitions.

    Arguments:
        jsonFile: The google benchmark json output file.
    """
    with open( jsonFile, "r") as f:
        file = json.load( f )

    timeUnit = None
    benchmarks = collections.OrderedDict()
    for benchmark in file[ "benchmarks" ]:
        if benchmark[ "run_type" ] == "iteration":
            if timeUnit is None:
                timeUnit = benchmark[ "time_unit" ]
            elif timeUnit != benchmark[ "time_unit" ]:
                raise Exception( "Time unit mismatch!" )

            benchmarks.setdefault( benchmark[ "name" ], [] ).append( benchmark )

    return benchmarks