From f8ad5d1c4700b11fc5e0d2797bf250deaae17d78 Mon Sep 17 00:00:00 2001 From: Brett Date: Mon, 23 Sep 2024 15:11:45 -0400 Subject: [PATCH] add profile run to ci --- .github/workflows/ci.yml | 10 ++++++++++ asdf/conftest.py | 24 ++++++++++++++++++++++++ tox.ini | 8 ++++++++ 3 files changed, 42 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f54064da8..d58c205d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -125,3 +125,13 @@ jobs: default_python: '3.11' envs: | - linux: compatibility + + profile: + uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1 + with: + submodules: false + # Any env name which does not start with `pyXY` will use this Python version. + default_python: '3.12' + envs: | + - linux: profile + artifact-path: .profiles/* diff --git a/asdf/conftest.py b/asdf/conftest.py index 7712992a2..70729fff6 100644 --- a/asdf/conftest.py +++ b/asdf/conftest.py @@ -1,4 +1,5 @@ import os +from pathlib import Path import pytest @@ -8,6 +9,29 @@ collect_ignore = ["asdf.py", "stream.py"] +try: + from pyinstrument import Profiler + + TESTS_ROOT = Path.cwd() + + @pytest.fixture(autouse=True) + def auto_profile(request): + PROFILE_ROOT = TESTS_ROOT / ".profiles" + # Turn profiling on + profiler = Profiler() + profiler.start() + + yield # Run test + + profiler.stop() + PROFILE_ROOT.mkdir(exist_ok=True) + results_file = PROFILE_ROOT / f"{request.node.name}.html" + profiler.write_html(results_file) + +except ImportError: + pass + + def pytest_collection_modifyitems(items): # Turn warnings into errors for all tests, this is needed # as running tests through pyargs will not use settings diff --git a/tox.ini b/tox.ini index 326489c2a..70dc11b64 100644 --- a/tox.ini +++ b/tox.ini @@ -13,6 +13,7 @@ env_list = weldx sunpy dkist + profile [testenv] set_env = @@ -324,3 +325,10 @@ commands = # https://github.com/sunpy/sunpy/pull/7432 pytest dkist --benchmark-skip \ -W "ignore::asdf.exceptions.AsdfManifestURIMismatchWarning" + +[testenv:profile] +commands_pre = + pip install pyinstrument + pip freeze +commands = + pyinstrument -m pytest {posargs}