def METHOD_NAME():
    if len(sys.argv) != 2:
        print("Usage: ", sys.argv[0], "<simout directory>")
        exit(-1)
    try:
        stats = open(sys.argv[1] + "/stats.txt", "r")
    except IOError:
        print("Failed to open ", sys.argv[1] + "/stats.txt", " for reading")
        exit(-1)
    try:
        simout = open(sys.argv[1] + "/simout", "r")
    except IOError:
        print("Failed to open ", sys.argv[1] + "/simout", " for reading")
        exit(-1)
    # Get the address ranges
    got_ranges = False
    ranges = []
    iterations = 1
    for line in simout:
        if got_ranges:
            ranges.append(int(line) / 1024)
        match = re.match("lat_mem_rd with (\d+) iterations, ranges:.*", line)
        if match:
            got_ranges = True
            iterations = int(match.groups(0)[0])
    simout.close()
    if not got_ranges:
        print("Failed to get address ranges, ensure simout is up-to-date")
        exit(-1)
    # Now parse the stats
    raw_rd_lat = []
    for line in stats:
        match = re.match(".*readLatencyHist::mean\s+(.+)\s+#.*", line)
        if match:
            raw_rd_lat.append(float(match.groups(0)[0]) / 1000)
    stats.close()
    # The stats also contain the warming, so filter the latency stats
    i = 0
    filtered_rd_lat = []
    for l in raw_rd_lat:
        if i % (iterations + 1) == 0:
            pass
        else:
            filtered_rd_lat.append(l)
        i = i + 1
    # Next we need to take care of the iterations
    rd_lat = []
    for i in range(iterations):
        rd_lat.append(filtered_rd_lat[i::iterations])
    final_rd_lat = [min(p) for p in zip(*rd_lat)]
    # Sanity check
    if not (len(ranges) == len(final_rd_lat)):
        print(
            "Address ranges (%d) and read latency (%d) do not match"
            % (len(ranges), len(final_rd_lat))
        )
        exit(-1)
    for (r, l) in zip(ranges, final_rd_lat):
        print(r, round(l, 2))
    # lazy version to check if an integer is a power of two
    def is_pow2(num):
        return num != 0 and ((num & (num - 1)) == 0)
    plt.semilogx(ranges, final_rd_lat)
    # create human readable labels
    xticks_locations = [r for r in ranges if is_pow2(r)]
    xticks_labels = []
    for x in xticks_locations:
        if x < 1024:
            xticks_labels.append("%d kB" % x)
        else:
            xticks_labels.append("%d MB" % (x / 1024))
    plt.xticks(xticks_locations, xticks_labels, rotation=-45)
    plt.minorticks_off()
    plt.xlim((xticks_locations[0], xticks_locations[-1]))
    plt.ylabel("Latency (ns)")
    plt.grid(True)
    plt.show()