Skip to content
Draft
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
9 changes: 9 additions & 0 deletions .github/actions/build/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ runs:
TARGETS=$(echo "${TARGETS_JSON}" | jq -cr '. | join(" ")')
time autoninja -C out/${{ matrix.platform }}_${{ matrix.config }} ${TARGETS}
shell: bash
- name: Archive Evergreen ARM Size Artifacts
if: startsWith(matrix.platform, 'evergreen-arm') && matrix.config == 'gold'
uses: actions/upload-artifact@v4
with:
name: size_artifacts_${{ matrix.platform }}_${{ matrix.config }}
path: |
src/out/${{ matrix.platform }}_${{ matrix.config }}/bin
src/out/${{ matrix.platform }}_${{ matrix.config }}/sizes
src/out/${{ matrix.platform }}_${{ matrix.config }}/libcobalt.so
- name: Archive Android APKs
if: startsWith(matrix.platform, 'android') && matrix.config == 'qa'
uses: actions/upload-artifact@v4
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ jobs:
cobalt/build
cobalt/docker
cobalt/testing/filters
cobalt/testing/tools
cobalt/tools
tools/binary_size
docker-compose.yaml
- name: Remove runtest if exists
if: github.event_name == 'pull_request'
Expand Down Expand Up @@ -338,6 +340,36 @@ jobs:
uses: ./src/.github/actions/api_leak_detector
if: inputs.run_api_leak_detector

check_binary_size:
needs: [initialize, build]
runs-on: [self-hosted, chrobalt-linux-runner]
name: Check Binary Sizes
if: startsWith(inputs.platform, 'evergreen-arm') && contains(fromJson(needs.initialize.outputs.build_configs), 'gold')
steps:
- name: Checkout
uses: actions/checkout@v4
with:
path: src
fetch-depth: 1
ref: ${{ github.event.pull_request.head.sha }}
- name: Set Up Depot Tools
uses: ./src/.github/actions/depot_tools
- name: Download all size artifacts
uses: actions/download-artifact@v4
with:
pattern: size_artifacts_evergreen-arm-*_gold
path: size_artifacts

- name: Move size artifacts
run: mv size_artifacts src/
shell: bash

- name: Process size artifacts
run: |
cd src
cobalt/testing/tools/process_size_artifacts.sh
shell: bash

on-device-test:
needs: [initialize, build]
if: |
Expand Down
17 changes: 17 additions & 0 deletions cobalt/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import("//build/linux/strip_binary.gni")
import("//cobalt/build/modular_executable.gni")
import("//testing/test.gni")
import("//tools/binary_size/sizes.gni")
import("//ui/base/ui_features.gni")

# This arg temporarily enables or disables the updater_sandbox target.
Expand Down Expand Up @@ -55,6 +56,9 @@ group("gn_all") {
"//third_party/crashpad/crashpad/tools:crashpad_database_util($native_target)",
]
}
if (use_evergreen) {
deps += [ ":cobalt_sizes" ]
}
}

group("cobalt_browsertests") {
Expand Down Expand Up @@ -244,3 +248,16 @@ test("cobalt_unittests") {
deps += [ "//ui/ozone:ozone_switches" ]
}
}

