mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-03-14 20:27:24 +00:00
Fix sccache checks when running locally. (#268)
This commit is contained in:
@@ -1,21 +1,26 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script prints the sccache hit rate between two calls to sccache --show-stats.
|
||||
# It should be sourced in your script before and after the operations you want to profile,
|
||||
# with the 'start' or 'end' argument respectively.
|
||||
# It must be sourced. Exits with an error if executed directly.
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
|
||||
echo "Error: ci/sccache_stats.sh must be sourced, not executed."
|
||||
echo "Usage: source ci/sccache_stats.sh {start|end}"
|
||||
exit 2
|
||||
fi
|
||||
|
||||
mode=$1
|
||||
|
||||
if [[ "$mode" != "start" && "$mode" != "end" ]]; then
|
||||
echo "Invalid mode: $mode"
|
||||
echo "Usage: $0 {start|end}"
|
||||
exit 1
|
||||
echo "Usage: source ${BASH_SOURCE[0]} {start|end}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check if sccache is available
|
||||
if ! command -v sccache &> /dev/null; then
|
||||
echo "Notice: sccache is not available. Skipping..."
|
||||
exit 0
|
||||
return 0
|
||||
fi
|
||||
|
||||
case $mode in
|
||||
@@ -26,7 +31,7 @@ case $mode in
|
||||
end)
|
||||
if [[ -z ${SCCACHE_START_HITS+x} || -z ${SCCACHE_START_MISSES+x} ]]; then
|
||||
echo "Error: start stats not collected. Did you call this script with 'start' before your operations?"
|
||||
exit 1
|
||||
return 1
|
||||
fi
|
||||
|
||||
final_hits=$(sccache --show-stats | awk '/^[ \t]*Cache hits[ \t]+[0-9]+/ {print $3}')
|
||||
@@ -35,16 +40,11 @@ case $mode in
|
||||
misses=$((final_misses - SCCACHE_START_MISSES))
|
||||
total=$((hits + misses))
|
||||
|
||||
prefix=""
|
||||
if [ ${GITHUB_ACTIONS:-false} = "true" ]; then
|
||||
prefix="::notice::"
|
||||
fi
|
||||
|
||||
if (( total > 0 )); then
|
||||
hit_rate=$(awk -v hits="$hits" -v total="$total" 'BEGIN { printf "%.2f", (hits / total) * 100 }')
|
||||
echo ${prefix}"sccache hits: $hits | misses: $misses | hit rate: $hit_rate%"
|
||||
echo "sccache hits: $hits | misses: $misses | hit rate: $hit_rate%"
|
||||
else
|
||||
echo ${prefix}"sccache stats: N/A No new compilation requests"
|
||||
echo "sccache stats: N/A No new compilation requests"
|
||||
fi
|
||||
unset SCCACHE_START_HITS
|
||||
unset SCCACHE_START_MISSES
|
||||
|
||||
Reference in New Issue
Block a user