Skip to content

Commit 70af5c3

Browse files
author
dcbuilder.eth
committed
Merge branch 'main' of github.com:worldcoin/mobile-bench-rs
2 parents bf30234 + 86e36d6 commit 70af5c3

File tree

25 files changed

+5905
-233
lines changed

25 files changed

+5905
-233
lines changed

BENCH_SDK_INTEGRATION.md

Lines changed: 449 additions & 4 deletions
Large diffs are not rendered by default.

BROWSERSTACK_CI_INTEGRATION.md

Lines changed: 180 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,69 @@ This guide shows how to run benchmarks on BrowserStack and fetch results within
55
## Overview
66

77
The BrowserStack client now supports:
8-
1. **Scheduling runs** - Upload artifacts and start tests
9-
2. **Polling for completion** - Wait for tests to finish (with timeout)
10-
3. **Fetching results** - Download device logs and extract benchmark data
8+
1. **Prerequisite checking** - Verify tools and credentials before builds
9+
2. **Device validation** - Validate device specs before scheduling runs
10+
3. **Scheduling runs** - Upload artifacts and start tests
11+
4. **Polling for completion** - Wait for tests to finish (with timeout)
12+
5. **Fetching results** - Download device logs and extract benchmark data
13+
6. **Result analysis** - Display summary statistics from reports
14+
15+
## Pre-flight Validation
16+
17+
Before running benchmarks on BrowserStack, validate your setup:
18+
19+
### Check Prerequisites
20+
21+
```bash
22+
# Verify Android build tools are installed
23+
cargo mobench check --target android
24+
25+
# Verify iOS build tools are installed
26+
cargo mobench check --target ios
27+
28+
# Output as JSON for CI parsing
29+
cargo mobench check --target android --format json
30+
```
31+
32+
The `check` command validates:
33+
- Rust toolchain and cargo
34+
- Android: NDK, cargo-ndk, Rust targets, JDK
35+
- iOS: Xcode, xcodegen, Rust targets
36+
37+
### Validate Devices
38+
39+
Before scheduling runs, validate device specs:
40+
41+
```bash
42+
# Validate specific device specs
43+
cargo mobench devices --validate "Google Pixel 7-13.0" "iPhone 14-16"
44+
45+
# List available devices
46+
cargo mobench devices --platform android
47+
cargo mobench devices --platform ios
48+
49+
# Output as JSON
50+
cargo mobench devices --platform android --json
51+
```
52+
53+
Invalid device specs return helpful suggestions:
54+
```
55+
Invalid devices (1):
56+
[ERROR] Google Pixle 7-13.0: Device not found
57+
Suggestions:
58+
- Google Pixel 7-13.0
59+
- Google Pixel 7 Pro-13.0
60+
```
61+
62+
### Verify Benchmark Setup
63+
64+
```bash
65+
# Verify registry, spec, and artifacts
66+
cargo mobench verify --target android --check-artifacts
67+
68+
# Include smoke test
69+
cargo mobench verify --target android --smoke-test --function my_benchmark
70+
```
1171

1272
## Quick Example
1373

@@ -181,6 +241,15 @@ jobs:
181241
- name: Install mobench
182242
run: cargo install mobench
183243

