Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add profiling for pytest #7135

Merged
merged 2 commits into from
Nov 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/actions/profile/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: profile
description: Run pytest with profiling
inputs:
arguments:
default: './src'
description: 'Arguments for pytest'
required: true

artifact_name:
default: 'prof.svg'
description: 'A name for the artifact'
required: true

runs:
using: 'composite'
steps:
- name: Install profiling dependencies (linux)
if: ${{runner.os == 'Linux'}}
shell: bash
run: |
sudo apt-get -y install graphviz

- name: Install profiling dependencies (macOS)
if: ${{runner.os == 'macOS'}}
shell: bash
run: |
brew install graphviz

- name: Install profiling dependencies (Windows)
if: ${{runner.os == 'Windows'}}
shell: bash
run: |
choco install graphviz

- name: Run Pytest with --profile-svg
shell: bash
run: |
pytest ${{inputs.arguments}} --profile-svg

- name: Check combined.prof existence
id: check_combined_prof
uses: andstor/file-existence-action@v2
with:
files: prof/combined.prof

- name: Run svg generation for Windows
shell: bash
if: ${{always() && runner.os == 'Windows' && steps.check_combined_prof.outputs.files_exists == 'true'}}
run: |
gprof2dot -f pstats prof/combined.prof > prof/tmp
dot -Tsvg -o prof/combined.svg prof/tmp

- uses: actions/upload-artifact@v3
if: ${{always()}}
with:
name: ${{runner.os}}_${{inputs.artifact_name}}
path: ./prof/combined.svg
retention-days: 1
6 changes: 6 additions & 0 deletions .github/workflows/!PR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,23 @@ jobs:

# PR is Ready only
pytest_nix:
needs: changes
if: ${{needs.changes.outputs.src == 'true' && !github.event.pull_request.draft}}
uses: ./.github/workflows/pytest.yml
with:
python-version: 3.8
matrix: '{"os": ["macos-latest", "ubuntu-latest"]}'

guitest_nix:
needs: changes
if: ${{needs.changes.outputs.src == 'true' && !github.event.pull_request.draft}}
uses: ./.github/workflows/guitest.yml
with:
python-version: 3.8
matrix: '{"os": ["macos-latest", "ubuntu-latest"]}'

ubuntu:
needs: changes
if: ${{needs.changes.outputs.build == 'true' && !github.event.pull_request.draft}}
uses: ./.github/workflows/build_ubuntu.yml
with:
Expand All @@ -102,6 +105,7 @@ jobs:
python-version: 3.8

windows:
needs: changes
if: ${{needs.changes.outputs.build == 'true' && !github.event.pull_request.draft}}
uses: ./.github/workflows/build_windows.yml
with:
Expand All @@ -110,6 +114,7 @@ jobs:
python-version: 3.8

mac:
needs: changes
if: ${{needs.changes.outputs.build == 'true' && !github.event.pull_request.draft}}
uses: ./.github/workflows/build_mac.yml
with:
Expand All @@ -118,6 +123,7 @@ jobs:
python-version: 3.8

documentation:
needs: changes
if: ${{needs.changes.outputs.doc == 'true' && !github.event.pull_request.draft}}
uses: ./.github/workflows/documentation.yml
with:
Expand Down
28 changes: 25 additions & 3 deletions .github/workflows/guitest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,27 @@ on:
required: false

matrix:
default: '{"os":["windows-latest"]}'
default: '{"os":["windows-latest", "macos-latest", "ubuntu-latest"]}'
type: string
required: false

enable-profiling:
default: true
type: boolean
required: false

jobs:
run:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix: ${{fromJson(inputs.matrix)}}

timeout-minutes: 10

env:
PYTEST_ARGUMENTS: ./src/tribler/gui --guitests -v --randomly-seed=1 --exitfirst --disable-warnings

steps:
- uses: actions/checkout@v3

