Skip to content

Commit f73bfc6

Browse files
committed
done
1 parent e348194 commit f73bfc6

File tree

2 files changed

+78
-30
lines changed

2 files changed

+78
-30
lines changed

ci/fireci/fireciplugins/macrobenchmark.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ async def _launch_macrobenchmark_test(build_only):
6565

6666
_logger.info(f'Building {len(tests)} macrobenchmark test apps...')
6767
# TODO(yifany): investigate why it is much slower with asyncio.gather
68-
# - on corp workstations (10 min) than M1 macbook pro (3 min)
69-
# - with gradle 7.5.1 (10 min) than gradle 6.9.2 (5 min)
68+
# - on corp workstations (9 min) than M1 macbook pro (3 min)
69+
# - with gradle 7.5.1 (9 min) than gradle 6.9.2 (5 min)
7070
# await asyncio.gather(*[x.build() for x in tests])
7171
for test in tests:
7272
await test.build()
@@ -119,6 +119,12 @@ async def _prepare_test_directory():
119119

120120

121121
async def _post_processing(results):
122+
_logger.info(f'Macrobenchmark results: {results}')
123+
124+
if os.getenv('CI') is None:
125+
_logger.info('Running locally. Results upload skipped.')
126+
return
127+
122128
# Upload successful measurements to the metric service
123129
measurements = []
124130
for result in results:
@@ -197,13 +203,8 @@ async def _assemble_benchmark_apks(self):
197203
await self._exec_subprocess('./gradlew', ['assemble'])
198204

199205
async def _execute_benchmark_tests(self):
200-
self.logger.debug(glob.glob(f'{self.test_app_dir}/**/*.apk', recursive=True))
201-
app_apk_paths = glob.glob(f'{self.test_app_dir}/**/app-benchmark.apk', recursive=True)
202-
self.logger.debug(app_apk_paths)
203-
app_apk_path = app_apk_paths[0]
204-
test_apk_paths = glob.glob(f'{self.test_app_dir}/**/macrobenchmark-benchmark.apk', recursive=True)
205-
self.logger.debug(test_apk_paths)
206-
test_apk_path = test_apk_paths[0]
206+
app_apk_path = glob.glob(f'{self.test_app_dir}/**/app-benchmark.apk', recursive=True)[0]
207+
test_apk_path = glob.glob(f'{self.test_app_dir}/**/macrobenchmark-benchmark.apk', recursive=True)[0]
207208

208209
self.logger.info(f'App apk: {app_apk_path}')
209210
self.logger.info(f'Test apk: {test_apk_path}')
@@ -232,6 +233,7 @@ async def _prepare_mustache_context(self):
232233
mustache_context = {
233234
'm2repository': os.path.join(self.repo_root_dir, 'build/m2repository'),
234235
'plugins': self.test_app_config.get('plugins', []),
236+
'traces': self.test_app_config.get('traces', []),
235237
'dependencies': [],
236238
}
237239

