Ver código fonte

fix(action): enhance cache restoration outputs with size and hit information

Co-authored-by: Copilot <copilot@github.com>
TheWildJames 4 meses atrás
pai
commit
5928651977
2 arquivos alterados com 78 adições e 2 exclusões
  1. 21 0
      .github/actions/restore-cache/action.yml
  2. 57 2
      .github/workflows/build.yml

+ 21 - 0
.github/actions/restore-cache/action.yml

@@ -25,10 +25,22 @@ inputs:
     type: number
     default: 6
 
+outputs:
+  cache-hit:
+    description: 'Returns "true" if cache was found and restored, "false" otherwise'
+    value: ${{ steps.restore.outputs.cache-hit }}
+  cache-key:
+    description: 'The key that matched (primary or fallback)'
+    value: ${{ steps.restore.outputs.cache-key }}
+  cache-size:
+    description: 'Size of restored cache in human-readable format'
+    value: ${{ steps.restore.outputs.cache-size }}
+
 runs:
   using: 'composite'
   steps:
     - name: Detect and Download Cache
+      id: restore
       shell: bash
       working-directory: ${{ github.workspace }}
       env:
@@ -158,10 +170,19 @@ runs:
             fi
             echo "✅ Restore complete."
             echo "::endgroup::"
+            
+            # Output cache hit information
+            CACHE_SIZE=$(du -sh "${{ inputs.cache_path }}" 2>/dev/null | awk '{print $1}' || echo "unknown")
+            echo "cache-hit=true" >> $GITHUB_OUTPUT
+            echo "cache-key=$KEY" >> $GITHUB_OUTPUT
+            echo "cache-size=$CACHE_SIZE" >> $GITHUB_OUTPUT
             break
           done <<< "$SEARCH_LIST"
           
           if [ "$FOUND" = "false" ]; then
               echo "⚠️ No cache matches found. Proceeding with fresh run."
+              echo "cache-hit=false" >> $GITHUB_OUTPUT
+              echo "cache-key=none" >> $GITHUB_OUTPUT
+              echo "cache-size=0B" >> $GITHUB_OUTPUT
           fi
         fi

+ 57 - 2
.github/workflows/build.yml

@@ -188,7 +188,8 @@ jobs:
         grep -n 'vm_flags_clear' ${{ github.workspace }}/kernel/common/mm/mmap.c || echo 'Not found'
 
 
-    - name: Restore build caches (ccache, Bazel)
+    - name: Restore build caches (ccache)
+      id: restore-ccache
       uses: ./.github/actions/restore-cache
       with:
         cache_path: ${{ github.workspace }}/.ccache
@@ -198,7 +199,16 @@ jobs:
         restore_keys: |
           buildcache-
 
-    - name: Restore build caches (ccache, Bazel)
+    - name: Check ccache hit
+      run: |
+        if [ "${{ steps.restore-ccache.outputs.cache-hit }}" = "true" ]; then
+          echo "✅ ccache HIT - Key: ${{ steps.restore-ccache.outputs.cache-key }} - Size: ${{ steps.restore-ccache.outputs.cache-size }}"
+        else
+          echo "❌ ccache MISS - Fresh build"
+        fi
+
+    - name: Restore build caches (LTO/ld_cache)
+      id: restore-ldcache
       uses: ./.github/actions/restore-cache
       with:
         cache_path: ${{ github.workspace }}/.ld_cache
@@ -208,12 +218,57 @@ jobs:
         restore_keys: |
           buildcache-
 
+    - name: Check ld_cache hit
+      run: |
+        if [ "${{ steps.restore-ldcache.outputs.cache-hit }}" = "true" ]; then
+          echo "✅ ld_cache HIT - Key: ${{ steps.restore-ldcache.outputs.cache-key }} - Size: ${{ steps.restore-ldcache.outputs.cache-size }}"
+        else
+          echo "❌ ld_cache MISS - Fresh build"
+        fi
+
+    - name: Pre-build cache stats
+      id: pre-cache-stats
+      run: |
+        set -euo pipefail
+        stats=$(ccache -s || true)
+        pre_hits=$(echo "$stats" | awk '/cache hit/ {h+=$NF} END{print (h+0)}')
+        pre_misses=$(echo "$stats" | awk '/cache miss/ {m+=$NF} END{print (m+0)}')
+        echo "pre_hits=$pre_hits" >> $GITHUB_OUTPUT
+        echo "pre_misses=$pre_misses" >> $GITHUB_OUTPUT
+        pre_ld_size=$(du -sh "$GITHUB_WORKSPACE/.ld_cache" 2>/dev/null | awk '{print $1}' || echo "0B")
+        pre_ld_files=$(find "$GITHUB_WORKSPACE/.ld_cache" -type f 2>/dev/null | wc -l || true)
+        echo "pre_ld_size=$pre_ld_size" >> $GITHUB_OUTPUT
+        echo "pre_ld_files=$pre_ld_files" >> $GITHUB_OUTPUT
+
     - name: Build Kernel
       env:
         SOURCE_DATE_EPOCH: ${{ env.SOURCE_DATE_EPOCH }}
         KBUILD_BUILD_TIMESTAMP: ${{ env.KBUILD_BUILD_TIMESTAMP }}
       uses: ./.github/actions/build-kernel
 
+    - name: Post-build cache stats
+      id: post-cache-stats
+      run: |
+        set -euo pipefail
+        stats=$(ccache -s || true)
+        post_hits=$(echo "$stats" | awk '/cache hit/ {h+=$NF} END{print (h+0)}')
+        post_misses=$(echo "$stats" | awk '/cache miss/ {m+=$NF} END{print (m+0)}')
+        pre_hits=${{ steps.pre-cache-stats.outputs.pre_hits }}
+        pre_misses=${{ steps.pre-cache-stats.outputs.pre_misses }}
+        delta_hits=$((post_hits - pre_hits)) || true
+        delta_misses=$((post_misses - pre_misses)) || true
+        delta_total=$((delta_hits + delta_misses))
+        if [ "$delta_total" -gt 0 ]; then
+          percent=$(( delta_hits * 100 / delta_total ))
+          echo "ccache hit during build: ${percent}% (${delta_hits} hits / ${delta_total} accesses)"
+        else
+          echo "No compiler activity detected (no ccache accesses)."
+        fi
+        post_ld_size=$(du -sh "$GITHUB_WORKSPACE/.ld_cache" 2>/dev/null | awk '{print $1}' || echo "0B")
+        post_ld_files=$(find "$GITHUB_WORKSPACE/.ld_cache" -type f 2>/dev/null | wc -l || true)
+        echo "ld_cache size before: ${{ steps.pre-cache-stats.outputs.pre_ld_size }}, after: $post_ld_size"
+        echo "ld_cache files before: ${{ steps.pre-cache-stats.outputs.pre_ld_files }}, after: $post_ld_files"
+
     - name: List cache contents
       working-directory: ${{ github.workspace }}
       run: |