Skip to content

Commit bd89c43

Browse files
committed
Add tracebox and advanced profiling support to Perfetto workflow
Enable heap profiling, CPU profiling, and system-wide tracing via Perfetto's tracebox tool for comprehensive performance analysis. Changes: - Install tracebox binary in CI Docker image from get.perfetto.dev for system-wide profiling capabilities - Add workflow_dispatch inputs for perfetto-heap-profile and perfetto-cpu-profile to control profiling modes (CPU profiling enabled by default, heap profiling opt-in) - Add SYS_PTRACE capability and disable seccomp in container options to enable perf_event access required for CPU profiling - Configure perf_event_paranoid=-1 at runtime when CPU profiling is enabled to allow non-root access to performance counters - Update Perfetto profiling step to conditionally wrap ctest execution with tracebox when heap or CPU profiling is enabled, passing appropriate flags (--heapprofd for heap, --cpu-freq/--cpu-idle/ --cpu-sched for CPU) - Fall back to SDK-only tracing when no system profiling is requested Users can now enable heap profiling and CPU counter profiling via workflow_dispatch inputs to capture detailed memory allocation patterns and CPU performance metrics alongside application traces.
1 parent bec6861 commit bd89c43

2 files changed

Lines changed: 49 additions & 5 deletions

File tree

.github/workflows/cmake-build.yaml

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ on:
2626
Default (if empty): Run `gcc/none`
2727
required: false
2828
default: ''
29+
perfetto-heap-profile:
30+
description: "Enable heap profiling for Perfetto runs"
31+
required: false
32+
type: boolean
33+
default: false
34+
perfetto-cpu-profile:
35+
description: "Enable CPU profiling for Perfetto runs"
36+
required: false
37+
type: boolean
38+
default: true
2939
workflow_call:
3040
inputs:
3141
checkout-path:
@@ -193,6 +203,7 @@ jobs:
193203

194204
container:
195205
image: ghcr.io/framework-r-d/phlex-ci:latest
206+
options: --cap-add=SYS_PTRACE --security-opt seccomp=unconfined
196207

197208
steps:
198209
- name: Check out code
@@ -270,17 +281,45 @@ jobs:
270281
271282
- name: Run Perfetto profiling
272283
if: matrix.sanitizer == 'perfetto'
284+
env:
285+
PERFETTO_HEAP_PROFILE: ${{ github.event.inputs.perfetto-heap-profile || 'false' }}
286+
PERFETTO_CPU_PROFILE: ${{ github.event.inputs.perfetto-cpu-profile || 'true' }}
273287
run: |
274288
. /entrypoint.sh
275289
cd "$GITHUB_WORKSPACE/${{ env.local_build_path }}"
276290
277291
echo "➡️ Running tests with Perfetto profiling..."
278-
echo "::group::Running ctest with Perfetto"
279-
if ctest --progress --output-on-failure -j "$(nproc)"; then
280-
echo "::endgroup::"
292+
293+
# Set perf_event_paranoid for CPU profiling
294+
if [ "$PERFETTO_CPU_PROFILE" = "true" ]; then
295+
echo "Configuring perf_event_paranoid for CPU profiling"
296+
echo -1 | tee /proc/sys/kernel/perf_event_paranoid 2>/dev/null || echo "Warning: Could not set perf_event_paranoid"
297+
fi
298+
299+
# Configure profiling based on environment
300+
TRACEBOX_ARGS=""
301+
if [ "$PERFETTO_HEAP_PROFILE" = "true" ]; then
302+
echo "Enabling heap profiling"
303+
TRACEBOX_ARGS="$TRACEBOX_ARGS --app '*' --heapprofd"
304+
fi
305+
if [ "$PERFETTO_CPU_PROFILE" = "true" ]; then
306+
echo "Enabling CPU profiling"
307+
TRACEBOX_ARGS="$TRACEBOX_ARGS --cpu-freq --cpu-idle --cpu-sched"
308+
fi
309+
310+
# Run tests with or without tracebox wrapper
311+
if [ -n "$TRACEBOX_ARGS" ]; then
312+
echo "::group::Running ctest with tracebox"
313+
tracebox $TRACEBOX_ARGS -o perfetto-trace.pftrace -- ctest --progress --output-on-failure -j "$(nproc)" || TEST_RESULT=$?
314+
else
315+
echo "::group::Running ctest with Perfetto SDK tracing"
316+
ctest --progress --output-on-failure -j "$(nproc)" || TEST_RESULT=$?
317+
fi
318+
319+
echo "::endgroup::"
320+
if [ "${TEST_RESULT:-0}" -eq 0 ]; then
281321
echo "✅ Perfetto profiling completed."
282322
else
283-
echo "::endgroup::"
284323
echo "::error:: Perfetto profiling failed."
285324
exit 1
286325
fi

ci/Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ CLEAN_TEMP_FILES
286286
RUN <<'INSTALL_PERFETTO'
287287
set -euo pipefail
288288

289-
# Install Perfetto SDK
289+
# Install Perfetto SDK and tools
290290
apt-get update
291291
apt-get install -y --no-install-recommends \
292292
wget
@@ -298,6 +298,11 @@ cd /opt/perfetto
298298
wget -O perfetto.h https://raw.githubusercontent.com/google/perfetto/main/sdk/perfetto.h
299299
wget -O perfetto.cc https://raw.githubusercontent.com/google/perfetto/main/sdk/perfetto.cc
300300
chmod 644 perfetto.h perfetto.cc
301+
302+
# Install tracebox for system-wide profiling
303+
wget -O tracebox https://get.perfetto.dev/tracebox
304+
chmod +x tracebox
305+
mv tracebox /usr/local/bin/
301306
INSTALL_PERFETTO
302307

303308
########################################################################

0 commit comments

Comments
 (0)