@@ -5,9 +5,69 @@ This guide shows how to run benchmarks on BrowserStack and fetch results within
55## Overview
66
77The 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)) {
2914081 . Check device logs manually in BrowserStack dashboard
2924092 . Verify your app logs benchmark results as JSON to stdout/logcat
2934103 . 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)) {
3004181 . Check the BrowserStack dashboard for device screenshots/video
3014192 . Increase timeout if benchmarks legitimately take longer
3024203 . 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)) {
3104292 . Use BrowserStack's webhook notifications instead of polling
3114303 . 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
0 commit comments