From 4e04bbc343e59a6107b1e0a93eb4f2c53c39f368 Mon Sep 17 00:00:00 2001 From: Andrei Radulescu Date: Wed, 4 Sep 2024 07:35:40 +0300 Subject: [PATCH] agnos rootfs statistics in CI (#291) * agnos rootfs statistics in CI * rebuild * wip * minimal stats * agnos stats in PR comment * just the folders * just stats * raw image is now just image * fix printing stats when no [upload] * this is nicer [upload] --- .github/workflows/build.yaml | 12 ++++++++- .github/workflows/push-and-comment.yaml | 15 ++++++++++- scripts/analyze-agnos-rootfs.sh | 35 +++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100755 scripts/analyze-agnos-rootfs.sh diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index bdf7afc..c829310 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -58,6 +58,15 @@ jobs: - name: Build system run: ./build_system.sh + - name: Statistics + id: stats + run: | + { + echo 'stats_summary<> $GITHUB_OUTPUT + - name: Package and OTA push if: "contains(env.LAST_COMMIT_MESSAGE, '[upload]')" env: @@ -65,11 +74,12 @@ jobs: run: | scripts/package_ota.py - - name: Save PR number and VERSION + - name: Save PR number, VERSION and stats if: "contains(env.LAST_COMMIT_MESSAGE, '[upload]')" run: | echo ${{ github.event.number }} > output/ota/PR cp VERSION output/ota + echo "${{ steps.stats.outputs.stats_summary }}" > output/ota/agnos_stats.txt - name: Upload artifacts if: "contains(env.LAST_COMMIT_MESSAGE, '[upload]')" diff --git a/.github/workflows/push-and-comment.yaml b/.github/workflows/push-and-comment.yaml index 78382d2..a9fa2e6 100644 --- a/.github/workflows/push-and-comment.yaml +++ b/.github/workflows/push-and-comment.yaml @@ -59,7 +59,6 @@ jobs: git push origin agnos-builder/pr-${{ env.PR_NUMBER }} --force - name: List .xz files with links - id: list_xz working-directory: ${{ github.workspace }}/ci-artifacts run: | { @@ -70,6 +69,15 @@ jobs: echo EOF } >> $GITHUB_ENV + - name: Read agnos_stats.txt + working-directory: ${{ github.workspace }}/ci-artifacts + run: | + { + echo 'AGNOS_STATS<> $GITHUB_ENV + - name: Comment on PR uses: thollander/actions-comment-pull-request@fabd468d3a1a0b97feee5f6b9e499eab0dd903f6 with: @@ -82,6 +90,11 @@ jobs: ### Images: ${{ env.XZ_FILES }} + + ### Stats: + ``` + ${{ env.AGNOS_STATS }} + ``` pr_number: ${{ env.PR_NUMBER }} comment_tag: run_id mode: recreate diff --git a/scripts/analyze-agnos-rootfs.sh b/scripts/analyze-agnos-rootfs.sh new file mode 100755 index 0000000..07660c6 --- /dev/null +++ b/scripts/analyze-agnos-rootfs.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -e + +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null && pwd)" +cd $DIR + +BUILD_DIR="$DIR/build" +ROOTFS_DIR="$BUILD_DIR/agnos-rootfs" +ROOTFS_IMAGE="$BUILD_DIR/system.img" + +# Setup mount container for macOS and CI support (namespace.so) +docker build -f $DIR/Dockerfile.builder -t agnos-mount $DIR > /dev/null 2>&1 +MOUNT_CONTAINER_ID=$(docker run -d --privileged -v $DIR:$DIR agnos-mount) +exec() { + docker exec $MOUNT_CONTAINER_ID "$@" +} + +# Cleanup container on exit +trap "docker container rm -f $MOUNT_CONTAINER_ID > /dev/null" EXIT + +# Mount filesystem +exec mount "$ROOTFS_IMAGE" "$ROOTFS_DIR" + +# Stats +# echo "Total size:" +exec bash -c "du -sh \"$ROOTFS_DIR\" | sed 's|$ROOTFS_DIR|/|'" +# echo "Python env size:" +exec bash -c "du -sh -t 150M \"$ROOTFS_DIR\"/usr/local/* | sort -rh | sed 's|$ROOTFS_DIR||'" +# echo "Lib size:" +exec bash -c "du -sh -t 150M \"$ROOTFS_DIR\"/usr/lib/* | sort -rh | sed 's|$ROOTFS_DIR||'" +# echo "Others size:" +exec bash -c "find \"$ROOTFS_DIR/usr\" -mindepth 1 -maxdepth 1 -type d ! -path \"$ROOTFS_DIR/usr/local\" ! -path \"$ROOTFS_DIR/usr/lib\" -exec du -sh -t 150M {} + | sort -rh | sed 's|$ROOTFS_DIR||'" + +# Unmount image +exec umount -l "$ROOTFS_DIR"