Esempio n. 1
0
def test_fork_wall_time(austin, py, heap):
    result = austin("-i", "2ms", *heap, *python(py), target("target34.py"))
    assert py in (result.stderr
                  or result.stdout), result.stderr or result.stdout

    assert len(processes(result.stdout)) == 1, compress(result.stdout)
    ts = threads(result.stdout)
    assert len(ts) == 2, compress(result.stdout)

    assert has_pattern(result.stdout,
                       "target34.py:keep_cpu_busy:3"), compress(result.stdout)
    assert not has_pattern(result.stdout, "Unwanted")

    meta = metadata(result.stdout)

    assert meta["mode"] == "wall"

    a = sum_metric(result.stdout)
    d = int(meta["duration"])

    assert 0 < a < 2.1 * d

    if austin == "austinp":
        ms = maps(result.stdout)
        assert len(ms) >= 2, ms
        assert [_ for _ in ms if "python" in _], ms
Esempio n. 2
0
def test_gc_on(py):
    result = austin("-gi", "1ms", *python(py), target("target_gc.py"))
    assert result.returncode == 0

    meta = metadata(result.stdout)
    assert float(meta["gc"]) / float(meta["duration"]) > 0.1

    gcs = [_ for _ in samples(result.stdout) if ":GC:" in _]
    assert len(gcs) > 10
Esempio n. 3
0
def test_where(py):
    with run_python(py, target("sleepy.py")) as p:
        sleep(1)
        result = austin("-w", str(p.pid))
        assert result.returncode == 0

        assert "Process" in result.stdout
        assert "Thread" in result.stdout
        assert "sleepy.py" in result.stdout
        assert "<module>" in result.stdout
Esempio n. 4
0
def test_pipe_cpu_time(py):
    result = austin("-sPi", "1ms", *python(py), target())
    assert result.returncode == 0

    meta = metadata(result.stdout)

    assert meta["python"].startswith(py), meta
    assert meta["mode"] == "cpu", meta
    assert int(meta["duration"]) > 100000, meta
    assert meta["interval"] == "1000", meta
Esempio n. 5
0
def test_accuracy_fast_recursive(py, heap):
    result = austin("-i", "1ms", *heap, *python(py), target("recursive.py"))
    assert result.returncode == 0, result.stderr or result.stdout

    assert has_pattern(result.stdout, "sum_up_to"), compress(result.stdout)
    assert has_pattern(result.stdout, ":INVALID:"), compress(result.stdout)

    for _ in samples(result.stdout):
        if "sum_up_to" in _ and "<module>" in _:
            assert len(_.split(";")) <= 20, _
Esempio n. 6
0
def test_gc_disabled(py, monkeypatch):
    monkeypatch.setenv("GC_DISABLED", "1")

    result = austin("-gi", "10ms", *python(py), target("target_gc.py"))
    assert result.returncode == 0

    meta = metadata(result.stdout)
    assert int(meta["gc"]) < int(meta["duration"]) / 20

    gcs = [_ for _ in samples(result.stdout) if ":GC:" in _]
    assert len(gcs) < 5
Esempio n. 7
0
def test_pipe_wall_time_multiprocess(py):
    result = austin("-CPi", "1ms", *python(py), target())
    assert result.returncode == 0

    meta = metadata(result.stdout)

    assert meta["mode"] == "wall", meta
    assert int(meta["duration"]) > 100000, meta
    assert meta["interval"] == "1000", meta
    assert meta["multiprocess"] == "on", meta
    assert meta["python"].startswith(py), meta
Esempio n. 8
0
def test_fork_multiprocess(py):
    result = austin("-Ci", "1ms", *python(py), target("target_mp.py"))
    assert result.returncode == 0, result.stderr or result.stdout

    ps = processes(result.stdout)
    assert len(ps) >= 3, ps

    meta = metadata(result.stdout)
    assert meta["multiprocess"] == "on", meta
    assert meta["mode"] == "wall", meta

    assert has_pattern(result.stdout, "target_mp.py:do:"), result.stdout
    assert has_pattern(result.stdout, "target_mp.py:fact:"), result.stdout
