Skip to content

Commit 17637b3

Browse files
committed
Refine startup time test app
- Forece initialize all components - Include fire-perf-early in measurements - Test only changed products in pull requests
1 parent d816ea8 commit 17637b3

File tree

7 files changed

+69
-15
lines changed

7 files changed

+69
-15
lines changed

.github/workflows/health-metrics.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ jobs:
122122
echo $INTEG_TESTS_GOOGLE_SERVICES | base64 -d > $BENCHMARK_APP_LOCATION
123123
- name: Run startup-time tests (presubmit)
124124
if: ${{ github.event_name == 'pull_request' }}
125-
run: fireci macrobenchmark ci --pull-request
125+
run: |
126+
git diff --name-only HEAD~1 | \
127+
xargs printf -- '--changed-git-paths %s\n' | \
128+
xargs ./gradlew writeChangedProjects --output-file-path=modules.json
129+
fireci macrobenchmark ci --pull-request --changed-modules-file modules.json
126130
- name: Run startup-time tests (post-submit)
127131
if: ${{ github.event_name == 'push' }}
128-
run: fireci macrobenchmark ci --push
132+
run: |
133+
fireci macrobenchmark ci --push

ci/fireci/fireciplugins/macrobenchmark/commands.py

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
import asyncio
1616
import click
1717
import json
18+
import logging
1819

1920
from .analyze import analyzer
2021
from .run import runner
2122
from fireci import ci_command, ci_utils, uploader
2223
from pathlib import Path
2324
from typing import List
2425

26+
logger = logging.getLogger('fireci.macrobenchmark')
27+
2528

2629
@ci_command(cls=click.Group)
2730
def macrobenchmark():
@@ -38,7 +41,7 @@ def macrobenchmark():
3841
)
3942
@click.option(
4043
'--local/--remote',
41-
required=True,
44+
default=True,
4245
help='Run the test on local devices or Firebase Test Lab.'
4346
)
4447
@click.option(
@@ -132,28 +135,45 @@ def analyze(
132135
required=True,
133136
help='Whether the test is running for a pull request or a push event.'
134137
)
138+
@click.option(
139+
'--changed-modules-file',
140+
type=click.Path(resolve_path=True, path_type=Path),
141+
help='Contains a list of changed modules in the current pull request.'
142+
)
135143
@click.option(
136144
'--repeat',
137145
default=10,
138146
show_default=True,
139147
help='Number of times to repeat the test (for obtaining more data points).'
140148
)
141149
@ci_command(group=macrobenchmark)
142-
def ci(pull_request, repeat):
150+
def ci(pull_request: bool, changed_modules_file: Path, repeat: int):
143151
"""Run tests in CI and upload results to the metric service."""
144152

145-
# TODO(yifany): run tests only for affected product in pull requests
146-
147153
output_path = Path("macrobenchmark-test-output.json")
148154
exception = None
155+
149156
try:
150-
asyncio.run(runner.start(build_only=False, local=False, repeat=repeat, output=output_path))
157+
if pull_request:
158+
asyncio.run(
159+
runner.start(
160+
build_only=False,
161+
local=False,
162+
repeat=repeat,
163+
output=output_path,
164+
changed_modules_file=changed_modules_file,
165+
)
166+
)
167+
else:
168+
asyncio.run(runner.start(build_only=False, local=False, repeat=repeat, output=output_path))
151169
except Exception as e:
170+
logger.error(f"Error: {e}")
152171
exception = e
153172

154173
with open(output_path) as output_file:
155174
output = json.load(output_file)
156-
ftl_dirs = list(filter(lambda x: x['project'] == 'all-included', output))[0]['successful_runs']
175+
project_name = 'test-changed' if pull_request else 'test-all'
176+
ftl_dirs = list(filter(lambda x: x['project'] == project_name, output))[0]['successful_runs']
157177
ftl_bucket_name = 'fireescape-benchmark-results'
158178

159179
log = ci_utils.ci_log_link()

ci/fireci/fireciplugins/macrobenchmark/run/runner.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,25 @@
2222
from .test_project_builder import TestProjectBuilder
2323
from .utils import execute
2424
from pathlib import Path
25-
from typing import Dict
25+
from typing import Dict, List
2626

2727

2828
logger = logging.getLogger('fireci.macrobenchmark')
2929

3030

31-
async def start(build_only: bool, local: bool, repeat: int, output: Path):
31+
async def start(
32+
build_only: bool,
33+
local: bool,
34+
repeat: int,
35+
output: Path,
36+
changed_modules_file: Path = None
37+
):
3238
logger.info('Starting macrobenchmark test ...')
3339

3440
config = _process_config_yaml()
3541
product_versions = _assemble_all_products()
3642
test_dir = _prepare_test_directory()
43+
changed_modules = _process_changed_modules(changed_modules_file)
3744
template_project_dir = Path('health-metrics/benchmark/template')
3845

3946
test_projects = [
@@ -42,6 +49,7 @@ async def start(build_only: bool, local: bool, repeat: int, output: Path):
4249
test_dir,
4350
template_project_dir,
4451
product_versions,
52+
changed_modules,
4553
).build() for test_config in config['test-apps']]
4654

