Skip to content

Commit 308ac3a

Browse files
committed
[Feature] Introduce benchx_cli for benchmark
Use it with `./benchx_cli -o <output_ptrace_file> run <lynx_bundle_path>` to get a ptrace file of the Lynx Bundle. Under the hood it runs the Lynx Bundle with specific embedder api mocked so not suitable for serious e2e test, but should be sufficient for benchmark. Also, codspeed is integrate into the cli, so benchmark result can be uploaded to codspeed platform for tracking ingression.
1 parent 25af017 commit 308ac3a

33 files changed

+1090
-23
lines changed
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
name: Benchx CLI Publish
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
7+
push:
8+
tags:
9+
- '*'
10+
workflow_call:
11+
inputs:
12+
skip_release:
13+
description: 'Skip the release job'
14+
required: false
15+
default: false
16+
type: boolean
17+
commit_ref:
18+
description: 'Commit SHA or branch name to build'
19+
required: false
20+
type: string
21+
workflow_dispatch:
22+
23+
permissions:
24+
contents: write
25+
26+
jobs:
27+
build:
28+
name: Build ${{ matrix.os_name }} ${{ matrix.arch_name }}
29+
runs-on: ${{ matrix.os }}
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
include:
34+
- os: ubuntu-latest
35+
os_name: Linux
36+
arch_name: x86_64
37+
- os: macos-latest
38+
os_name: Darwin
39+
arch_name: arm64
40+
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v4
44+
with:
45+
ref: ${{ inputs.commit_ref || github.ref }}
46+
47+
- name: Setup Node
48+
uses: actions/setup-node@v4
49+
with:
50+
node-version: '24'
51+
52+
- name: Setup sccache
53+
uses: mozilla-actions/sccache-action@v0.0.8
54+
55+
- name: Setup uv
56+
uses: astral-sh/setup-uv@v5
57+
58+
- name: Install Dependencies
59+
run: |
60+
# Configure sccache
61+
echo "SCCACHE_DIR=$GITHUB_WORKSPACE/.sccache" >> $GITHUB_ENV
62+
mkdir -p .sccache
63+
64+
# Show sccache stats before build
65+
sccache -z
66+
67+
uv venv
68+
uv pip install pip
69+
70+
# Ensure tools are executable
71+
chmod +x tools/hab || true
72+
73+
# Source envsetup to set paths for hab and other tools
74+
set +u
75+
source tools/envsetup.sh
76+
77+
echo "Syncing dependencies..."
78+
tools/hab sync .
79+
80+
- name: Cache sccache
81+
uses: actions/cache@v4
82+
with:
83+
path: .sccache
84+
key: ${{ matrix.os }}-${{ matrix.arch_name }}-sccache-${{ github.sha }}
85+
restore-keys: |
86+
${{ matrix.os }}-${{ matrix.arch_name }}-sccache-
87+
88+
- name: Build
89+
run: |
90+
set +u
91+
source tools/envsetup.sh
92+
93+
echo "Generating build files for ${{ matrix.os_name }} ${{ matrix.arch_name }}..."
94+
95+
# Base args
96+
ARGS='enable_unittests=true enable_trace="perfetto" jsengine_type="quickjs" enable_frozen_mode=true use_sccache=true'
97+
98+
99+
# Platform specific args
100+
if [[ "${{ matrix.os_name }}" == "Darwin" ]]; then
101+
ARGS="$ARGS use_flutter_cxx=false"
102+
fi
103+
104+
# Note: If cross-compilation is needed for arm64 on Linux, target_cpu arg would be needed
105+
# But here we are running on native runners (macos-latest is arm64, others x64)
106+
107+
echo "GN Args: $ARGS"
108+
gn gen --args="$ARGS" out/Default
109+
110+
echo "Building benchx_cli..."
111+
ninja -C out/Default cli/benchx:benchx_cli
112+
113+
# Show sccache stats after build
114+
sccache -s
115+
116+
- name: Prepare and Package Artifacts
117+
run: |
118+
mkdir -p dist/bin
119+
BINARY_PATH="out/Default/benchx_cli"
120+
121+
if [ ! -f "$BINARY_PATH" ]; then
122+
echo "Error: Binary not found at $BINARY_PATH"
123+
ls -R out/Default
124+
exit 1
125+
fi
126+
127+
echo "Found binary at $BINARY_PATH"
128+
cp "$BINARY_PATH" dist/bin/benchx_cli
129+
130+
# Create archive with specific naming format: benchx_cli_OS_Arch.tar.gz
131+
# e.g., benchx_cli_Darwin_arm64.tar.gz
132+
ARCHIVE_NAME="benchx_cli_${{ matrix.os_name }}_${{ matrix.arch_name }}.tar.gz"
133+
134+
cd dist/bin
135+
tar -czvf "../../$ARCHIVE_NAME" benchx_cli
136+
cd ../..
137+
138+
echo "Created archive: $ARCHIVE_NAME"
139+
140+
- name: Upload Artifact
141+
uses: actions/upload-artifact@v4
142+
with:
143+
name: build-artifact-${{ matrix.os_name }}-${{ matrix.arch_name }}
144+
path: benchx_cli_*.tar.gz
145+
146+
release:
147+
name: Create Release
148+
needs: build
149+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') && !inputs.skip_release
150+
runs-on: ubuntu-latest
151+
steps:
152+
- name: Download Artifacts
153+
uses: actions/download-artifact@v4
154+
with:
155+
path: artifacts
156+
merge-multiple: true # Merge all artifacts into one directory
157+
158+
- name: List Artifacts
159+
run: |
160+
ls -R artifacts
161+
162+
- name: Publish Release
163+
uses: softprops/action-gh-release@v2
164+
with:
165+
files: artifacts/*
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Periodic Rebase
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *' # Daily at 00:00 UTC
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
prepare-rebase:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
temp_branch: ${{ steps.create_branch.outputs.branch_name }}
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
with:
20+
ref: develop
21+
fetch-depth: 0
22+
token: ${{ secrets.GITHUB_TOKEN }}
23+
24+
- name: Configure Git
25+
run: |
26+
git config --global user.name "github-actions[bot]"
27+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
28+
29+
- name: Rebase Upstream and Push to Temp Branch
30+
id: create_branch
31+
run: |
32+
UPSTREAM_URL="https://github.com/lynx-family/lynx.git"
33+
34+
echo "Setting upstream to $UPSTREAM_URL"
35+
git remote add upstream "$UPSTREAM_URL"
36+
git fetch upstream
37+
38+
echo "Rebasing develop..."
39+
git checkout develop
40+
41+
if git rebase upstream/develop; then
42+
echo "Rebase successful."
43+
# Create a unique temporary branch name
44+
TEMP_BRANCH="rebase-check-${{ github.run_id }}"
45+
git checkout -b "$TEMP_BRANCH"
46+
git push origin "$TEMP_BRANCH" --force
47+
48+
echo "branch_name=$TEMP_BRANCH" >> "$GITHUB_OUTPUT"
49+
else
50+
echo "Rebase failed due to conflicts. Aborting."
51+
git rebase --abort
52+
exit 1
53+
fi
54+
55+
check-build:
56+
needs: prepare-rebase
57+
uses: ./.github/workflows/benchx_cli_publish.yml
58+
with:
59+
skip_release: true
60+
commit_ref: ${{ needs.prepare-rebase.outputs.temp_branch }}
61+
62+
push-to-develop:
63+
needs: [prepare-rebase, check-build]
64+
runs-on: ubuntu-latest
65+
if: success()
66+
steps:
67+
- name: Checkout Temp Branch
68+
uses: actions/checkout@v4
69+
with:
70+
ref: ${{ needs.prepare-rebase.outputs.temp_branch }}
71+
fetch-depth: 0
72+
token: ${{ secrets.GITHUB_TOKEN }}
73+
74+
- name: Push to Develop
75+
run: |
76+
git config --global user.name "github-actions[bot]"
77+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
78+
79+
echo "Pushing verified rebase to develop..."
80+
git checkout develop
81+
# Reset develop to the verified temp branch commit
82+
git reset --hard origin/${{ needs.prepare-rebase.outputs.temp_branch }}
83+
git push origin develop --force-with-lease
84+
85+
# Cleanup
86+
git push origin --delete ${{ needs.prepare-rebase.outputs.temp_branch }}

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,8 @@ js_libraries/lynx-core/src/common/feature.ts
144144
/tools/api/android
145145
/tools/api/ios
146146
/tools/api/docs/gen
147+
148+
compile_commands.json
149+
.cache/
150+
151+
.codspeed_*/