Esempio n. 9
0
def test_fork_cpu_time_idle(py):
    result = austin("-si", "1ms", *python(py), target("sleepy.py"))
    assert result.returncode == 0, result.stderr or result.stdout

    assert has_pattern(result.stdout,
                       "sleepy.py:<module>:"), compress(result.stdout)

    meta = metadata(result.stdout)

    a = sum_metric(result.stdout)
    d = int(meta["duration"])

    assert a < 1.1 * d
Esempio n. 10
0
def test_fork_exposure(py, exposure):
    result = austin("-i", "1ms", "-x", str(exposure), *python(py),
                    target("sleepy.py"), "1")
    assert result.returncode == 0, result.stderr or result.stdout

    assert has_pattern(result.stdout,
                       "sleepy.py:<module>:"), compress(result.stdout)

    meta = metadata(result.stdout)

    assert meta["mode"] == "wall"

    d = int(meta["duration"])
    assert 900000 * exposure < d < 1100000 * exposure
Esempio n. 11
0
def test_cli_no_python():
    result = austin(
        "-C",
        "powershell" if platform.system() == "Windows" else "bash",
        "-c",
        "sleep 1",
    )
    if platform.system() == "Darwin":
        # Darwin CI gives a different result than manual tests. We are accepting
        # this for now.
        assert result.returncode in (37, 39)
        assert "Insufficient permissions" in result.stderr, result.stderr
    else:
        assert result.returncode == 39
        assert "not a Python" in result.stderr or "Cannot launch" in result.stderr
Esempio n. 12
0
def test_attach_exposure(py, exposure):
    with run_python(py, target("sleepy.py"), "3") as p:
        result = austin("-i", "1ms", "-x", str(exposure), "-p", str(p.pid))
        assert result.returncode == 0

        assert has_pattern(result.stdout,
                           "sleepy.py:<module>:"), compress(result.stdout)

        meta = metadata(result.stdout)

        a = sum_metric(result.stdout)
        d = int(meta["duration"])

        assert exposure * 800000 <= d < exposure * 1200000

        p.kill()
Esempio n. 13
0
def test_fork_cpu_time_cpu_bound(py, heap):
    result = austin("-si", "1ms", *heap, *python(py), target("target34.py"))
    assert result.returncode == 0, result.stderr or result.stdout

    assert has_pattern(result.stdout,
                       "target34.py:keep_cpu_busy:3"), compress(result.stdout)
    assert not has_pattern(result.stdout, "Unwanted")

    meta = metadata(result.stdout)

    assert meta["mode"] == "cpu"

    a = sum_metric(result.stdout)
    d = int(meta["duration"])

    assert 0 < a < 2.1 * d
Esempio n. 14
0
def test_where_multiprocess(py):
    with run_python(py, target("target_mp.py")) as p:
        while p.returncode is None:
            sleep(0.2)
            result = austin("-Cw", str(p.pid))
            assert result.returncode == 0

            lines = Counter(result.stdout.splitlines())

            if sum(c for line, c in lines.items() if "Process" in line) >= 3:
                break
        else:
            assert False, result.stdout

        assert sum(c for line, c in lines.items()
                   if "fact" in line) == 2, result.stdout
        (join_line, ) = (line for line in lines if "join" in line)
        assert lines[join_line] == 1, result.stdout
Esempio n. 15
0
def test_fork_memory(py):
    result = austin("-mi", "1ms", *python(py), target("target34.py"))
    assert result.returncode == 0, result.stderr or result.stdout

    assert has_pattern(result.stdout, "target34.py:keep_cpu_busy:32")

    meta = metadata(result.stdout)

    assert meta["mode"] == "memory"

    d = int(meta["duration"])
    assert d > 100000

    ms = [int(_.rpartition(" ")[-1]) for _ in samples(result.stdout)]
    alloc = sum(_ for _ in ms if _ > 0)
    dealloc = sum(-_ for _ in ms if _ < 0)

    assert alloc * dealloc
Esempio n. 16
0
def test_attach_wall_time(py, mode, mode_meta, heap):
    with run_python(py, target("sleepy.py")) as p:
        sleep(0.5)

        result = austin(mode, f"10ms", *heap, "-p", str(p.pid))
        assert result.returncode == 0

        ts = threads(result.stdout)
        assert len(ts) == 1, compress(result.stdout)

        assert has_pattern(result.stdout,
                           "sleepy.py:<module>:"), compress(result.stdout)

        meta = metadata(result.stdout)

        assert meta["mode"] == mode_meta

        a = sum_metric(result.stdout)
        d = int(meta["duration"])

        assert a <= d