4755
if not build_only:
@@ -99,3 +107,17 @@ def _prepare_test_directory() -> Path:
99107
test_dir = tempfile.mkdtemp(prefix='benchmark-test-')
100108
logger.info(f'Temporary test directory created at: {test_dir}')
101109
return Path(test_dir)
110+
111+
112+
def _process_changed_modules(path: Path) -> List[str]:
113+
results = []
114+
if path:
115+
with open(path) as changed_modules_file:
116+
changed_modules = json.load(changed_modules_file)
117+
for module in changed_modules:
118+
names = module.split(':')
119+
for name in names:
120+
if name.startswith('firebase-'):
121+
results.append(f'com.google.firebase:{name}')
122+
logger.info(f"Extracted changed modules {results} from {path}")
123+
return results

ci/fireci/fireciplugins/macrobenchmark/run/test_project_builder.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from .test_project import TestProject
2222
from .utils import execute
2323
from pathlib import Path
24-
from typing import Any, Dict
24+
from typing import Any, Dict, List
2525

2626

2727
logger = logging.getLogger('fireci.macrobenchmark')
@@ -33,13 +33,15 @@ def __init__(
3333
test_config: Any,
3434
test_dir: Path,
3535
template_project_dir: Path,
36-
product_versions: Dict[str, str]
36+
product_versions: Dict[str, str],
37+
changed_modules: List[str],
3738
):
3839
self.test_config = test_config
3940
self.template_project_dir = template_project_dir
4041
self.product_versions = product_versions
42+
self.changed_modules = changed_modules
4143

42-
self.name = test_config['name']
44+
self.name = 'test-changed' if changed_modules else 'test-all'
4345
self.logger = LogDecorator(logger, self.name)
4446
self.project_dir = test_dir.joinpath(self.name)
4547

@@ -77,7 +79,8 @@ def _flesh_out_mustache_template_files(self):
7779
dependency = {'key': key, 'version': version}
7880
else:
7981
dependency = {'key': dep, 'version': self.product_versions[dep]}
80-
mustache_context['dependencies'].append(dependency)
82+
if not self.changed_modules or dep in self.changed_modules:
83+
mustache_context['dependencies'].append(dependency)
8184

8285
renderer = pystache.Renderer()
8386
mustaches = self.project_dir.rglob('**/*.mustache')

firebase-common/src/main/java/com/google/firebase/FirebaseApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ public boolean isDefaultApp() {
472472
/** @hide */
473473
@VisibleForTesting
474474
@RestrictTo(Scope.TESTS)
475-
void initializeAllComponents() {
475+
public void initializeAllComponents() {
476476
componentRuntime.initializeAllComponentsForTests();
477477
}
478478

health-metrics/benchmark/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ test-apps:
5656
- fire-installations
5757
- firebase-ml-modeldownloader
5858
- fire-perf
59+
- fire-perf-early
5960
- fire-rc
6061
- fire-rtdb
6162
- fire-transport

health-metrics/benchmark/template/app/src/main/java/com/google/firebase/benchmark/MainActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ package com.google.firebase.benchmark
1616

1717
import androidx.appcompat.app.AppCompatActivity
1818
import android.os.Bundle
19+
import com.google.firebase.FirebaseApp
1920

2021
class MainActivity : AppCompatActivity() {
2122
override fun onCreate(savedInstanceState: Bundle?) {
2223
super.onCreate(savedInstanceState)
2324
setContentView(R.layout.activity_main)
25+
26+
FirebaseApp.getInstance().initializeAllComponents()
2427
}
2528
}

0 commit comments

Comments
 (0)