|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: Apache-2.0 |
| 4 | + |
| 5 | +name: sccache summary |
| 6 | +description: Parse sccache stats JSON and write a summary table to GITHUB_STEP_SUMMARY |
| 7 | + |
| 8 | +# Inspired by NVIDIA/cccl's prepare-execution-summary.py (PR #3621). |
| 9 | +# Only counts C/C++ and CUDA language hits (excludes PTX/CUBIN which are |
| 10 | +# not included in sccache's compile_requests counter). |
| 11 | + |
| 12 | +inputs: |
| 13 | + json-file: |
| 14 | + description: "Path to the sccache stats JSON file (from sccache --show-stats --stats-format=json)" |
| 15 | + required: true |
| 16 | + label: |
| 17 | + description: "Label for the stats row (e.g. cuda.bindings, cuda.core)" |
| 18 | + required: false |
| 19 | + default: "sccache" |
| 20 | + build-step: |
| 21 | + description: "Name of the cibuildwheel build step (for deep-link in summary)" |
| 22 | + required: false |
| 23 | + default: "" |
| 24 | + |
| 25 | +runs: |
| 26 | + using: composite |
| 27 | + steps: |
| 28 | + - name: Report sccache stats |
| 29 | + shell: bash --noprofile --norc -euo pipefail {0} |
| 30 | + env: |
| 31 | + SCCACHE_JSON: ${{ inputs.json-file }} |
| 32 | + SCCACHE_LABEL: ${{ inputs.label }} |
| 33 | + SCCACHE_BUILD_STEP: ${{ inputs.build-step }} |
| 34 | + run: | |
| 35 | + if [ ! -f "$SCCACHE_JSON" ]; then |
| 36 | + echo "::warning::sccache stats file not found: $SCCACHE_JSON" |
| 37 | + exit 0 |
| 38 | + fi |
| 39 | +
|
| 40 | + python3 - <<'PYEOF' |
| 41 | + import json, os, urllib.parse |
| 42 | +
|
| 43 | + json_file = os.environ["SCCACHE_JSON"] |
| 44 | + label = os.environ["SCCACHE_LABEL"] |
| 45 | + build_step = os.environ.get("SCCACHE_BUILD_STEP", "") |
| 46 | +
|
| 47 | + with open(json_file) as f: |
| 48 | + stats = json.load(f)["stats"] |
| 49 | +
|
| 50 | + # compile_requests includes non-compilation calls (linker, etc). |
| 51 | + # Use cache_hits + cache_misses as the denominator to match sccache's |
| 52 | + # own "Cache hits rate" which only counts actual compilation requests. |
| 53 | + counted_languages = {"C/C++", "CUDA"} |
| 54 | + hits = sum( |
| 55 | + v for k, v in stats.get("cache_hits", {}).get("counts", {}).items() |
| 56 | + if k in counted_languages |
| 57 | + ) |
| 58 | + misses = sum( |
| 59 | + v for k, v in stats.get("cache_misses", {}).get("counts", {}).items() |
| 60 | + if k in counted_languages |
| 61 | + ) |
| 62 | + total = hits + misses |
| 63 | + pct = int(100 * hits / total) if total > 0 else 0 |
| 64 | +
|
| 65 | + # Build a deep-link to the cibuildwheel step if step name is provided. |
| 66 | + # GHA step summary links use the format: #step:N:L but we can't know the |
| 67 | + # step number here. Instead, link to the job page with a search hint. |
| 68 | + link_note = "" |
| 69 | + if build_step: |
| 70 | + link_note = f"\n\n_Full stats in the **{build_step}** step log._\n" |
| 71 | +
|
| 72 | + summary_file = os.environ.get("GITHUB_STEP_SUMMARY", "") |
| 73 | + if summary_file: |
| 74 | + with open(summary_file, "a") as sf: |
| 75 | + sf.write(f"### 📊 {label} — sccache stats\n") |
| 76 | + sf.write("| Hit Rate | Hits | Misses | Requests |\n") |
| 77 | + sf.write("|----------|------|--------|----------|\n") |
| 78 | + sf.write(f"| {pct}% | {hits} | {misses} | {total} |{link_note}\n") |
| 79 | +
|
| 80 | + print(f"{label}: {pct}% hit rate ({hits}/{total})") |
| 81 | + PYEOF |
0 commit comments