244+
- name: Check prerequisites
245+
run: cargo mobench check --target android
246+
247+
- name: Validate devices
248+
env:
249+
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
250+
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
251+
run: cargo mobench devices --validate "Google Pixel 7-13.0"
252+
184253
- name: Run benchmarks on BrowserStack
185254
env:
186255
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
@@ -199,14 +268,22 @@ jobs:
199268
--fetch-timeout-secs 600 \
200269
--output results.json
201270
202-
# Extract metrics for comparison
203-
cat results.json | jq '.devices[0].samples | map(.duration_ns) | add / length'
271+
- name: Display summary
272+
run: cargo mobench summary results.json
273+
274+
- name: Extract metrics
275+
run: |
276+
# JSON format for programmatic access
277+
cargo mobench summary results.json --format json > metrics.json
278+
cat metrics.json | jq '.[0].mean_ns'
204279
205280
- name: Upload results
206281
uses: actions/upload-artifact@v4
207282
with:
208283
name: benchmark-results
209-
path: results.json
284+
path: |
285+
results.json
286+
metrics.json
210287
```
211288
212289
## Advanced: Custom Result Processing
@@ -283,6 +360,46 @@ match client.wait_and_fetch_all_results(build_id, "espresso", Some(600)) {
283360

284361
## Troubleshooting
285362

363+
### BrowserStack credentials not configured
364+
365+
**Error**:
366+
```
367+
BrowserStack credentials not configured.
368+
369+
Set credentials using one of these methods:
370+
371+
1. Environment variables:
372+
export BROWSERSTACK_USERNAME=your_username
373+
export BROWSERSTACK_ACCESS_KEY=your_access_key
374+
375+
2. Config file (bench-config.toml):
376+
[browserstack]
377+
app_automate_username = "your_username"
378+
app_automate_access_key = "your_access_key"
379+
380+
3. .env.local file in project root:
381+
BROWSERSTACK_USERNAME=your_username
382+
BROWSERSTACK_ACCESS_KEY=your_access_key
383+
384+
Get credentials: https://app-automate.browserstack.com/
385+
(Navigate to Settings -> Access Key)
386+
```
387+
388+
**Solution**: Set credentials using any of the three methods shown.
389+
390+
### Device spec validation failed
391+
392+
**Error**:
393+
```
394+
Invalid devices (1):
395+
[ERROR] Google Pixle 7-13.0: Device not found
396+
Suggestions:
397+
- Google Pixel 7-13.0
398+
- Google Pixel 7 Pro-13.0
399+
```
400+
401+
**Solution**: Use the suggested device name or run `cargo mobench devices` to see all available devices.
402+
286403
### No benchmark results found
287404

288405
**Cause**: The benchmark app didn't log results, or logs are in unexpected format.
@@ -291,6 +408,7 @@ match client.wait_and_fetch_all_results(build_id, "espresso", Some(600)) {
291408
1. Check device logs manually in BrowserStack dashboard
292409
2. Verify your app logs benchmark results as JSON to stdout/logcat
293410
3. Use `client.get_device_logs()` to inspect raw logs
411+
4. Run `cargo mobench verify --smoke-test` to test locally first
294412

295413
### Build stuck in "running" state
296414

@@ -300,6 +418,7 @@ match client.wait_and_fetch_all_results(build_id, "espresso", Some(600)) {
300418
1. Check the BrowserStack dashboard for device screenshots/video
301419
2. Increase timeout if benchmarks legitimately take longer
302420
3. Add health checks to your benchmark code
421+
4. Use `--progress` flag to see detailed progress during runs
303422

304423
### Rate limiting
305424

@@ -310,8 +429,63 @@ match client.wait_and_fetch_all_results(build_id, "espresso", Some(600)) {
310429
2. Use BrowserStack's webhook notifications instead of polling
311430
3. Check your BrowserStack plan limits
312431

432+
### Prerequisites missing
433+
434+
**Error**: Build fails with missing tools.
435+
436+
**Solution**: Run `cargo mobench check --target <android|ios>` to identify missing prerequisites and get fix suggestions.
437+
438+
## New CLI Commands
439+
440+
### `cargo mobench check`
441+
442+
Validate prerequisites before building:
443+
444+
```bash
445+
cargo mobench check --target android [--format text|json]
446+
```
447+
448+
### `cargo mobench devices`
449+
450+
List and validate BrowserStack devices:
451+
452+
```bash
453+
# List all devices
454+
cargo mobench devices
455+
456+
# List by platform
457+
cargo mobench devices --platform android
458+
459+
# Validate specific specs
460+
cargo mobench devices --validate "Google Pixel 7-13.0" "iPhone 14-16"
461+
462+
# JSON output
463+
cargo mobench devices --json
464+
```
465+
466+
### `cargo mobench verify`
467+
468+
Validate benchmark setup:
469+
470+
```bash
471+
cargo mobench verify \
472+
--target android \
473+
--check-artifacts \
474+
--smoke-test \
475+
--function my_benchmark
476+
```
477+
478+
### `cargo mobench summary`
479+
480+
Display statistics from results:
481+
482+
```bash
483+
cargo mobench summary results.json [--format text|json|csv]
484+
```
485+
313486
## Next Steps
314487

315488
- See `BROWSERSTACK_METRICS.md` for metrics and performance documentation
489+
- See `FETCH_RESULTS_GUIDE.md` for detailed fetch and summary workflows
316490
- Check `crates/mobench/src/browserstack.rs` for full API documentation
317491
- Run `cargo doc --open -p mobench` for detailed API docs

BUILD.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,60 @@
33
Complete build instructions for Android and iOS targets.
44

55
> **For SDK Integrators**: Use the CLI commands:
6+
> - `cargo mobench check --target android` (validate prerequisites first)
7+
> - `cargo mobench check --target ios` (validate prerequisites first)
68
> - `cargo mobench build --target android`
79
> - `cargo mobench build --target ios`
810
>
911
> See [BENCH_SDK_INTEGRATION.md](BENCH_SDK_INTEGRATION.md) for the integration guide.
1012
1113
## Table of Contents
14+
- [Prerequisites Check](#prerequisites-check)
1215
- [Prerequisites](#prerequisites)
1316
- [Android Build](#android-build)
1417
- [iOS Build](#ios-build)
1518
- [Common Issues](#common-issues)
1619

20+
## Prerequisites Check
21+
22+
Before installing prerequisites manually, use the `check` command to validate your setup:
23+
24+
```bash
25+
# Check Android prerequisites
26+
cargo mobench check --target android
27+
28+
# Check iOS prerequisites
29+
cargo mobench check --target ios
30+
31+
# Check both platforms
32+
cargo mobench check --target android
33+
cargo mobench check --target ios
34+
```
35+
36+
The `check` command validates:
37+
- **Android**: `ANDROID_NDK_HOME` environment variable, `cargo-ndk` installation, Rust targets
38+
- **iOS**: Xcode installation, `xcodegen`, Rust targets
39+
- **Both**: Cargo, rustup, required Rust targets
40+
41+
Output includes:
42+
- Pass/fail status for each prerequisite
43+
- Instructions for fixing missing prerequisites
44+
- JSON output option (`--format json`) for CI integration
45+
46+
Example output:
47+
```
48+
Checking Android prerequisites...
49+
[PASS] cargo found
50+
[PASS] rustup found
51+
[PASS] ANDROID_NDK_HOME set: /Users/you/Library/Android/sdk/ndk/29.0.14206865
52+
[PASS] cargo-ndk installed
53+
[PASS] Rust target aarch64-linux-android installed
54+
[PASS] Rust target armv7-linux-androideabi installed
55+
[PASS] Rust target x86_64-linux-android installed
56+
57+
All prerequisites satisfied!
58+
```
59+
1760
## Prerequisites
1861

1962
### All Platforms
@@ -75,9 +118,15 @@ xcodebuild -version
75118

76119
### Quick Start (Recommended)
77120
```bash
121+
# First, check prerequisites
122+
cargo mobench check --target android
123+
78124
# Build everything and create APK in one command
79125
cargo mobench build --target android
80126

