#!/usr/bin/env bash set -euo pipefail # Build Google TCMalloc (gperftools) locally for LD_PRELOAD benchmarking. # # Output: # - deps/gperftools/install/lib/libtcmalloc.so (or libtcmalloc_minimal.so) # # Usage: # scripts/setup_tcmalloc_gperftools.sh # # Notes: # - This script does not change any build defaults in this repo. # - If your system already has libtcmalloc, you can skip building and just set # TCMALLOC_SO to that path when running allocator comparisons. root_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" deps_dir="${root_dir}/deps" src_dir="${deps_dir}/gperftools-src" install_dir="${deps_dir}/gperftools/install" mkdir -p "${deps_dir}" if command -v ldconfig >/dev/null 2>&1; then if ldconfig -p 2>/dev/null | rg -q "libtcmalloc(_minimal)?\\.so"; then echo "[tcmalloc] Found system tcmalloc via ldconfig:" ldconfig -p | rg "libtcmalloc(_minimal)?\\.so" | head echo "[tcmalloc] You can set TCMALLOC_SO to one of the above paths and skip local build." fi fi if [[ ! -d "${src_dir}/.git" ]]; then echo "[tcmalloc] Cloning gperftools into ${src_dir}" git clone --depth=1 https://github.com/gperftools/gperftools "${src_dir}" fi echo "[tcmalloc] Building gperftools (this may require autoconf/automake/libtool)" cd "${src_dir}" ./autogen.sh ./configure --prefix="${install_dir}" --disable-static make -j"$(nproc)" make install echo "[tcmalloc] Build complete." echo "[tcmalloc] Install dir: ${install_dir}" ls -la "${install_dir}/lib" | rg "libtcmalloc" || true echo "" echo "Next:" echo " export TCMALLOC_SO=\"${install_dir}/lib/libtcmalloc.so\"" echo " # or: ${install_dir}/lib/libtcmalloc_minimal.so" echo " scripts/bench_allocators_compare.sh --scenario mixed --iterations 50"