chore: import upstream snapshot with attribution
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
build container image / cpu (push) Has been cancelled
build container image / cuda (push) Has been cancelled
build container image / rocm (push) Has been cancelled
frontend checks / frontend-checks (push) Has been cancelled
frontend tests / frontend-tests (push) Has been cancelled
lfs checks / lfs-check (push) Has been cancelled
python checks / python-checks (push) Has been cancelled
python tests / py3.12: macos-default (push) Has been cancelled
python tests / py3.11: windows-cpu (push) Has been cancelled
python tests / py3.12: windows-cpu (push) Has been cancelled
python tests / py3.11: linux-cpu (push) Has been cancelled
typegen checks / typegen-checks (push) Has been cancelled
uv lock checks / uv-lock-checks (push) Has been cancelled
openapi checks / openapi-checks (push) Has been cancelled
python tests / py3.11: macos-default (push) Has been cancelled
python tests / py3.12: linux-cpu (push) Has been cancelled
docs / deploy (push) Has been cancelled
docs / changes (push) Has been cancelled
docs / check-and-build (push) Has been cancelled
build container image / cpu (push) Has been cancelled
build container image / cuda (push) Has been cancelled
build container image / rocm (push) Has been cancelled
frontend checks / frontend-checks (push) Has been cancelled
frontend tests / frontend-tests (push) Has been cancelled
lfs checks / lfs-check (push) Has been cancelled
python checks / python-checks (push) Has been cancelled
python tests / py3.12: macos-default (push) Has been cancelled
python tests / py3.11: windows-cpu (push) Has been cancelled
python tests / py3.12: windows-cpu (push) Has been cancelled
python tests / py3.11: linux-cpu (push) Has been cancelled
typegen checks / typegen-checks (push) Has been cancelled
uv lock checks / uv-lock-checks (push) Has been cancelled
openapi checks / openapi-checks (push) Has been cancelled
python tests / py3.11: macos-default (push) Has been cancelled
python tests / py3.12: linux-cpu (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user