Skip to content

Commit

Permalink
MAINT: Add action for profiling (#888)
Browse files Browse the repository at this point in the history
  • Loading branch information
choldgraf committed Aug 22, 2022
1 parent 490a813 commit 4e7da76
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
31 changes: 31 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,34 @@ jobs:
temporaryPublicStorage: true
uploadArtifacts: true
runs: 3 # Multiple runs to reduce variance

# Generate a profile of the code and upload as an artifact
profile:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
cache-dependency-path: "pyproject.toml"

- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel setuptools nox
- name: Generate a profile
run: |
nox -s profile
continue-on-error: true

- uses: actions/upload-artifact@v3
with:
name: profile-results
path: profile.svg
7 changes: 6 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ def profile(session):
for ii in range(50):
(path_tmp / "many" / f"{ii}.rst").write_text("Test\n====\n\nbody\n")

if "-o" in session.posargs:
output = session.posargs[session.posargs.index("-o") + 1]
else:
output = "profile.svg"

# Specify our output directory and profile the build
path_tmp_out = path_tmp / "_build"
session.run(
*f"py-spy record -o profile.svg -- sphinx-build {path_tmp} {path_tmp_out}".split() # noqa
*f"py-spy record -o {output} -- sphinx-build {path_tmp} {path_tmp_out}".split() # noqa
)

0 comments on commit 4e7da76

Please sign in to comment.