From 087b102c22c6ae6971ee231d79ee636b8c7c14f6 Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Thu, 20 Jun 2024 15:29:24 +0200 Subject: [PATCH] new(ci): move perf CI to a composite action. 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 --- .github/actions/composite-perf/action.yml | 48 +++++++++++++++++ .github/generate_inline_svg_md.py | 20 +++++++ .github/workflows/pages.yml | 63 ++++++++++++++++++++++- .github/workflows/perf.yml | 56 +++----------------- docs/index.md | 4 ++ docs/perf.md | 8 +++ mkdocs.yml | 4 ++ 7 files changed, 154 insertions(+), 49 deletions(-) create mode 100644 .github/actions/composite-perf/action.yml create mode 100644 .github/generate_inline_svg_md.py create mode 100644 docs/perf.md diff --git a/.github/actions/composite-perf/action.yml b/.github/actions/composite-perf/action.yml new file mode 100644 index 00000000000..2d96c904c14 --- /dev/null +++ b/.github/actions/composite-perf/action.yml @@ -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 \ No newline at end of file diff --git a/.github/generate_inline_svg_md.py b/.github/generate_inline_svg_md.py new file mode 100644 index 00000000000..c92cbead4f9 --- /dev/null +++ b/.github/generate_inline_svg_md.py @@ -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'' % 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]) \ No newline at end of file diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index a4deb187424..d871025fb1b 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -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: @@ -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 @@ -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 \ No newline at end of file diff --git a/.github/workflows/perf.yml b/.github/workflows/perf.yml index 8a5e4ea2f45..8e7a5b79564 100644 --- a/.github/workflows/perf.yml +++ b/.github/workflows/perf.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/docs/index.md b/docs/index.md index d952333a8e2..7a34565d20e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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). diff --git a/docs/perf.md b/docs/perf.md new file mode 100644 index 00000000000..27ab85ac8fc --- /dev/null +++ b/docs/perf.md @@ -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) \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index 4d6a11e6915..c83bfe1a96d 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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