Skip to content

Commit

Permalink
ci: binary size regression job (#211)
Browse files Browse the repository at this point in the history
Signed-off-by: Jose Nino jnino@lyft.com

Description: this PR adds a CI job to test for relative size increases as well as absolute size of the test_binary_size target as a check on size for mobile platform constraints.
Risk Level: low - added new CI jobs.
Testing: CI. Also tested locally for failure messages.

Signed-off-by: JP Simard <jp@jpsim.com>
  • Loading branch information
junr03 authored and jpsim committed Nov 28, 2022
1 parent 7011112 commit 2be3d8d
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
70 changes: 70 additions & 0 deletions mobile/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,76 @@ stages:
- checkout: self
- script: ./ci/kotlin_lint.sh
displayName: 'Run Kotlin lint'
# Note: the size regression jobs are not ideal.
# The size analysis described in the docs was ran on arm64 machines.
# However, it seems that azure pipelines will support arm64 machines sometime soon.
# Whenever that is available this jobs should be moved to that architecture.
# Issue: https://github.com/lyft/envoy-mobile/issues/216
- stage: performance
dependsOn: [] # this removes the implicit dependency on previous stage and causes this to run in parallel.
jobs:
- job: size_current
timeoutInMinutes: 60
pool:
vmImage: 'Ubuntu 16.04'
steps:
- checkout: self
submodules: true
- script: ./ci/linux_ci_setup.sh
displayName: 'Install dependencies'
- script: bazel build //test/performance:test_binary_size --config=sizeopt
displayName: 'Build test binary'
- task: PublishPipelineArtifact@0
displayName: 'Publish current test binary'
inputs:
artifactName: 'current'
targetPath: bazel-bin/test/performance/test_binary_size
- job: size_master
timeoutInMinutes: 60
pool:
vmImage: 'Ubuntu 16.04'
steps:
- checkout: self
submodules: true
- script: git checkout master && git pull origin master
- script: ./ci/linux_ci_setup.sh
displayName: 'Install dependencies'
- script: bazel build //test/performance:test_binary_size --config=sizeopt
displayName: 'Build test binary'
- task: PublishPipelineArtifact@0
displayName: 'Publish master test binary'
inputs:
artifactName: 'master'
targetPath: bazel-bin/test/performance/test_binary_size
- job: size_compare
dependsOn:
- size_current
- size_master
timeoutInMinutes: 60
pool:
vmImage: 'Ubuntu 16.04'
steps:
- script: mkdir -p dist/master && mkdir -p dist/current
- script: ./ci/linux_ci_setup.sh
displayName: 'Install dependencies'
- task: DownloadPipelineArtifact@0
displayName: 'Download current test binary'
inputs:
artifactName: 'current'
targetPath: dist/current
- task: DownloadPipelineArtifact@0
displayName: 'Download master test binary'
inputs:
artifactName: 'master'
targetPath: dist/master
- script: |
strip -s -o dist/master/test_binary_size.stripped dist/master/test_binary_size
strip -s -o dist/current/test_binary_size.stripped dist/current/test_binary_size
zip -9 dist/master.zip dist/master/test_binary_size.stripped
zip -9 dist/current.zip dist/current/test_binary_size.stripped
displayName: 'Strip and Zip binary'
- script: ./ci/test_size_regression.sh dist/master.zip dist/current.zip
displayName: 'Test size regression'
- stage: android
dependsOn: [] # this removes the implicit dependency on previous stage and causes this to run in parallel.
jobs:
Expand Down
30 changes: 30 additions & 0 deletions mobile/ci/test_size_regression.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

# Checks the absolute size, and the relative increase of a file.
MAX_SIZE=4000000
MAX_PERC=1

if [ `uname` == "Darwin" ]
then
SIZE1=$(stat -f "%z" "$1")
SIZE2=$(stat -f "%z" "$2")
else
SIZE1=$(stat -c "%s" "$1")
SIZE2=$(stat -c "%s" "$2")
fi
PERC=$(bc <<< "scale=2; ($SIZE2 - $SIZE1)/$SIZE1 * 100")

echo "The new binary is $PERC % different in size compared to master."
echo "The new binary is $SIZE2 bytes."

if [ $SIZE2 -gt $MAX_SIZE ]
then
echo "The current size ($SIZE2) is larger than the maximum size ($MAX_SIZE)."
exit 1
fi

if [ $(bc <<< "scale=2; $PERC >= $MAX_PERC") -eq 1 ]
then
echo "The percentage increase ($PERC) is larger then the maximum percentage increase ($MAX_PERC)."
exit 1
fi

0 comments on commit 2be3d8d

Please sign in to comment.