Esempio n. 17
0
def test_fork_output(py, tmp_path):
    datafile = tmp_path / "test_fork_output.austin"

    result = austin("-i", "1ms", "-o", datafile, *python(py),
                    target("target34.py"))
    assert result.returncode == 0, result.stderr or result.stdout

    assert "Unwanted" in result.stdout

    with datafile.open() as f:
        data = f.read()
        assert has_pattern(data, "target34.py:keep_cpu_busy:32")

        meta = metadata(data)

        assert meta["mode"] == "wall"

        a = sum(int(_.rpartition(" ")[-1]) for _ in samples(data))
        d = int(meta["duration"])

        assert 0 < 0.9 * d < a < 2.1 * d
Esempio n. 18
0
def test_fork_full_metrics(py):
    result = austin("-i", "10ms", "-f", *python(py), target("target34.py"))
    assert py in (result.stderr
                  or result.stdout), result.stderr or result.stdout

    assert len(processes(result.stdout)) == 1
    ts = threads(result.stdout)
    assert len(ts) == 2, ts

    assert has_pattern(result.stdout, "target34.py:keep_cpu_busy:32")
    assert not has_pattern(result.stdout, "Unwanted")

    meta = metadata(result.stdout)

    assert meta["mode"] == "full"

    wall, cpu, alloc, dealloc = sum_metrics(result.stdout)
    d = int(meta["duration"])

    assert 0 < 0.9 * d < wall < 2.1 * d
    assert 0 < cpu <= wall
    assert alloc * dealloc
Esempio n. 19
0
def test_pipe_wall_time(py):
    interval = 1
    result = austin("-Pi", f"{interval}ms", *python(py), target())
    assert result.returncode == 0

    meta = metadata(result.stdout)

    assert meta["python"].startswith(py), meta
    assert meta["mode"] == "wall", meta
    assert int(meta["duration"]) > 100000, meta
    assert meta["interval"] == str(interval * 1000), meta

    assert len(processes(result.stdout)) == 1
    ts = threads(result.stdout)
    assert len(ts) == 2, ts

    assert has_pattern(result.stdout, "target34.py:keep_cpu_busy:32")
    assert not has_pattern(result.stdout, "Unwanted")

    a = sum_metric(result.stdout)
    d = int(meta["duration"])

    assert 0 < 0.8 * d < a < 2.2 * d
Esempio n. 20
0
def test_pipe_wall_time_multiprocess_output(py, tmp_path):
    datafile = tmp_path / "test_pipe.austin"

    result = austin("-CPi", "1ms", "-o", str(datafile), *python(py), target())
    assert result.returncode == 0

    with datafile.open() as f:
        data = f.read()
        meta = metadata(data)

        assert meta, meta
        assert meta["mode"] == "wall", meta
        assert int(meta["duration"]) > 100000, meta
        assert meta["interval"] == "1000", meta
        assert meta["multiprocess"] == "on", meta
        assert meta["python"].startswith(py), meta

        assert has_pattern(data,
                           "target34.py:keep_cpu_busy:32"), compress(data)

        a = sum(int(_.rpartition(" ")[-1]) for _ in samples(data))
        d = int(meta["duration"])

        assert 0 < 0.8 * d < a < 2.2 * d
Esempio n. 21
0
def test_gc_off(py):
    result = austin("-i", "1ms", *python(py), target("target_gc.py"))
    assert result.returncode == 0

    assert not has_pattern(":GC:", result.stdout)
Esempio n. 22
0
def test_cli_permissions():
    with run_python("3", target("sleepy.py")) as p:
        result = austin("-i", "1ms", "-p", str(p.pid))
        assert result.returncode == 37, result.stderr
        assert "Insufficient permissions" in result.stderr, result.stderr
Esempio n. 23
0
def test_cli_invalid_pid():
    result = austin("-p", "9999999")

    assert result.returncode == 36
    assert "Cannot attach" in result.stderr
Esempio n. 24
0
def test_cli_invalid_command():
    result = austin("snafubar")
    assert result.returncode == 33
    assert "Cannot launch" in (result.stderr or result.stdout)
Esempio n. 25
0
def test_cli_no_arguments():
    result = austin()
    assert result.returncode == 0
    assert "Usage:" in result.stdout
    assert not result.stderr