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
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
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
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, _
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
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
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
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
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
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
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
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
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
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
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
def test_valgrind_fork(py, mode): result = valgrind([*python(py), target()], mode) assert result.returncode == 0, "\n".join((result.stdout, result.stderr))
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)