action.yml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. name: 'Show Cache Stats'
  2. description: 'Displays statistics for ccache and Bazel remote cache to help analyze cache performance and hit rates'
  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. ccache -s || true
  26. echo "====================="
  27. echo "=== ccache config ==="
  28. echo "====================="
  29. ccache -p || true
  30. echo "====================="
  31. STATS="$(ccache -s)"
  32. CACHEABLE=$(echo "$STATS" | awk '/Cacheable calls:/ {
  33. match($0, /[0-9]+/);
  34. print substr($0, RSTART, RLENGTH)
  35. }' | head -n1)
  36. HITS=$(echo "$STATS" | awk '/^[[:space:]]*Hits:/ {
  37. match($0, /[0-9]+/);
  38. print substr($0, RSTART, RLENGTH)
  39. }' | head -n1)
  40. DIRECT=$(echo "$STATS" | awk '/Direct:/ {
  41. match($0, /[0-9]+/);
  42. print substr($0, RSTART, RLENGTH)
  43. }' | head -n1)
  44. if [ "${CACHEABLE:-0}" -gt 0 ]; then
  45. HIT_RATE=$(awk -v h="${HITS:-0}" -v c="$CACHEABLE" 'BEGIN{printf "%.1f", (h/c)*100}')
  46. DIRECT_RATE=$(awk -v d="${DIRECT:-0}" -v c="$CACHEABLE" 'BEGIN{printf "%.1f", (d/c)*100}')
  47. else
  48. HIT_RATE="0.0"
  49. DIRECT_RATE="0.0"
  50. fi
  51. echo "hit_rate=${HIT_RATE}%"
  52. echo "direct_rate=${DIRECT_RATE}%"
  53. if [ "${{ inputs.clear_stats }}" = "true" ]; then
  54. echo "=== ccache reset ==="
  55. echo "====================="
  56. ccache -z || true
  57. echo "====================="
  58. else
  59. echo "Keeping ccache stats for next run"
  60. fi
  61. - name: Show ccache folder Stats
  62. shell: bash
  63. working-directory: ${{ github.workspace }}
  64. run: |
  65. set -euo pipefail
  66. echo "==============="
  67. echo "=== .ccache ==="
  68. echo "==============="
  69. du -sh /home/runner/.ccache || true
  70. ls -l /home/runner/.ccache || true
  71. echo "==============="
  72. - name: Show Bazel Cache folder Stats
  73. shell: bash
  74. working-directory: ${{ github.workspace }}
  75. run: |
  76. set -euo pipefail
  77. echo "===================="
  78. echo "=== .cache/bazel ==="
  79. echo "===================="
  80. du -sh /home/runner/.cache/bazel || true
  81. ls -l /home/runner/.cache/bazel || true
  82. echo "===================="
  83. - name: Show ld cache folder Stats
  84. shell: bash
  85. working-directory: ${{ github.workspace }}
  86. run: |
  87. set -euo pipefail
  88. echo "================="
  89. echo "=== .ld_cache ==="
  90. echo "================="
  91. du -sh /home/runner/.ld_cache || true
  92. ls -l /home/runner/.ld_cache || true
  93. echo "================="