Skip to content

Commit

Permalink
new(ci): move perf CI to a composite action.
Browse files Browse the repository at this point in the history
It will be ran by perf CI on PRs and pages CI on master.
Also, add a new gh pages section with flamegraphs built from master.

Signed-off-by: Federico Di Pierro <[email protected]>
  • Loading branch information
FedeDP committed Jun 20, 2024
1 parent 273299c commit 087b102
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 49 deletions.
48 changes: 48 additions & 0 deletions .github/actions/composite-perf/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: 'libs-perf'
description: 'Run multiple perf tests on libs.'

outputs:
perf_tests:
description: "Unit tests perf.data"
value: ${{ steps.store-outputs.outputs.tests }}
perf_scap:
description: "Scap file perf.data"
value: ${{ steps.store-outputs.outputs.scap }}

runs:
using: "composite"
steps:
- name: Install deps ⛓️
shell: bash
run: |
sudo apt update && sudo apt install -y --no-install-recommends ca-certificates cmake build-essential git clang llvm pkg-config autoconf automake libtool libelf-dev wget libc-ares-dev libcurl4-openssl-dev libssl-dev libtbb-dev libjq-dev libjsoncpp-dev libgrpc++-dev protobuf-compiler-grpc libgtest-dev libprotobuf-dev
sudo .github/install-deps.sh
- name: Build
shell: bash
run: |
mkdir -p build
cd build && cmake -DUSE_BUNDLED_DEPS=False ../
make unit-test-libsinsp -j4
make sinsp-example -j4
- name: Run Perf - unit tests
shell: bash
run: |
cd build
sudo perf record --call-graph dwarf -o perf_tests.data -q libsinsp/test/unit-test-libsinsp
- name: Run Perf - scap file
shell: bash
run: |
cd build
wget https://download.falco.org/fixtures/trace-files/traces-positive.zip
unzip traces-positive.zip
sudo perf record --call-graph dwarf -o perf_scap.data -q ./libsinsp/examples/sinsp-example -s traces-positive/falco-event-generator.scap
- name: Set Outputs
id: store-outputs
shell: bash
run: |
echo "tests=${{ github.action_path }}/build/perf_tests.data" >> $GITHUB_OUTPUT
echo "scap=${{ github.action_path }}/build/perf_scap.data" >> $GITHUB_OUTPUT
20 changes: 20 additions & 0 deletions .github/generate_inline_svg_md.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Small script used by pages workflow
# to generate markdown pages with inlined svgs.

import sys
import base64

def generate_md(svg):
b64 = base64.b64encode(svg.encode('utf-8')).decode("utf-8")
html = r'<img src="data:image/svg+xml;base64,%s"/>' % b64
with open("out.md", "w") as f:
f.write(html)

def inline_svg_to_md(svg_file):
with open(svg_file, "r") as f:
lines = f.readlines()
svg=''.join(lines)
generate_md(svg)

if __name__ == '__main__':
inline_svg_to_md(sys.argv[1])
63 changes: 62 additions & 1 deletion .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,53 @@ jobs:
uses: ./.github/workflows/reusable_kernel_tests.yaml
secrets: inherit

perf-libs-master:
runs-on: [ "self-hosted", "linux", "X64" ]
steps:
- name: Checkout Libs ⤵️
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: Run perf
id: perf
uses: ./.github/actions/composite-perf

- name: Archive master perf report
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: perf_report
retention-days: 30 # 30 days because this is the artifact on master; we need to retain it to be able to properly diff it
path: |
${{ steps.perf.outputs.perf_tests }}
${{ steps.perf.outputs.perf_scap }}
if-no-files-found: error

- name: Checkout Flamegraph ⤵️
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
repository: 'brendangregg/FlameGraph'
path: flamegraph

- name: Generate svg file - unit tests
run: |
sudo perf script --dsos unit-test-libsinsp -i ${{ steps.perf.outputs.perf_tests }} > trace_tests.perf
flamegraph/stackcollapse-perf.pl trace_tests.perf > trace_tests.folded
flamegraph/flamegraph.pl trace_tests.folded > trace_tests.svg
- name: Generate svg file - scap file
run: |
sudo perf script --dsos sinsp-example -i ${{ steps.perf.outputs.perf_scap }} > trace_scap.perf
flamegraph/stackcollapse-perf.pl trace_scap.perf > trace_scap.folded
flamegraph/flamegraph.pl trace_scap.folded > trace_scap.svg
- name: Upload svg files
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: perf_svg
path: trace_*.svg
if-no-files-found: error

deploy-pages:
needs: [kernel-tests-master]
environment:
Expand Down Expand Up @@ -50,6 +97,20 @@ jobs:
- uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # v4.7.1
with:
python-version: 3.x

- name: Download perf svg files
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: perf_svg

- name: Generate perf pages
run: |
python3 ./github/generate_inline_svg_md.py trace_tests.svg
mv out.md docs/unit_tests.md
rm -rf out.md
python3 ./github/generate_inline_svg_md.py trace_scap.svg
mv out.md docs/scap_file.md
rm -rf out.md
- run: pip install mkdocs mkdocs-material

Expand All @@ -60,4 +121,4 @@ jobs:
path: 'site'

