diff --git a/barretenberg/cpp/.gitignore b/barretenberg/cpp/.gitignore index 9a5226b72fac..811aef3620e6 100644 --- a/barretenberg/cpp/.gitignore +++ b/barretenberg/cpp/.gitignore @@ -8,4 +8,6 @@ CMakeUserPresets.json .vscode/settings.json # to be unignored when we agree on clang-tidy rules .clangd -acir_tests \ No newline at end of file +acir_tests +# we may download go in scripts/collect_heap_information.sh +go*.tar.gz diff --git a/barretenberg/cpp/CMakePresets.json b/barretenberg/cpp/CMakePresets.json index 7927b0ba494a..0174d8b873bc 100644 --- a/barretenberg/cpp/CMakePresets.json +++ b/barretenberg/cpp/CMakePresets.json @@ -147,6 +147,18 @@ "CMAKE_BUILD_TYPE": "Debug" } }, + { + "name": "gperftools", + "displayName": "Debugging build with gperftools on Clang-16", + "description": "Build with gperf", + "inherits": "clang16", + "binaryDir": "build-gperftools", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "CMAKE_EXE_LINKER_FLAGS": "-ltcmalloc", + "CXXFLAGS": "-fno-omit-frame-pointer" + } + }, { "name": "wasm", "displayName": "Build for WASM", @@ -283,6 +295,11 @@ "inherits": "clang16", "configurePreset": "fuzzing" }, + { + "name": "gperftools", + "inherits": "clang16", + "configurePreset": "gperftools" + }, { "name": "smt-verification", "inherits": "clang16", @@ -335,11 +352,6 @@ "name": "xray-1thread", "configurePreset": "xray-1thread", "inherits": "default" - }, - { - "name": "xray", - "configurePreset": "xray", - "inherits": "default" } ], "testPresets": [ diff --git a/barretenberg/cpp/scripts/collect_heap_information.sh b/barretenberg/cpp/scripts/collect_heap_information.sh new file mode 100755 index 000000000000..1d25c5a791c4 --- /dev/null +++ b/barretenberg/cpp/scripts/collect_heap_information.sh @@ -0,0 +1,47 @@ +#!/bin/bash +set -eu + +PRESET=gperftools +ONLY_PROCESS=${1:-} +EXECUTABLE=${2:-ultra_honk_rounds_bench} + +# Move above script dir. +cd $(dirname $0)/.. + +# Configure and build with heap profiling preset. + +cmake --preset $PRESET +cmake --build --preset $PRESET + +cd build-$PRESET + +if [ -z "$ONLY_PROCESS" ]; then + # Clear old heap profile data. + rm -f $EXECUTABLE.heap* + + # Run application with heap profiling to a file with prefix '$EXECUTABLE'. + HEAPPROFILE=./$EXECUTABLE ./bin/$EXECUTABLE +fi + +# Download and install Go +if [ ! -d ~/go ]; then + ARCHIVE=go1.21.3.linux-amd64.tar.gz + echo "Downloading and installing Go..." + wget https://go.dev/dl/$ARCHIVE + tar -C ~/ -xvf $ARCHIVE + rm $ARCHIVE + export PATH=$PATH:~/go/bin +fi + +# Install pprof +if [ ! -f ~/go/bin/pprof ]; then + echo "Installing pprof..." + ~/go/bin/go install github.com/google/pprof@latest +fi + +# Collect the heap files +files=(./$EXECUTABLE.*.heap) +# Find the middle index based on the count +middle_index=$(( (${#files[@]} + 1) / 2 - 1)) +# Process the heap profile with pprof +~/go/bin/pprof --text ./bin/$EXECUTABLE ${files[$middle_index]}