-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
[build] monitor disk and cache usage throughout a bazel job #17569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
69e8f64
[build] monitor disk and cache usage throughout a bazel job
titusfortner 0eb8885
needs android
titusfortner 2fbe461
make it not need android
titusfortner 4b6d4ab
fix cache size reporting
titusfortner 962cb10
use MB
titusfortner bebf1b5
[build] harden disk cleanup scripts against empty paths and rounding
titusfortner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #!/usr/bin/env bash | ||
| # | ||
| # Print a disk-status snapshot for use as a CI checkpoint: | ||
| # Also exports AVAIL_GB (available space in GB | ||
|
|
||
| echo "=== Disk space ===" | ||
| df -h "$GITHUB_WORKSPACE" || true | ||
| if [[ "$RUNNER_OS" == "Windows" ]]; then df -h /c || true; fi | ||
|
|
||
| # On Windows the workspace is on D: but C: is the constrained drive | ||
| if [[ "$RUNNER_OS" == "Windows" ]]; then | ||
| AVAIL_GB=$(df -k /c | awk 'NR==2 {printf "%.0f", $4/1024/1024}') | ||
| else | ||
| AVAIL_GB=$(df -k "$GITHUB_WORKSPACE" | awk 'NR==2 {printf "%.0f", $4/1024/1024}') | ||
| fi | ||
| if ! [[ "$AVAIL_GB" =~ ^[0-9]+$ ]]; then | ||
| echo "::error::Could not determine available disk space (got: '${AVAIL_GB}')" | ||
| AVAIL_GB=0 | ||
| fi | ||
| export AVAIL_GB | ||
| echo "Available: ${AVAIL_GB}GB" | ||
|
|
||
| if [[ "$RUNNER_OS" == "Windows" ]]; then | ||
| external="/d/b/external" | ||
| repos="/d/b-repo" | ||
| bazelisk="/c/Users/runneradmin/AppData/Local/bazelisk" | ||
| else | ||
| external="$HOME/.bazel/external" | ||
| repos="$HOME/.cache/bazel-repo" | ||
| bazelisk="$HOME/.cache/bazelisk" | ||
| fi | ||
|
|
||
| echo "=== Bazel cache sizes ===" | ||
| cache_size() { | ||
| local label="$1" path="$2" | ||
| if [ -d "$path" ]; then | ||
| local size | ||
| size=$(du -sh "$path" 2>/dev/null | awk '{print $1}') | ||
| printf " %-25s %s\n" "${label}:" "$size" | ||
| else | ||
| printf " %-25s (not present)\n" "${label}:" | ||
| fi | ||
| } | ||
| cache_size "External" "$external" | ||
| if [ -d "$repos" ]; then | ||
| for sub in "$repos"/*/; do | ||
| [ -d "$sub" ] || continue | ||
| case "$(basename "$sub")" in | ||
| content_addressable) label="Repository Cache" ;; | ||
| contents) label="Repo Contents Cache" ;; | ||
| *) label="Repository/$(basename "$sub")" ;; | ||
| esac | ||
| cache_size "$label" "$sub" | ||
| done | ||
| else | ||
| cache_size "Repository Cache" "$repos" | ||
| fi | ||
| cache_size "Bazelisk" "$bazelisk" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| #!/usr/bin/env pwsh | ||
|
|
||
| function FreeBytes { (Get-PSDrive C).Free } | ||
|
|
||
| function Clean($Label, $Path) { | ||
| if (-not $Path) { | ||
| "{0} {1,-13} (path not set, skipping)" -f (Get-Date -Format HH:mm:ss), $Label | ||
| return | ||
| } | ||
| $before = FreeBytes | ||
| $t0 = Get-Date | ||
| Remove-Item -Path $Path -Recurse -Force -ErrorAction SilentlyContinue | ||
| $after = FreeBytes | ||
| $duration = [math]::Round((Get-Date).Subtract($t0).TotalSeconds, 0) | ||
| $freedMB = [math]::Round(($after - $before) / 1MB, 0) | ||
| "{0} {1,-13} {2,3}s {3,5}GB -> {4,5}GB free (freed {5}MB)" -f ` | ||
| (Get-Date -Format HH:mm:ss), $Label, $duration, ` | ||
| [math]::Round($before/1GB, 1), [math]::Round($after/1GB, 1), $freedMB | ||
| } | ||
|
|
||
| Write-Host "=== Disk before cleanup ===" | ||
| Get-PSDrive C, D | Format-Table -AutoSize | Out-String | Write-Host | ||
| Write-Host | ||
| Write-Host "=== Per-step delete (time + free-space delta on C:) ===" | ||
|
|
||
| # Pre-installed language toolchains | ||
| Clean "miniconda" "C:\Miniconda" | ||
| Clean "ghc" "C:\tools\ghc" | ||
| Clean "llvm" "C:\Program Files\LLVM" | ||
| Clean "postgres" "C:\Program Files\PostgreSQL" | ||
| Clean "mongo" "C:\Program Files\MongoDB" | ||
| Clean "mysql" "C:\Program Files\MySQL" | ||
|
|
||
| # WebDriver binaries (Selenium tests use bazel-pinned drivers) | ||
| Clean "chromedriver" $env:ChromeWebDriver | ||
| Clean "edgedriver" $env:EdgeWebDriver | ||
| Clean "geckodriver" $env:GeckoWebDriver | ||
|
|
||
| Write-Host | ||
| Write-Host "=== Disk after cleanup ===" | ||
| Get-PSDrive C, D | Format-Table -AutoSize | Out-String | Write-Host |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -u | ||
|
|
||
| free_mb() { df -BM / | awk 'NR==2 {print $4}' | tr -d 'M'; } | ||
|
|
||
| clean() { | ||
| local label="$1" path="$2" | ||
| local before after t0 | ||
| if [ -z "$path" ]; then | ||
| printf "%s %-13s (path not set, skipping)\n" "$(date +%T)" "$label" | ||
| return | ||
| fi | ||
| before=$(free_mb) | ||
| t0=$SECONDS | ||
| # shellcheck disable=SC2086 # intentional word-split for globs (julia*) | ||
| sudo rm -rf -- $path | ||
| after=$(free_mb) | ||
| printf "%s %-13s %3ds %3sG -> %3sG free (freed %sM)\n" \ | ||
| "$(date +%T)" "$label" "$((SECONDS - t0))" \ | ||
| "$((before / 1024))" "$((after / 1024))" "$((after - before))" | ||
| } | ||
|
|
||
| echo "=== Disk before cleanup ===" | ||
| df -h / | ||
| echo | ||
| echo "=== Per-step delete (time + free-space delta) ===" | ||
|
|
||
| # Pre-installed language toolchains | ||
| clean ghc /opt/ghc | ||
| clean ghcup /usr/local/.ghcup | ||
| clean boost /usr/local/share/boost | ||
| clean swift /usr/share/swift | ||
| clean julia '/usr/local/julia*' | ||
| clean gcloud-sdk /usr/lib/google-cloud-sdk | ||
| clean codeql /opt/hostedtoolcache/CodeQL | ||
|
|
||
| # App SDKs that Selenium has no binding for | ||
| clean android /usr/local/lib/android | ||
| clean dotnet /usr/share/dotnet | ||
| clean graalvm /usr/local/graalvm | ||
| clean powershell /usr/local/share/powershell | ||
|
|
||
| # WebDriver binaries (Selenium tests use bazel-pinned drivers) | ||
| clean chromedriver "${CHROMEWEBDRIVER:-}" | ||
| clean edgedriver "${EDGEWEBDRIVER:-}" | ||
| clean geckodriver "${GECKOWEBDRIVER:-}" | ||
|
|
||
| # Docker images pre-pulled by the runner image | ||
| before=$(free_mb); t0=$SECONDS | ||
| docker image prune -af >/dev/null 2>&1 || true | ||
| after=$(free_mb) | ||
| printf "%s %-13s %3ds %3sG -> %3sG free (freed %sM)\n" \ | ||
| "$(date +%T)" "docker-images" "$((SECONDS - t0))" \ | ||
| "$((before / 1024))" "$((after / 1024))" "$((after - before))" | ||
|
|
||
| sync | ||
|
|
||
| echo | ||
| echo "=== Disk after cleanup ===" | ||
| df -h / |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.