@@ -256,9 +258,9 @@ async def _aggregate_benchmark_results(self):
256258
for benchmark in benchmarks:
257259
method = benchmark['name']
258260
clazz = benchmark['className'].split('.')[-1]
259-
runs = benchmark['metrics']['startupMs']['runs']
261+
runs = benchmark['metrics']['timeToInitialDisplayMs']['runs']
260262
results.append({
261-
'sdk': self.test_app_config.sdk,
263+
'sdk': self.test_app_config['sdk'],
262264
'device': device,
263265
'name': f'{clazz}.{method}',
264266
'min': min(runs),

health-metrics/benchmark/README.md

Lines changed: 65 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
11
# Benchmark
22

33
This directory contains the benchmark test apps used for measuring latency for
4-
different Firebase Android SDKs during app startup.
4+
initializing Firebase Android SDKs during app startup.
55

6-
## Usage
6+
## Test app configurations
7+
8+
[config.yaml](config.yaml) contains a list of configuration blocks for
9+
building a macrobenchmark test app for each of the Firebase Android SDKs.
10+
If not all of them are required, comment out irrelevant ones for faster build
11+
and test time.
12+
13+
**Note**: An empty Android app (named `baseline`) will be created during runtime
14+
for baseline comparison, even though it is not listed in
15+
[config.yaml](config.yaml). This app can also be used as a skeleton for
16+
setting up a more complex benchmark testing app.
17+
18+
## Run benchmark tests
719

820
### Prerequisite
921

1022
1. `fireci` CLI tool
1123

12-
Refer to the [readme](../../ci/fireci/README.md) for how to install it.
24+
Refer to its [readme](../../ci/fireci/README.md) for how to install it.
1325

1426
1. `google-services.json`
1527

16-
Download it from Firebase project
28+
Download it from the Firebase project
1729
[`fireescape-integ-tests`](https://firebase.corp.google.com/u/0/project/fireescape-integ-tests)
18-
to the directory `firebase-android-sdk/health-metrics/benchmark/template/app`.
30+
to the directory `./template/app`.
1931

2032
1. Authentication to Google Cloud
2133

22-
Authentication is required by Google Cloud SDK and Cloud Storage client
23-
library used in the benchmark tests.
34+
Authentication is required by Google Cloud SDK and Google Cloud Storage
35+
client library used in the benchmark tests.
2436

2537
One simple way is to configure it is to set an environment variable
2638
`GOOGLE_APPLICATION_CREDENTIALS` to a service account key file. However,
2739
please refer to the official Google Cloud
2840
[doc](https://cloud.google.com/docs/authentication) for full guidance on
2941
authentication.
3042

31-
### Running benchmark tests locally
43+
### Run benchmark tests locally
3244

3345
1. Build all test apps by running below command in the root
3446
directory `firebase-android-sdk`:
@@ -41,25 +53,48 @@ different Firebase Android SDKs during app startup.
4153

4254
1. Locate the temporary test apps directory from the log, for example:
4355

44-
- on linux: `/tmp/benchmark-test-run-*/`
45-
- on macos: `/var/folders/**/benchmark-test-run-*/`
56+
- on linux: `/tmp/benchmark-test-*/`
57+
- on macos: `/var/folders/**/benchmark-test-*/`
4658

47-
1. Start the benchmark tests from Android Studio or CLI:
59+
1. Start the benchmark tests from CLI or Android Studio:
60+
61+
- CLI
62+
63+
Run below command in the above test app project directory
64+
65+
```
66+
./gradlew :macrobenchmark:connectedCheck
67+
```
4868
4969
- Android Studio
5070
51-
1. Import the project (e.g. `**/benchmark-test-run-*/firestore`) into Android Studio
52-
1. Start the benchmark test by clicking gutter icon in the file `BenchmarkTest.kt`
71+
1. Import the project (e.g. `**/benchmark-test-*/firestore`) into Android Studio
72+
1. Start the benchmark test by clicking gutter icons in the file `BenchmarkTest.kt`
73+
74+
1. Inspect the benchmark test results:
5375
5476
- CLI
5577
56-
1. Run below command in the test app project directory
78+
Result files are created in `<test-app-dir>/macrobenchmark/build/outputs/`:
5779
58-
```
59-
../gradlew :macrobenchmark:connectedCheck
60-
```
80+
- `*-benchmarkData.json` contains metric aggregates
81+
- `*.perfetto-trace` are the raw trace files
6182
62-
### Running benchmark tests on Firebase Test Lab
83+
Additionally, upload `.perfetto-trace` files to
84+
[Perfetto Trace Viewer](https://ui.perfetto.dev/) to visualize all traces.
85+
86+
- Android Studio
87+
88+
Test results are displayed directly in the "Run" tool window, including
89+
90+
- macrobenchmark built-in metrics
91+
- duration of custom traces
92+
- links to trace files that can be visualized within the IDE
93+
94+
Alternatively, same set of result files are produced at the same output
95+
location as invoking tests from CLI, which can be used for inspection.
96+
97+
### Run benchmark tests on Firebase Test Lab
6398
6499
Build and run all tests on FTL by running below command in the root
65100
directory `firebase-android-sdk`:
@@ -68,4 +103,15 @@ directory `firebase-android-sdk`:
68103
fireci macrobenchmark
69104
```
70105
71-
### Examining benchmark test results
106+
Alternatively, it is possible to build all test apps via steps described in
107+
[Running benchmark tests locally](#running-benchmark-tests-locally)
108+
and manually
109+
[run tests on FTL with `gcloud` CLI ](https://firebase.google.com/docs/test-lab/android/command-line#running_your_instrumentation_tests).
110+
111+
Aggregated benchmark results are displayed in the log. The log also
112+
contains links to FTL result pages and result files on Google Cloud Storage.
113+
114+
## Toolchains
115+
116+
- Gradle 7.5.1
117+
- Android Gradle Plugin 7.2.2

0 commit comments

Comments
 (0)