if (use_evergreen) {
sizes_test("cobalt_sizes") {
data_deps = [ ":cobalt" ]
data = [ "${root_out_dir}/libcobalt.so" ]
executable_args = [
"--platform",
"cobalt-evergreen",
"--isolated-script-test-output",
"${root_out_dir}/test_results.json",
]
}
}
72 changes: 72 additions & 0 deletions cobalt/testing/tools/compare_sizes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""Compares the current size of libcobalt.so with a reference size."""

import json
import sys
import argparse


def get_stripped_size(perf_results_path):
with open(perf_results_path, 'r', encoding='utf-8') as f:
data = json.load(f)
for item in data:
if item.get('name') == 'libcobalt.so':
return item['sampleValues'][0]
return None


def get_reference_size(reference_path, platform, config):
with open(reference_path, 'r', encoding='utf-8') as f:
data = json.load(f)
build_key = f"{platform}_{config}"
if build_key in data and 'libcobalt.so' in data[build_key]:
return data[build_key]['libcobalt.so']['size']
return None


def main():
parser = argparse.ArgumentParser(description='Compare binary sizes.')
parser.add_argument(
'--current', required=True, help='Path to the current perf_results.json')
parser.add_argument(
'--reference', required=True, help='Path to the reference_metrics.json')
parser.add_argument(
'--platform',
required=True,
help='Platform (e.g., evergreen-arm-hardfp-rdk)')
parser.add_argument('--config', required=True, help='Config (e.g., gold)')
args = parser.parse_args()

current_size = get_stripped_size(args.current)
if current_size is None:
print(
f"Error: Could not find libcobalt.so size in {args.current}",
file=sys.stderr)
sys.exit(1)

reference_size = get_reference_size(args.reference, args.platform,
args.config)
if reference_size is None:
print(
f'Error: Could not find reference size for {args.platform}_'
f'{args.config} in {args.reference}',
file=sys.stderr)
sys.exit(1)

print(f'Current stripped size: {current_size} bytes ('
f'{current_size / 1000000:.2f} MB)')
print(f'Reference stripped size: {reference_size} bytes ('
f'{reference_size / 1000000:.2f} MB)')

if current_size > reference_size:
print(
f'Error: Current size ({current_size}) exceeds reference size '
f'({reference_size}) by {current_size - reference_size} bytes',
file=sys.stderr)
sys.exit(1)
else:
print('Success: Current size is within the reference size.')
sys.exit(0)


if __name__ == '__main__':
main()
47 changes: 47 additions & 0 deletions cobalt/testing/tools/process_size_artifacts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/bash -x

set -x

artifact_dir=$(find . -type d -name "size_artifacts_*" | head -n 1)
if [[ -d "$artifact_dir" ]]; then
# Extract platform from directory name like size_artifacts_evergreen-arm-hardfp-raspi_gold
PLATFORM=$(basename "$artifact_dir" | sed -n 's/size_artifacts_\(.*\)_gold/\1/p')
CONFIG=gold

if [[ -z "$PLATFORM" ]]; then
echo "Could not extract platform from $artifact_dir"
exit 1
fi

libcobalt_so_src="${artifact_dir}/libcobalt.so"

find_file() {
local file_name="$1"
local search_dir="$2"
local result_var="$3"
local file_path
file_path=$(find "$search_dir" -name "$file_name" -type f | head -n 1)
if [[ -z "$file_path" ]]; then
echo "$file_name not found in $search_dir"
return 1
fi
eval "$result_var"="'$file_path'"
}
RUNNER_PATH="${artifact_dir}/bin/run_cobalt_sizes"

echo "Running Check binary size for $PLATFORM"
vpython3 "$RUNNER_PATH" \
--output-directory "$artifact_dir" \
--isolated-script-test-output "$artifact_dir/sizes/test_results.json"

SIZES_PATH="$artifact_dir/sizes/sizes/perf_results.json"

echo "Running Compare binary size for $PLATFORM"
python3 cobalt/testing/tools/compare_sizes.py \
--current "$SIZES_PATH" \
--reference cobalt/testing/tools/reference_metrics.json \
--platform "${PLATFORM}" \
--config "${CONFIG}"
else
echo "Not a directory: $artifact_dir"
fi
8 changes: 8 additions & 0 deletions cobalt/testing/tools/reference_metrics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"evergreen-arm-hardfp-rdk_gold": {
"libcobalt.so": {
"size": 92482716,
"unit": "bytes"
}
}
}
20 changes: 20 additions & 0 deletions tools/binary_size/sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,25 @@ def main_win(output_directory, results_collector, size_path):
return 0


def main_cobalt_evergreen(output_directory, results_collector, size_path):
"""Print appropriate size information about built Cobalt Evergreen targets."""
assert size_path is None
binaries = [
'libcobalt.so',
]

result = 0

for binary in binaries:
this_result, this_sizes = check_linux_binary(binary, output_directory)
if result == 0:
result = this_result
for name, identifier, _, value, units in this_sizes:
results_collector.add_result(name, identifier, value, units)

return result


def format_for_histograms_conversion(data):
# We need to do two things to the provided data to make it compatible with the
# conversion script:
Expand All @@ -415,6 +434,7 @@ def main():
main_map = {
'android': main_android,
'android-cronet': main_android_cronet,
'cobalt-evergreen': main_cobalt_evergreen,
'linux': main_linux,
'mac': main_mac,
'win': main_win,
Expand Down
Loading