-
Notifications
You must be signed in to change notification settings - Fork 623
Expand file tree
/
Copy pathdebug-bazel-cache.sh
More file actions
executable file
·47 lines (42 loc) · 1.37 KB
/
Copy pathdebug-bazel-cache.sh
File metadata and controls
executable file
·47 lines (42 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
# Debug bazel remote cache uploads/downloads per target.
#
# Usage:
# ./dev/debug-bazel-cache.sh build //...
# ./dev/debug-bazel-cache.sh test //pkg/cache:cache_test
# ./dev/debug-bazel-cache.sh build //svc/api:api
#
set -euo pipefail
EXEC_LOG="/tmp/bazel_exec_$$.json"
cleanup() {
rm -f "$EXEC_LOG"
}
trap cleanup EXIT
echo "Running: bazel $*"
bazel "$@" --execution_log_json_file="$EXEC_LOG"
echo ""
echo "=== Remote Cache Stats ==="
jq -rs '
def sum_sizes: [.[].digest.sizeBytes | tonumber] | if length == 0 then 0 else add end;
def to_mb: . / 1048576;
group_by(.targetLabel) |
map({
target: .[0].targetLabel,
up: ([.[] | select(.cacheHit == false) | .actualOutputs[]] | sum_sizes | to_mb | floor),
down: ([.[] | select(.cacheHit == true) | .actualOutputs[]] | sum_sizes | to_mb | floor)
}) |
map(select(.up > 1 or .down > 1)) |
sort_by(-.up - .down) |
.[] |
"\(.target)\t↑\(.up)MB\t↓\(.down)MB"
' "$EXEC_LOG" | column -t -s $'\t'
echo ""
jq -rs '
def sum_sizes: [.[].digest.sizeBytes | tonumber] | if length == 0 then 0 else add end;
def to_mb: . / 1048576;
{
uploaded: ([.[] | select(.cacheHit == false) | .actualOutputs[]] | sum_sizes | to_mb),
downloaded: ([.[] | select(.cacheHit == true) | .actualOutputs[]] | sum_sizes | to_mb)
} |
"Total: ↑\(.uploaded | floor)MB ↓\(.downloaded | floor)MB"
' "$EXEC_LOG"