| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- name: 'Show ccache Stats'
- description: 'Display ccache statistics, hit rates, and config'
- inputs:
- clear_stats:
- description: 'Whether to clear ccache stats after displaying (default: true)'
- required: true
- type: boolean
- default: true
- runs:
- using: 'composite'
- steps:
- - name: Show ccache Stats
- shell: bash
- working-directory: ${{ github.workspace }}
- run: |
- set -euo pipefail
- echo "===================="
- echo "=== ccache stats ==="
- echo "===================="
- if ! command -v ccache >/dev/null 2>&1; then
- echo "⚠️ ccache not installed, skipping ccache stats"
- echo "===================="
- exit 0
- fi
- echo "=== ccache config ==="
- echo "====================="
- ccache -p || true
- echo "====================="
- STATS="$(ccache -s)"
- echo "$STATS"
- CACHEABLE=$(echo "$STATS" | awk '/Cacheable calls:/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH) }' | head -n1)
- HITS=$(echo "$STATS" | awk '/^[[:space:]]*Hits:/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH) }' | head -n1)
- DIRECT=$(echo "$STATS" | awk '/Direct:/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH) }' | head -n1)
- if [ "${CACHEABLE:-0}" -gt 0 ]; then
- HIT_RATE=$(awk -v h="${HITS:-0}" -v c="$CACHEABLE" 'BEGIN{printf "%.1f", (h/c)*100}')
- DIRECT_RATE=$(awk -v d="${DIRECT:-0}" -v c="$CACHEABLE" 'BEGIN{printf "%.1f", (d/c)*100}')
- echo "hit_rate=${HIT_RATE}%"
- echo "direct_rate=${DIRECT_RATE}%"
- else
- echo "hit_rate=0.0%"
- echo "direct_rate=0.0%"
- fi
- if [ "${{ inputs.clear_stats }}" = "true" ]; then
- echo "=== ccache reset ==="
- echo "====================="
- ccache -z || true
- echo "====================="
- if [ -d /home/runner/.ccache ] && find /home/runner/.ccache -type f -print -quit 2>/dev/null | grep -q .; then
- find /home/runner/.ccache -type f -exec touch -t $(date -d "1 day ago" +%Y%m%d%H%M) {} +
- echo "✅ ccache atime updated"
- fi
- fi
|