cddb07a176
build container image / cpu (push) Waiting to run
build container image / cuda (push) Waiting to run
build container image / rocm (push) Waiting to run
frontend tests / frontend-tests (push) Waiting to run
openapi checks / openapi-checks (push) Waiting to run
python tests / py3.12: macos-default (push) Waiting to run
python tests / py3.11: windows-cpu (push) Waiting to run
python tests / py3.12: windows-cpu (push) Waiting to run
python tests / py3.11: linux-cpu (push) Waiting to run
python tests / py3.12: linux-cpu (push) Waiting to run
typegen checks / typegen-checks (push) Waiting to run
uv lock checks / uv-lock-checks (push) Waiting to run
frontend checks / frontend-checks (push) Waiting to run
lfs checks / lfs-check (push) Waiting to run
python checks / python-checks (push) Waiting to run
python tests / py3.11: macos-default (push) Waiting to run
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
54 lines
1.7 KiB
Python
54 lines
1.7 KiB
Python
import re
|
|
from logging import Logger
|
|
from pathlib import Path
|
|
from tempfile import TemporaryDirectory
|
|
|
|
import pytest
|
|
|
|
from invokeai.app.util.profiler import Profiler
|
|
|
|
|
|
def test_profiler_starts():
|
|
with TemporaryDirectory() as tempdir:
|
|
profiler = Profiler(logger=Logger("test_profiler"), output_dir=Path(tempdir))
|
|
assert not profiler._profiler
|
|
assert not profiler.profile_id
|
|
profiler.start("test")
|
|
assert profiler._profiler
|
|
assert profiler.profile_id == "test"
|
|
profiler.stop()
|
|
assert not profiler._profiler
|
|
assert not profiler.profile_id
|
|
profiler.start("test2")
|
|
assert profiler._profiler
|
|
assert profiler.profile_id == "test2"
|
|
profiler.stop()
|
|
|
|
|
|
def test_profiler_profiles():
|
|
with TemporaryDirectory() as tempdir:
|
|
profiler = Profiler(logger=Logger("test_profiler"), output_dir=Path(tempdir))
|
|
profiler.start("test")
|
|
for _ in range(1000000):
|
|
pass
|
|
profiler.stop()
|
|
assert (Path(tempdir) / "test.prof").exists()
|
|
|
|
|
|
def test_profiler_profiles_with_prefix():
|
|
with TemporaryDirectory() as tempdir:
|
|
profiler = Profiler(logger=Logger("test_profiler"), output_dir=Path(tempdir), prefix="prefix")
|
|
profiler.start("test")
|
|
for _ in range(1000000):
|
|
pass
|
|
profiler.stop()
|
|
assert (Path(tempdir) / "prefix_test.prof").exists()
|
|
|
|
|
|
def test_profile_fails_if_not_set_up():
|
|
with TemporaryDirectory() as tempdir:
|
|
profiler = Profiler(logger=Logger("test_profiler"), output_dir=Path(tempdir))
|
|
match = re.escape("Profiler not initialized. Call start() first.")
|
|
with pytest.raises(RuntimeError, match=match):
|
|
profiler.stop()
|