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 automatic benchmarks to Github Actions #103

Draft
wants to merge 6 commits into
base: freeze-feat-andreas
Choose a base branch
from
Draft
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
80 changes: 80 additions & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Benchmark Wayshot

on:
pull_request:
types:
- opened
- reopened
- synchronize

permissions:
pull-requests: write

jobs:
benchmark:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install dependencies
run: |
# install sway and flamegraph dependencies
sudo apt update
sudo apt install --no-install-recommends -y sway \
linux-tools-common linux-tools-generic linux-tools-`uname -r`
# install flamegraph-rs
cargo install flamegraph
# install hyperfine
wget https://github.com/sharkdp/hyperfine/releases/download/v1.16.1/hyperfine_1.16.1_amd64.deb
sudo dpkg -i hyperfine_1.16.1_amd64.deb

- name: Run benchmarks
run: |
export XDG_RUNTIME_DIR=/tmp
export WLR_BACKENDS=headless
export WLR_LIBINPUT_NODEVICES=1
export WLR_RENDERER_ALLOW_SOFTWARE=1
export SWAYSOCK=/tmp/swaysock

# file where we'll store $WAYLAND_DISPLAY
export SWAY_STARTUP=/tmp/sway_startup

sway -c ./test/swayconfig -d &
export SWAY_PID=$!
# TODO: maybe find a more elegant way to wait for sway to start
sleep 10

# load WAYLAND_DISPLAY from the file we stored it in, as defined
# in the test sway config
read wayland_display < "$SWAY_STARTUP"
export WAYLAND_DISPLAY="$wayland_display"
sudo sh -c 'echo -1 >/proc/sys/kernel/perf_event_paranoid'
cargo flamegraph --release -- --log-level debug - > /dev/null
hyperfine --export-markdown hyperfine.md --export-json hyperfine.json "cargo run --release -- --log-level debug - > /dev/null"

- name: Upload benchmark results
uses: actions/upload-artifact@v4
id: upload-artifacts
with:
name: benchmark-results
path: |
flamegraph.svg
perf.data
hyperfine.json

- name: Generate PR comment
run: |
touch comment.txt
echo "Here are the benchmark results for this changeset:" >> comment.txt
echo "" >> comment.txt
cat hyperfine.md >> comment.txt
FLAMEGRAPH_ARTIFACT_URL=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts/${{ steps.upload-artifacts.outputs.artifact-id }}
echo "" >> comment.txt
echo "You can download perf data and a flamegraph heatmap for this changeset [here]($FLAMEGRAPH_ARTIFACT_URL)." >> comment.txt

- name: Post comment with results on PR
uses: thollander/actions-comment-pull-request@v2
with:
filePath: ./comment.txt
52 changes: 52 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,55 @@ jobs:
sudo apt update
sudo apt install --no-install-recommends scdoc
for file in $(find . -type f -iwholename "./docs/*.scd"); do scdoc < $file > /dev/null; done

benchmark:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install dependencies
run: |
# install sway and flamegraph dependencies
sudo apt update
sudo apt install --no-install-recommends -y sway \
linux-tools-common linux-tools-generic linux-tools-`uname -r`
# install flamegraph-rs
cargo install flamegraph
# install hyperfine
wget https://github.com/sharkdp/hyperfine/releases/download/v1.16.1/hyperfine_1.16.1_amd64.deb
sudo dpkg -i hyperfine_1.16.1_amd64.deb

- name: Run benchmarks
run: |
export XDG_RUNTIME_DIR=/tmp
export WLR_BACKENDS=headless
export WLR_LIBINPUT_NODEVICES=1
export WLR_RENDERER_ALLOW_SOFTWARE=1
export SWAYSOCK=/tmp/swaysock

# file where we'll store $WAYLAND_DISPLAY
export SWAY_STARTUP=/tmp/sway_startup

sway -c ./test/swayconfig -d &
export SWAY_PID=$!
# TODO: maybe find a more elegant way to wait for sway to start
sleep 10

# load WAYLAND_DISPLAY from the file we stored it in, as defined
# in the test sway config
read wayland_display < "$SWAY_STARTUP"
export WAYLAND_DISPLAY="$wayland_display"
sudo sh -c 'echo -1 >/proc/sys/kernel/perf_event_paranoid'
cargo flamegraph --release -- --log-level debug - > /dev/null
hyperfine --export-json hyperfine.json "cargo run --release -- --log-level debug - > /dev/null"

- name: Collect benchmark results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: |
flamegraph.svg
perf.data
hyperfine.json
27 changes: 27 additions & 0 deletions test/swayconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Create a virtual, headless output for wayshot to capture
output HEADLESS-1 {
pos 1920,0
mode 1280x720@75Hz
}

### Store the $WAYLAND_DISPLAY variable in a file
exec echo "$WAYLAND_DISPLAY" > "$SWAY_STARTUP"

# Status Bar:
#
# Read `man 5 sway-bar` for more information about this section.
bar {
position top

# When the status_command prints a new line to stdout, swaybar updates.
# The default just shows the current date and time.
status_command while date +'%Y-%m-%d %I:%M:%S %p'; do sleep 1; done

colors {
statusline #ffffff
background #323232
inactive_workspace #32323200 #32323200 #5c5c5c
}
}

include /etc/sway/config.d/*
Loading