.habitat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
habitat_version = "0.3.146-alpha.2"
1+
habitat_version = "0.3.146-alpha.4"
22
solutions = [
33
{
44
'name': '.',

BUILD.gn

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,8 @@ group("third_party_trace_group") {
7171
deps += [ "base/trace/native:trace_tests" ]
7272
}
7373
}
74+
75+
group("cli") {
76+
deps = ["cli/benchx:benchx_cli"]
77+
testonly = true
78+
}

cli/benchx/BUILD.gn

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Copyright 2020 The Lynx Authors. All rights reserved.
2+
# Licensed under the Apache License Version 2.0 that can be found in the
3+
# LICENSE file in the root directory of this source tree.
4+
5+
import("//core/Lynx.gni")
6+
import("//testing/test.gni")
7+
8+
executable("benchx_cli") {
9+
testonly = true
10+
sources = [
11+
"benchx_cli.cc",
12+
"painting_context_platform_impl.cc",
13+
"performance_apis.cc",
14+
"resource_loader.cc",
15+
"tasm_platform_invoker_dummy.cc",
16+
]
17+
deps = [
18+
"//base/src:base_group",
19+
"//base/trace/native:trace",
20+
"//core/event",
21+
"//core/renderer:tasm",
22+
"//core/renderer/dom:dom",
23+
"//core/renderer/dom:renderer_dom",
24+
"//core/renderer/dom/selector:element_selector",
25+
"//core/resource",
26+
"//core/services/event_report",
27+
"//core/shared_data",
28+
"//core/shell",
29+
"//js_libraries/lynx-core",
30+
"//third_party/argparse",
31+
"//third_party/codspeed-instrument-hooks",
32+
"//third_party/rapidjson",
33+
]
34+
}

0 commit comments

Comments
 (0)