Skip to content

Commit e348194

Browse files
committed
new
1 parent 92970db commit e348194

File tree

2 files changed

+67
-24
lines changed

2 files changed

+67
-24
lines changed

ci/fireci/fireciplugins/macrobenchmark.py

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ async def _launch_macrobenchmark_test(build_only):
5656
_logger.info(f'Artifact versions: {artifact_versions}')
5757

5858
test_dir = await _prepare_test_directory()
59-
_logger.info(f'Test app directory: {test_dir}')
59+
_logger.info(f'Directory for test apps: {test_dir}')
6060

6161
config = await _process_config_yaml()
6262
_logger.info(f'Processed yaml configurations: {config}')
6363

6464
tests = [MacrobenchmarkTest(app, artifact_versions, os.getcwd(), test_dir) for app in config['test-apps']]
6565

6666
_logger.info(f'Building {len(tests)} macrobenchmark test apps...')
67-
# TODO(yifany): investigate why it runs significantly slower
68-
# - on corp workstations than M1 macbook pro
69-
# - with gradle 7.5.1 than gradle 6.9.2
67+
# 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)
7070
# await asyncio.gather(*[x.build() for x in tests])
7171
for test in tests:
7272
await test.build()
@@ -102,12 +102,12 @@ async def _process_config_yaml():
102102
app['traces'].extend(config['common-traces'])
103103

104104
# Adding an empty android app for baseline comparison
105-
config['test-apps'].append({'sdk': 'baseline', 'name': 'baseline'})
105+
config['test-apps'].insert(0, {'sdk': 'baseline', 'name': 'baseline'})
106106
return config
107107

108108

109109
async def _prepare_test_directory():
110-
test_dir = tempfile.mkdtemp(prefix='test-run-')
110+
test_dir = tempfile.mkdtemp(prefix='benchmark-test-')
111111

112112
# Required as the dir is not defined in the root settings.gradle
113113
open(os.path.join(test_dir, 'settings.gradle'), 'w').close()
@@ -172,25 +172,29 @@ async def _create_benchmark_projects(self):
172172
app_name = self.test_app_config['name']
173173
self.logger.info(f'Creating test app "{app_name}"...')
174174

175-
mustache_context = await self._prepare_mustache_context()
176-
175+
self.logger.info(f'Copying project template files into "{self.test_app_dir}"...')
177176
template_dir = os.path.join(self.repo_root_dir, 'health-metrics/benchmark/template')
178177
shutil.copytree(template_dir, self.test_app_dir)
178+
179+
self.logger.info(f'Copying gradle wrapper binary into "{self.test_app_dir}"...')
180+
shutil.copy(os.path.join(self.test_dir, 'gradlew'), self.test_app_dir)
181+
shutil.copy(os.path.join(self.test_dir, 'gradlew.bat'), self.test_app_dir)
182+
shutil.copytree(os.path.join(self.test_dir, 'gradle'), os.path.join(self.test_app_dir, 'gradle'))
183+
179184
with chdir(self.test_app_dir):
185+
mustache_context = await self._prepare_mustache_context()
180186
renderer = pystache.Renderer()
181187
mustaches = glob.glob('**/*.mustache', recursive=True)
182188
for mustache in mustaches:
183-
self.logger.info(f'Processing mustache template: {mustache}...')
189+
self.logger.info(f'Processing template file: {mustache}')
184190
result = renderer.render_path(mustache, mustache_context)
185191
original_name = mustache.removesuffix('.mustache')
186192
with open(original_name, 'w') as file:
187193
file.write(result)
188194

189195
async def _assemble_benchmark_apks(self):
190-
executable = './gradlew'
191-
args = ['assemble', '--project-dir', self.test_app_dir]
192-
with chdir(self.test_dir):
193-
await self._exec_subprocess(executable, args)
196+
with chdir(self.test_app_dir):
197+
await self._exec_subprocess('./gradlew', ['assemble'])
194198

195199
async def _execute_benchmark_tests(self):
196200
self.logger.debug(glob.glob(f'{self.test_app_dir}/**/*.apk', recursive=True))

health-metrics/benchmark/README.md

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,65 @@ different Firebase Android SDKs during app startup.
77

88
### Prerequisite
99

10-
- `fireci` CLI tool
10+
1. `fireci` CLI tool
1111

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

14-
- `google-services.json`
14+
1. `google-services.json`
1515

16-
Download it from Firebase project
17-
[`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`.
16+
Download it from Firebase project
17+
[`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`.
19+
20+
1. Authentication to Google Cloud
21+
22+
Authentication is required by Google Cloud SDK and Cloud Storage client
23+
library used in the benchmark tests.
24+
25+
One simple way is to configure it is to set an environment variable
26+
`GOOGLE_APPLICATION_CREDENTIALS` to a service account key file. However,
27+
please refer to the official Google Cloud
28+
[doc](https://cloud.google.com/docs/authentication) for full guidance on
29+
authentication.
1930

2031
### Running benchmark tests locally
2132

22-
1. Under the root directory `firebase-android-sdk`, run
33+
1. Build all test apps by running below command in the root
34+
directory `firebase-android-sdk`:
2335

24-
```
36+
```shell
2537
fireci macrobenchmark --build-only
2638
```
2739

28-
to create all benchmark test apps based on the [configuration](config.yaml).
29-
3040
1. [Connect an Android device to the computer](https://d.android.com/studio/run/device)
3141

32-
1.
42+
1. Locate the temporary test apps directory from the log, for example:
43+
44+
- on linux: `/tmp/benchmark-test-run-*/`
45+
- on macos: `/var/folders/**/benchmark-test-run-*/`
46+
47+
1. Start the benchmark tests from Android Studio or CLI:
48+
49+
- Android Studio
50+
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`
53+
54+
- CLI
55+
56+
1. Run below command in the test app project directory
57+
58+
```
59+
../gradlew :macrobenchmark:connectedCheck
60+
```
61+
62+
### Running benchmark tests on Firebase Test Lab
63+
64+
Build and run all tests on FTL by running below command in the root
65+
directory `firebase-android-sdk`:
66+
67+
```
68+
fireci macrobenchmark
69+
```
70+
71+
### Examining benchmark test results

0 commit comments

Comments
 (0)