127+
# Or build with progress output for clearer feedback
128+
cargo mobench build --target android --progress
129+
81130
# Install on connected device or emulator
82131
adb install -r target/mobench/android/app/build/outputs/apk/debug/app-debug.apk
83132

@@ -157,9 +206,15 @@ cargo mobench build --target android
157206

158207
### Quick Start (Recommended)
159208
```bash
209+
# First, check prerequisites
210+
cargo mobench check --target ios
211+
160212
# Build Rust xcframework (includes automatic code signing)
161213
cargo mobench build --target ios
162214

215+
# Or build with progress output for clearer feedback
216+
cargo mobench build --target ios --progress
217+
163218
# Generate Xcode project
164219
cd target/mobench/ios/BenchRunner
165220
xcodegen generate
@@ -311,10 +366,17 @@ codesign --force --deep --sign - target/mobench/ios/sample_fns.xcframework
311366

312367
## Common Issues
313368

369+
### Prerequisite Validation
370+
371+
**Tip**: Before troubleshooting, run `cargo mobench check --target <android|ios>` to identify missing prerequisites. The check command provides specific instructions for each issue.
372+
314373
### Android
315374

316375
**Issue**: `ANDROID_NDK_HOME is not set`
317376
```bash
377+
# Run check to see the full prerequisite status
378+
cargo mobench check --target android
379+
318380
# Find your NDK installation
319381
find ~/Library/Android/sdk/ndk -name "ndk-build" 2>/dev/null
320382

0 commit comments

Comments
 (0)