Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/files/build-memory-sampler.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
# TEMP (WordPress/gutenberg#79889 measurement): sample memory every 2s until <pid> exits.
# Usage: build-memory-sampler.sh <pid> <output-dir>

root=$1
out=$2
mkdir -p "$out"
csv="$out/memory.csv"
echo "t,used_mb,swap_mb,tree_rss_mb,nproc" > "$csv"
start=$(date +%s)
peak=0

while kill -0 "$root" 2>/dev/null; do
snap=$(ps -eo pid=,ppid=,rss=,args=)
read -r used swap < <(awk '/^MemTotal:/{t=$2} /^MemAvailable:/{a=$2} /^SwapTotal:/{st=$2} /^SwapFree:/{sf=$2} END{printf "%d %d\n", (t-a)/1024, (st-sf)/1024}' /proc/meminfo)
tree=$(awk -v r="$root" '{p[NR]=$1; pp[NR]=$2; line[NR]=$0; n=NR}
END{inset[r]=1; c=1; while(c){c=0; for(i=1;i<=n;i++) if(!(p[i] in inset) && (pp[i] in inset)){inset[p[i]]=1; c=1}}
for(i=1;i<=n;i++) if(p[i] in inset) print line[i]}' <<<"$snap")
read -r rss nproc < <(awk '{s+=$3; k++} END{printf "%d %d\n", s/1024, k}' <<<"$tree")
echo "$(( $(date +%s) - start )),$used,$swap,$rss,$nproc" >> "$csv"
if [[ $rss -gt $peak ]]; then
peak=$rss
sort -k3 -rn <<<"$tree" | awk '{printf "%7d MB ", $3/1024; $1=$2=$3=""; print substr($0, 4, 200)}' > "$out/peak-processes.txt"
fi
sleep 2
done

awk -F, 'NR>1{ if($2>u)u=$2; if($3>s)s=$3; if($4>r){r=$4; rt=$1}; if($5>p)p=$5; sum+=$4; n++ }
END{ printf "| Peak system memory used | %d MB |\n| Peak swap used | %d MB |\n| Peak build-tree RSS | %d MB (at %ds) |\n| Mean build-tree RSS | %d MB |\n| Max build processes | %d |\n| Samples | %d |\n", u, s, r, rt, sum/n, p, n }' "$csv" > "$out/summary.md"
40 changes: 39 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,47 @@ jobs:
mkdir "$BUILD_BASE"
touch "$BUILD_BASE/mirrors.txt"
else
pnpm jetpack build -v --no-pnpm-install --for-mirrors="$BUILD_BASE" "${PROJECTS[@]}"
# TEMP (WordPress/gutenberg#79889 measurement): sample memory while building.
pnpm jetpack build -v --no-pnpm-install --for-mirrors="$BUILD_BASE" "${PROJECTS[@]}" &
BUILD_PID=$!
.github/files/build-memory-sampler.sh "$BUILD_PID" /tmp/build-memory &
SAMPLER_PID=$!
BUILD_RC=0
wait "$BUILD_PID" || BUILD_RC=$?
wait "$SAMPLER_PID"
exit "$BUILD_RC"
fi

- name: Report build memory
if: ${{ always() }}
env:
JOB_NAME: ${{ github.job }}
run: |
[[ -f /tmp/build-memory/summary.md ]] || exit 0
{
echo "### Build memory ($JOB_NAME, $(nproc) CPUs, $(awk '/MemTotal/{printf "%d", $2/1024}' /proc/meminfo) MB RAM) — $(grep -m1 'model name' /proc/cpuinfo | cut -d: -f2 | xargs)"
echo
echo "| Metric | Value |"
echo "| --- | --- |"
cat /tmp/build-memory/summary.md
echo
echo '<details><summary>Processes at peak build-tree RSS</summary>'
echo
echo '```'
head -40 /tmp/build-memory/peak-processes.txt
echo '```'
echo '</details>'
} | tee -a "$GITHUB_STEP_SUMMARY"

- name: Store build memory log
if: ${{ always() }}
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7
with:
name: build-memory-${{ github.job }}
path: /tmp/build-memory/
retention-days: 7
if-no-files-found: ignore

- name: Create archive
run: |
tar --owner=0 --group=0 --xz -cvvf "$FILENAME" -C "$BUILD_BASE" --transform 's,^\.,build,' .
Expand Down
Loading
Loading