Expand All @@ -42,10 +52,22 @@ jobs:
if: runner.os == 'Linux'
uses: pyvista/setup-headless-display-action@v1

- name: Add --looptime
if: runner.os != 'Windows'
run: |
echo "PYTEST_ARGUMENTS=$PYTEST_ARGUMENTS --looptime" >> $GITHUB_ENV

- name: Run GUI tests
timeout-minutes: 5
if: ${{!inputs.enable-profiling}}
run: |
pytest ./src/tribler/gui --guitests -v --randomly-seed=1 --timeout=300
pytest ${PYTEST_ARGUMENTS}

- name: Run GUI tests (Profiler)
if: ${{inputs.enable-profiling}}
uses: ./.github/actions/profile
with:
artifact_name: guitests_prof.svg
arguments: ${PYTEST_ARGUMENTS}

- uses: actions/upload-artifact@v3
if: always()
Expand Down
52 changes: 41 additions & 11 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,34 @@ on:
required: false

matrix:
default: '{"os":["ubuntu-latest"]}'
default: '{"os":["windows-latest", "macos-latest", "ubuntu-latest"]}'
type: string
required: false

enable_profiling:
default: true
type: boolean
required: false

jobs:
run:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix: ${{fromJson(inputs.matrix)}}

defaults:
run:
shell: bash

timeout-minutes: 10

env:
PYTEST_CORE_ARGUMENTS: ./src/tribler/core
PYTEST_TUNNELS_ARGUMENTS: ./src/tribler/core/components/tunnel/tests/test_full_session --tunneltests

PYTEST_COMMON_ARGUMENTS: --exitfirst --disable-warnings

steps:
- uses: actions/checkout@v3

Expand All @@ -29,22 +46,35 @@ jobs:
python-version: ${{inputs.python-version}}
requirements: requirements-test.txt

- name: Install windows dependencies
- name: Install dependencies (Windows)
if: runner.os == 'Windows'
uses: ./.github/actions/windows_dependencies

- name: Run Pytest (nix)
- name: Add --looptime
if: runner.os != 'Windows'
timeout-minutes: 5
run: |
pytest ./src/tribler/core --exitfirst --disable-warnings --looptime
echo "PYTEST_COMMON_ARGUMENTS=$PYTEST_COMMON_ARGUMENTS --looptime" >> $GITHUB_ENV

- name: Run Pytest (win)
if: runner.os == 'Windows'
timeout-minutes: 5
- name: Run Pytest
if: ${{!inputs.enable_profiling}}
run: |
pytest ./src/tribler/core --exitfirst --disable-warnings

pytest ${PYTEST_CORE_ARGUMENTS} ${PYTEST_COMMON_ARGUMENTS}

- name: Run Pytest (Profiler)
if: ${{inputs.enable_profiling}}
uses: ./.github/actions/profile
with:
artifact_name: pytest_prof.svg
arguments: ${PYTEST_CORE_ARGUMENTS} ${PYTEST_COMMON_ARGUMENTS}

- name: Run Tunnels Tests
if: ${{!inputs.enable_profiling}}
run: |
pytest ./src/tribler/core/components/tunnel/tests/test_full_session --tunneltests --exitfirst --disable-warnings
pytest ${PYTEST_TUNNELS_ARGUMENTS} ${PYTEST_COMMON_ARGUMENTS}

- name: Run Tunnel Tests (Profiler)
if: ${{inputs.enable_profiling}}
uses: ./.github/actions/profile
with:
artifact_name: tunneltest_prof.svg
arguments: ${PYTEST_TUNNELS_ARGUMENTS} ${PYTEST_COMMON_ARGUMENTS}
4 changes: 3 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ looptime==0.2

asynctest==0.13.0 # this library has to be installed to properly work with ipv8 TestBase.

scipy==1.8.0
scipy==1.8.0

pytest-profiling==1.7.0 # for pytest profiling