Ejemplo n.º 1
0
def test_reset():
    prf = Profiler()
    prf.start()
    f()
    prf.end()
    prf.reset()

    assert {} == prf.prf.__dict__
Ejemplo n.º 2
0
def test_end():
    prf = Profiler()
    prf.start()
    f()
    prf.end()
    t_1 = pstats.Stats(prf.prf).__dict__["total_tt"]
    t_2 = pstats.Stats(prf.prf).__dict__["total_tt"]
    assert t_1 == t_2
Ejemplo n.º 3
0
def test_start():
    prf = Profiler()
    prf.start()
    prf.end()
    t_1 = prf.getRuntime()

    prf.start()
    f()
    prf.end()
    t_2 = prf.getRuntime()
    assert t_1 != t_2
Ejemplo n.º 4
0
def test_getters():
    runs = 3

    prf = Profiler()
    for i in range(runs):
        prf.start()
        f()
        prf.end()

    assert prf.getRuntime() == pstats.Stats(prf.prf).__dict__["total_tt"]
    assert (prf.getAverageRuntime(runs) == pstats.Stats(
        prf.prf).__dict__["total_tt"] / runs)
    assert prf.getRuntime() != prf.getAverageRuntime(runs)
Ejemplo n.º 5
0
def test_f_output():
    runs = 3
    file = "test.txt"
    prf = Profiler()
    global f

    for i in range(runs):
        prf.start()
        f()
        prf.end()

    prf.dumpAverageStats("cumulative", file, runs)
    assert os.path.exists(file)

    with open(file, "r") as f:
        lines = f.readlines()

    assert "Averaged over {} trials".format(runs) in lines[2]

    os.remove(file)
Ejemplo n.º 6
0
def test_write_file():
    """Test that write_to_file, writes a profile to the correct file."""
    prf = Profiler()

    prf.start()
    f()
    prf.stop()

    prf.write_to_file("test.pstats")

    assert os.path.exists("test.pstats")

    sts = pstats.Stats("test.pstats")
    fn_names = []
    for stat in sts.__dict__["stats"]:
        fn_names.append(stat[2])

    assert "f" in fn_names

    os.remove("test.pstats")
    os.remove(prf._output + ".pstats")
Ejemplo n.º 7
0
def test_profiler():
    """ Test the profiler start/stop, ensure that f() has been profiled """
    prf = Profiler()

    prf.start()
    f()
    prf.stop()

    sts = pstats.Stats(prf._prf)
    assert "stats" in sts.__dict__

    fn_names = []
    for stat in sts.__dict__["stats"]:
        fn_names.append(stat[2])

    assert "f" in fn_names

    assert isinstance(prf.__str__(), str)
    assert "(f)" in prf.__str__()

    os.remove(prf._output + ".pstats")
Ejemplo n.º 8
0
def test_profiling_calc_pi(calc_pi_hpct_db):
    """Test debug wrapper as called from hpctoolkit."""
    prf = Profiler()
    output_file = prf._output + ".pstats"

    prf.start()
    gf = ht.GraphFrame.from_hpctoolkit(str(calc_pi_hpct_db))

    gf.copy()
    gf2 = gf.deepcopy()
    gf.tree()
    gf.to_dot()

    gf3 = gf + gf2
    gf *= gf2
    gf3 -= gf2

    gf.graph.traverse()
    gf.graph.copy()
    len(gf.graph)

    gf2 = gf.filter(lambda x: x["time"] > 0.01)

    gf2.squash()
    gf.drop_index_levels()

    prf.stop()

    assert os.path.exists(output_file)

    sts = pstats.Stats(output_file)

    fn_names = []
    for stat in sts.__dict__["stats"]:
        fn_names.append(stat[2])

    for call in decorated_calls:
        assert call in fn_names

    os.remove(output_file)