Team Ai
Modelpublic

Felipe97/llama-cpp-compiled

sourceHugging Faceupdated 21d agoView on Hugging Face
0likes1.2kdownloads
build-profile.sh123 linesDownload Raw Back to scripts
1#!/usr/bin/env bash2# Compile-time profiling using clang -ftime-trace + ClangBuildAnalyzer.3#4# Usage:5#   ./scripts/build-profile.sh [--full] [-jN]6#7# --full: include Server, Tools, and Tests (default: minimal build)8# -jN   :  number of parallel jobs (default: all cores)9#10# Requires ClangBuildAnalyzer:11#   macOS: brew install clang-build-analyzer12#   Linux: https://github.com/aras-p/ClangBuildAnalyzer.git13 14set -euo pipefail15 16SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"17ROOT_DIR="$(cd "${SCRIPT_DIR}/.." && pwd)"18 19FULL=020JOBS="-j$(nproc 2>/dev/null || sysctl -n hw.ncpu)"21 22for arg in "$@"; do23    case "${arg}" in24        --full) FULL=1 ;;25        -j*)    JOBS="${arg}" ;;26        *) echo "error: unknown argument: ${arg}" >&2; exit 1 ;;27    esac28done29 30if [ "${FULL}" -eq 1 ]; then31    BUILD_DIR="${ROOT_DIR}/build-profile-full"32    REPORT="${BUILD_DIR}/profile-report-full.txt"33else34    BUILD_DIR="${ROOT_DIR}/build-profile-baseline"35    REPORT="${BUILD_DIR}/profile-report.txt"36fi37 38OUTPUT_BIN="${BUILD_DIR}/clang_analysis.bin"39 40if ! command -v clang++ &>/dev/null; then41    echo "error: clang++ not found" >&242    exit 143fi44 45if ! command -v ClangBuildAnalyzer &>/dev/null; then46    echo "error: ClangBuildAnalyzer not found" >&247    echo "  brew install clangbuildanalyzer  (macOS)" >&248    echo "  or: https://github.com/aras-p/ClangBuildAnalyzer/releases" >&249    exit 150fi51 52CLANG_VER=$(clang++ --version | head -1)53echo "compiler : ${CLANG_VER}"54echo "build dir: ${BUILD_DIR}"55echo "output   : ${OUTPUT_BIN}"56echo "jobs     : ${JOBS}"57echo58 59if command -v ccache &>/dev/null; then60    echo "clearing ccache..."61    ccache -C -z62fi63 64export CCACHE_DISABLE=165 66cmake --fresh \67    -S "${ROOT_DIR}" \68    -B "${BUILD_DIR}" \69    -DCMAKE_BUILD_TYPE=Release \70    -DCMAKE_C_COMPILER=clang \71    -DCMAKE_CXX_COMPILER=clang++ \72    -DCMAKE_C_FLAGS="-ftime-trace" \73    -DCMAKE_CXX_FLAGS="-ftime-trace" \74    -DGGML_CCACHE=OFF \75    -DGGML_OPENMP=ON \76    -DGGML_NATIVE=OFF \77    -DLLAMA_BUILD_TESTS=$([ "${FULL}" -eq 1 ] && echo ON || echo OFF) \78    -DLLAMA_BUILD_EXAMPLES=OFF \79    -DLLAMA_BUILD_TOOLS=$([ "${FULL}" -eq 1 ] && echo ON || echo OFF) \80    -DLLAMA_BUILD_SERVER=$([ "${FULL}" -eq 1 ] && echo ON || echo OFF) \81    -DLLAMA_BUILD_APP=OFF82 83echo84 85echo "Initializing ClangBuildAnalyzer..."86ClangBuildAnalyzer --start "${BUILD_DIR}"87echo88 89echo "building..."90echo91 92START=$(date +%s)93 94cmake --build "${BUILD_DIR}" --clean-first "${JOBS}"95 96END=$(date +%s)97ELAPSED=$((END - START))98 99echo100printf "build time: %ds (%dm %ds)\n" "${ELAPSED}" "$((ELAPSED / 60))" "$((ELAPSED % 60))"101echo102 103echo "Aggregating profile metrics..."104ClangBuildAnalyzer --stop "${BUILD_DIR}" "${OUTPUT_BIN}" > /dev/null105 106echo107echo "================================================================================"108TUS=$(grep -oP "Compilation \(\K[0-9]+" "${REPORT}" 2>/dev/null || echo "?")109ClangBuildAnalyzer --analyze "${OUTPUT_BIN}" | tee "${REPORT}"110 111echo112echo "translation units: ${TUS}"113echo114echo "largest trace files (top 20 by size):"115find "${BUILD_DIR}" -name "*.json" ! -name "compile_commands.json" \116    | xargs ls -l 2>/dev/null \117    | awk 'NF>5 {print $5, $NF}' \118    | sort -rn \119    | awk 'NR<=20 {printf "%8.1f KB  %s\n", $1/1024, $2}'120 121echo122echo "ClangBuildAnalyzer report was generated: ${REPORT}"123