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

new(ci,benchmarks): added more benchmarks and make use of them in perf CI #2023

Merged
merged 5 commits into from
Aug 27, 2024
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
13 changes: 12 additions & 1 deletion .github/actions/composite-perf/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ outputs:
heaptrack_scap:
description: "Scap file heaptrack data"
value: ${{ steps.store-outputs.outputs.heaptrack_scap }}
gbench_json:
description: "Google benchmarks json data"
value: ${{ steps.store-outputs.outputs.gbench_json }}

runs:
using: "composite"
Expand All @@ -28,8 +31,9 @@ runs:
shell: bash
run: |
mkdir -p build
cd build && cmake -DUSE_BUNDLED_DEPS=False -DCMAKE_BUILD_TYPE=Debug ../
cd build && cmake -DUSE_BUNDLED_DEPS=False -DCMAKE_BUILD_TYPE=Debug -DENABLE_BENCHMARKS=True ../
make unit-test-libsinsp -j4
make bench -j4
make sinsp-example -j4

- name: Download scap file
Expand Down Expand Up @@ -70,6 +74,12 @@ runs:
cd build
sudo heaptrack -o heaptrack_scap.data ./libsinsp/examples/sinsp-example -s traces-positive/falco-event-generator.scap

- name: Run - gbench
shell: bash
run: |
cd build
./benchmark/bench --benchmark_repetitions=20 --benchmark_report_aggregates_only --benchmark_out=gbench_data.json --benchmark_out_format=json

- name: Set Outputs
id: store-outputs
shell: bash
Expand All @@ -79,3 +89,4 @@ runs:
echo "perf_scap=$(realpath perf_scap.data)" >> $GITHUB_OUTPUT
echo "heaptrack_tests=$(realpath heaptrack_tests.data.zst)" >> $GITHUB_OUTPUT
echo "heaptrack_scap=$(realpath heaptrack_scap.data.zst)" >> $GITHUB_OUTPUT
echo "gbench_json=$(realpath gbench_data.json)" >> $GITHUB_OUTPUT
1 change: 1 addition & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
${{ steps.perf.outputs.perf_scap }}
${{ steps.perf.outputs.heaptrack_tests }}
${{ steps.perf.outputs.heaptrack_scap }}
${{ steps.perf.outputs.gbench_json }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pages CI will now upload also master gbench json too.

if-no-files-found: error

- name: Checkout Flamegraph ⤵️
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ jobs:
- name: Checkout Libs ⤵️
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Checkout Google benchmark ⤵️
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
repository: 'google/benchmark'
ref: 'v1.9.0'
path: google-benchmark/

- name: Run perf
id: perf
uses: ./.github/actions/composite-perf
Expand Down Expand Up @@ -43,6 +50,11 @@ jobs:
run: |
sudo heaptrack_print heaptrack_scap.data.zst -d ${{ steps.perf.outputs.heaptrack_scap }} &> heaptrack_scap_diff.txt

- name: Diff from master - gbench
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The algorithm is as follows:

  • load all benchmarks present in master json
  • for each of them, take the master real_time value
  • for each of them, take the PR's head real_time value
  • if PR's head does not have the benchmark, skip it
  • compute the diff between head and master
  • compute the diff in percentage between head and master

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you ever considered to use the compare.py tool https:/google/benchmark/blob/main/docs/tools.md#comparepy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! I'll give it a look and eventually implement it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented, thanks!

run: |
pip3 install -r google-benchmark/tools/requirements.txt
python3 google-benchmark/tools/compare.py --no-color benchmarks gbench_data.json ${{ steps.perf.outputs.gbench_json }} &> gbench_diff.txt

- name: Archive perf diff
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
Expand Down Expand Up @@ -75,6 +87,10 @@ jobs:
echo "\`\`\`" >> ./pr/COMMENT
tail -n3 "heaptrack_scap_diff.txt" >> ./pr/COMMENT
echo "\`\`\`" >> ./pr/COMMENT
echo "# Benchmarks diff from master" >> ./pr/COMMENT
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the PERF comment, echo the full benchmark diffs.

echo "\`\`\`" >> ./pr/COMMENT
cat "gbench_diff.txt" >> ./pr/COMMENT
echo "\`\`\`" >> ./pr/COMMENT
echo Uploading PR info...
cat ./pr/COMMENT
echo ""
Expand Down Expand Up @@ -135,3 +151,15 @@ jobs:
if [ -s heaptrack_scap_diff_above_thresh.txt ]; then
exit 2
fi

# Check will fail if there any google benchmark is slowed more than 5%
- name: Check >= 5% slowdown on google benchmarks
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For every benchmark in our diff, check if diff in percentage is above 5% and eventually trigger a failure.

if: always() # Even if other threshold checks failed
run: |
# Remove first 3 lines and last line that are no tests results
tail -n+4 gbench_diff.txt | head -n -1 | while read p; do
diff_pct=$(echo "$p" | awk '{print $3}' | tr -d '+')
if (( $(echo "$diff_pct >= 5.0" | bc -l) )); then
exit 1
fi
done
46 changes: 45 additions & 1 deletion benchmark/libsinsp/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,48 @@ static void BM_sinsp_split(benchmark::State& state)
sinsp_split(str, ',');
}
}
BENCHMARK(BM_sinsp_split)->Repetitions(2);
BENCHMARK(BM_sinsp_split);

static void BM_sinsp_concatenate_paths_relative_path(benchmark::State& state)
{
std::string path1 = "/tmp/";
std::string path2 = "foo/bar";
for(auto _ : state)
{
sinsp_utils::concatenate_paths(path1, path2);
}
}
BENCHMARK(BM_sinsp_concatenate_paths_relative_path);

static void BM_sinsp_concatenate_paths_empty_path(benchmark::State& state)
{
std::string path1 = "/tmp/";
std::string path2 = "";
for(auto _ : state)
{
sinsp_utils::concatenate_paths(path1, path2);
}
}
BENCHMARK(BM_sinsp_concatenate_paths_empty_path);

static void BM_sinsp_concatenate_paths_absolute_path(benchmark::State& state)
{
std::string path1 = "/tmp/";
std::string path2 = "/foo/bar";
for(auto _ : state)
{
sinsp_utils::concatenate_paths(path1, path2);
}
}
BENCHMARK(BM_sinsp_concatenate_paths_absolute_path);

static void BM_sinsp_split_container_image(benchmark::State& state)
{
std::string container_image = "localhost:12345/library/busybox:1.27.2@sha256:da39a3ee5e6b4b0d3255bfef95601890afd80709";
std::string hostname, port, name, tag, digest;
for(auto _ : state)
{
sinsp_utils::split_container_image(container_image, hostname, port, name, tag, digest);
}
}
BENCHMARK(BM_sinsp_split_container_image);
2 changes: 1 addition & 1 deletion userspace/libsinsp/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,7 @@ std::vector<std::string> sinsp_split(std::string_view sv, char delim)
}

std::string_view::size_type start = 0;
for (std::string_view::size_type i = 0; i < sv.size(); i++)
for (std::string_view::size_type i = 0; i < sv.size(); i++)
{
if (sv[i] == delim)
{
Expand Down
Loading