- id: deployment
uses: actions/deploy-pages@9dbe3824824f8a1377b8e298bafde1a50ede43e5 # v2.0.4
uses: actions/deploy-pages@9dbe3824824f8a1377b8e298bafde1a50ede43e5 # v2.0.4
56 changes: 8 additions & 48 deletions .github/workflows/perf.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Perf CI
on:
pull_request:
push:
branches:
- master
workflow_dispatch:

# Checks if any concurrent jobs under the same pull request or branch are being executed
Expand All @@ -20,62 +17,27 @@ jobs:
with:
fetch-depth: 0

- name: Install deps ⛓️
run: |
sudo apt update && sudo apt install -y --no-install-recommends ca-certificates cmake build-essential git clang llvm pkg-config autoconf automake libtool libelf-dev wget libc-ares-dev libcurl4-openssl-dev libssl-dev libtbb-dev libjq-dev libjsoncpp-dev libgrpc++-dev protobuf-compiler-grpc libgtest-dev libprotobuf-dev
sudo .github/install-deps.sh
- name: Build
run: |
mkdir -p build
cd build && cmake -DUSE_BUNDLED_DEPS=False ../
make unit-test-libsinsp -j4
make sinsp-example -j4
- name: Run Perf - unit tests
shell: bash
run: |
cd build
sudo perf record --call-graph dwarf -o perf_tests.data -q libsinsp/test/unit-test-libsinsp
- name: Run Perf - scap file
shell: bash
run: |
cd build
wget https://download.falco.org/fixtures/trace-files/traces-positive.zip
unzip traces-positive.zip
sudo perf record --call-graph dwarf -o perf_scap.data -q ./libsinsp/examples/sinsp-example -s traces-positive/falco-event-generator.scap
- name: Archive master perf report
if: github.event_name == 'push'
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: perf_report
retention-days: 30 # 30 days because this is the artifact on master; we need to retain it to be able to properly diff it
path: build/perf_*.data
if-no-files-found: error
- name: Run perf
id: perf
uses: ./.github/actions/composite-perf

- name: Download latest master report
if: github.event_name == 'pull_request'
uses: dawidd6/action-download-artifact@v6
with:
workflow: perf.yml
workflow_search: true
branch: master
event: push
name: perf_report

- name: Diff from master - unit tests
if: github.event_name == 'pull_request'
run: |
sudo perf diff perf_tests.data build/perf_tests.data -d unit-test-libsinsp -b -o 1 --percentage relative -q &> perf_tests_diff.txt
sudo perf diff perf_tests.data ${{ steps.perf.outputs.perf_tests }} -d unit-test-libsinsp -b -o 1 --percentage relative -q &> perf_tests_diff.txt
- name: Diff from master - scap file
if: github.event_name == 'pull_request'
run: |
sudo perf diff perf_scap.data build/perf_scap.data -d sinsp-example -b -o 1 --percentage relative -q &> perf_scap_diff.txt
sudo perf diff perf_scap.data ${{ steps.perf.outputs.perf_scap }} -d sinsp-example -b -o 1 --percentage relative -q &> perf_scap_diff.txt
- name: Archive perf diff
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: perf_diff
Expand All @@ -85,7 +47,6 @@ jobs:
# Check will fail if there is any function slowed down >2%
# But we will always comment with the perf diff from master
- name: Check > 2% threshold - unit tests
if: github.event_name == 'pull_request'
id: compare_tests
run: |
echo "diff=perf_tests_diff.txt" >> $GITHUB_OUTPUT
Expand All @@ -97,7 +58,6 @@ jobs:
# Check will fail if there is any function slowed down >2%
# But we will always comment with the perf diff from master
- name: Check > 2% threshold - scap file
if: github.event_name == 'pull_request'
id: compare_scap
run: |
echo "diff=perf_scap_diff.txt" >> $GITHUB_OUTPUT
Expand All @@ -107,7 +67,7 @@ jobs:
fi
- name: Save PR info
if: always() && github.event_name == 'pull_request'
if: always()
run: |
mkdir -p ./pr
echo ${{ github.event.number }} > ./pr/NR
Expand All @@ -126,7 +86,7 @@ jobs:
echo ""
- name: Upload PR info as artifact
if: always() && github.event_name == 'pull_request'
if: always()
uses: actions/upload-artifact@v4
with:
name: pr
Expand Down
4 changes: 4 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ Navigate to the Home of Falco Drivers Kernel Testing on the left, or click this
## Supported Syscalls Report

Navigate to the Home of Falco Drivers Syscalls Report on the left, or click this [link](syscalls.md), or directly proceed to the supported syscalls [report](report.md).

## Perf Continuous Monitoring

Navigate to the Home of Falco Perf Monitoring on the left, or click this [link](perf.md).
8 changes: 8 additions & 0 deletions docs/perf.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Home of Falco Perf Monitoring

Our CI is capable of continuosuly benchmarking performance of our userspace code.
Every PR will have a comment with the perf diff from master for multiple aspects, while on master the flamegraph are pushed to this github pages.

Navigate to the perf reports on the left, or click these links:
* [unit tests perf](unit_tests.md)
* [scap file reading perf](scap_file.md)
4 changes: 4 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ nav:
- Syscalls:
- syscalls.md
- Report: report.md
- Perf:
- perf.md
- Unit tests: unit_tests.md
- Scap file: scap_file.md

theme: material

0 comments on commit 087b102

Please sign in to comment.