action.yml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. name: 'Show ccache Stats'
  2. description: 'Display ccache statistics, hit rates, and config'
  3. inputs:
  4. clear_stats:
  5. description: 'Whether to clear ccache stats after displaying (default: true)'
  6. required: true
  7. type: boolean
  8. default: true
  9. runs:
  10. using: 'composite'
  11. steps:
  12. - name: Show ccache Stats
  13. shell: bash
  14. working-directory: ${{ github.workspace }}
  15. run: |
  16. set -euo pipefail
  17. echo "===================="
  18. echo "=== ccache stats ==="
  19. echo "===================="
  20. if ! command -v ccache >/dev/null 2>&1; then
  21. echo "⚠️ ccache not installed, skipping ccache stats"
  22. echo "===================="
  23. exit 0
  24. fi
  25. echo "=== ccache config ==="
  26. echo "====================="
  27. ccache -p || true
  28. echo "====================="
  29. STATS="$(ccache -s)"
  30. echo "$STATS"
  31. CACHEABLE=$(echo "$STATS" | awk '/Cacheable calls:/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH) }' | head -n1)
  32. HITS=$(echo "$STATS" | awk '/^[[:space:]]*Hits:/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH) }' | head -n1)
  33. DIRECT=$(echo "$STATS" | awk '/Direct:/ { match($0, /[0-9]+/); print substr($0, RSTART, RLENGTH) }' | head -n1)
  34. if [ "${CACHEABLE:-0}" -gt 0 ]; then
  35. HIT_RATE=$(awk -v h="${HITS:-0}" -v c="$CACHEABLE" 'BEGIN{printf "%.1f", (h/c)*100}')
  36. DIRECT_RATE=$(awk -v d="${DIRECT:-0}" -v c="$CACHEABLE" 'BEGIN{printf "%.1f", (d/c)*100}')
  37. echo "hit_rate=${HIT_RATE}%"
  38. echo "direct_rate=${DIRECT_RATE}%"
  39. else
  40. echo "hit_rate=0.0%"
  41. echo "direct_rate=0.0%"
  42. fi
  43. if [ "${{ inputs.clear_stats }}" = "true" ]; then
  44. echo "=== ccache reset ==="
  45. echo "====================="
  46. ccache -z || true
  47. echo "====================="
  48. if [ -d /home/runner/.ccache ] && find /home/runner/.ccache -type f -print -quit 2>/dev/null | grep -q .; then
  49. find /home/runner/.ccache -type f -exec touch -t $(date -d "1 day ago" +%Y%m%d%H%M) {} +
  50. echo "✅ ccache atime updated"
  51. fi
  52. fi