action.yml 3.2 KB

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