Skip to content

Commit

Permalink
Refactor BenchmarkStore.listResources()
Browse files Browse the repository at this point in the history
  • Loading branch information
anhappdev committed Nov 7, 2024
1 parent 1e24327 commit f411947
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
4 changes: 1 addition & 3 deletions flutter/lib/benchmark/benchmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,11 @@ class BenchmarkStore {

List<Resource> listResources({
required List<BenchmarkRunMode> modes,
bool skipInactive = false,
required List<Benchmark> benchmarks,
}) {
final result = <Resource>[];

for (final b in benchmarks) {
if (skipInactive && !b.isActive) continue;

for (var mode in modes) {
final dataset = mode.chooseDataset(b.taskConfig);
final data = Resource(
Expand Down
10 changes: 4 additions & 6 deletions flutter/lib/benchmark/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,11 @@ class BenchmarkState extends ChangeNotifier {

await Wakelock.enable();
print('start loading resources');
await resourceManager.handleResources(
_benchmarkStore.listResources(
modes: [taskRunner.perfMode, taskRunner.accuracyMode],
skipInactive: false,
),
needToPurgeCache,
final resources = _benchmarkStore.listResources(
modes: [taskRunner.perfMode, taskRunner.accuracyMode],
benchmarks: benchmarks,
);
await resourceManager.handleResources(resources, needToPurgeCache);
print('finished loading resources');
error = null;
stackTrace = null;
Expand Down
11 changes: 9 additions & 2 deletions flutter/lib/resources/validation_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class ValidationHelper {
required this.selectedRunModes,
});

List<Benchmark> get activeBenchmarks =>
benchmarkStore.benchmarks.where((e) => e.isActive).toList();

Future<String> validateExternalResourcesDirectory(
String errorDescription) async {
final dataFolderPath = resourceManager.getDataFolder();
Expand All @@ -28,7 +31,9 @@ class ValidationHelper {
return 'Data folder does not exist';
}
final resources = benchmarkStore.listResources(
modes: selectedRunModes, skipInactive: true);
modes: selectedRunModes,
benchmarks: activeBenchmarks,
);
final missing = await resourceManager.validateResourcesExist(resources);
if (missing.isEmpty) return '';

Expand All @@ -38,7 +43,9 @@ class ValidationHelper {

Future<String> validateOfflineMode(String errorDescription) async {
final resources = benchmarkStore.listResources(
modes: selectedRunModes, skipInactive: true);
modes: selectedRunModes,
benchmarks: activeBenchmarks,
);
final internetResources = filterInternetResources(resources);
if (internetResources.isEmpty) return '';

Expand Down
28 changes: 24 additions & 4 deletions flutter/unit_test/benchmark/benchmark_store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ void main() {
);

final modes = [BenchmarkRunMode.accuracy];
final resources = store.listResources(modes: modes, skipInactive: true);
final activeBenchmarks =
store.benchmarks.where((e) => e.isActive).toList();
final resources = store.listResources(
modes: modes,
benchmarks: activeBenchmarks,
);

expect(resources.length, 0);
});
Expand All @@ -100,7 +105,12 @@ void main() {
);

final modes = [BenchmarkRunMode.accuracy];
final resources = store.listResources(modes: modes, skipInactive: true);
final activeBenchmarks =
store.benchmarks.where((e) => e.isActive).toList();
final resources = store.listResources(
modes: modes,
benchmarks: activeBenchmarks,
);

expect(resources.length, 3);
expect(
Expand Down Expand Up @@ -132,7 +142,12 @@ void main() {
);

final modes = [BenchmarkRunMode.performance];
final resources = store.listResources(modes: modes);
final activeBenchmarks =
store.benchmarks.where((e) => e.isActive).toList();
final resources = store.listResources(
modes: modes,
benchmarks: activeBenchmarks,
);

expect(resources.length, 2);
expect(
Expand Down Expand Up @@ -161,7 +176,12 @@ void main() {
BenchmarkRunMode.accuracyTest,
BenchmarkRunMode.performanceTest,
];
final resources = store.listResources(modes: modes);
final activeBenchmarks =
store.benchmarks.where((e) => e.isActive).toList();
final resources = store.listResources(
modes: modes,
benchmarks: activeBenchmarks,
);

expect(resources.length, 2);
expect(
Expand Down

0 comments on commit f411947

Please sign in to comment.