From a479e9aa504cf640c421b6c10835e9ecdc8a964a Mon Sep 17 00:00:00 2001 From: Federico Di Pierro Date: Fri, 14 Jun 2024 10:26:23 +0200 Subject: [PATCH] new(ci): added a `perf` CI job. Signed-off-by: Federico Di Pierro --- .github/workflows/ci.yml | 72 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 522df865bf6..88bebaee447 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -341,3 +341,75 @@ jobs: cd build && emcmake cmake -DUSE_BUNDLED_DEPS=True ../ emmake make -j4 emmake make run-unit-tests -j4 + + perf-libs-linux-amd64: + runs-on: 'ubuntu-22.04' + steps: + - name: Checkout Libs ⤵️ + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + 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 linux-headers-`uname -r` linux-tools-common linux-tools-generic linux-tools-`uname -r` + sudo .github/install-deps.sh + + - name: Build + run: | + mkdir -p build + cd build && cmake -DUSE_BUNDLED_DEPS=False ../ + make unit-test-libsinsp -j4 + + - name: Run Perf + run: | + cd build + sudo perf record --call-graph dwarf ./libsinsp/test/unit-test-libsinsp + + - name: Archive perf report (PR) + if: github.event_name == 'pull_request' + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 + with: + name: perf_report + retention-days: 1 # just 1 day because they are big and there can be multiple ones (ie: on each push to the PR) + path: build/perf.data + if-no-files-found: error + + - name: Archive perf report (master) + if: github.event_name == 'push' + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 + with: + name: perf_report + retention-days: 14 # 14 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: Download latest master report + if: github.event_name == 'pull_request' + uses: dawidd6/action-download-artifact@v6 + with: + workflow: ci.yml + branch: master + event: push + name: perf_report + + - name: Diff from master + if: github.event_name == 'pull_request' + run: | + sudo perf diff perf.data build/perf.data -d unit-test-libsinsp -b -o 0 --percentage relative -q &> perf_diff.txt + + - name: Archive perf diff + if: github.event_name == 'pull_request' + uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 + with: + name: perf_diff + path: perf_diff.txt + if-no-files-found: error + + - name: Check > 2% threshold + if: github.event_name == 'pull_request' + run: | + awk '{if (substr($2,RSTART+RLENGTH)+0 > 2) print }' perf_diff.txt &> perf_diff_above_thresh.txt + if [ "$(wc -l perf_diff_above_thresh.txt | awk '{print $1}')" -ne "0" ]; then + exit 1 + fi