Skip to content

Commit

Permalink
Format devtools_app and devtools_test with the new Dart formatter. (
Browse files Browse the repository at this point in the history
  • Loading branch information
kenzieschmoll authored Nov 21, 2024
1 parent 7ce5efa commit 4a3a921
Show file tree
Hide file tree
Showing 644 changed files with 56,414 additions and 60,202 deletions.
2 changes: 1 addition & 1 deletion flutter-candidate.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fe71cadf1959268ca5dd545863a195d78c232b74
1d01955721fbb5a3cde5beb6e0a0216b457d35ae
6 changes: 4 additions & 2 deletions packages/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ linter:
- prefer_relative_imports
- prefer_single_quotes
- prefer_typing_uninitialized_variables
- require_trailing_commas
# Obsolete with the new Dart formatter.
# - require_trailing_commas
- recursive_getters
- slash_for_doc_comments
- sort_child_properties_last
Expand Down Expand Up @@ -224,7 +225,8 @@ dart_code_metrics:
# - prefer-moving-to-variable:
# allowed-duplicated-chains: 2
# - prefer-static-class
- prefer-trailing-comma
# Obsolete with the new Dart formatter.
# - prefer-trailing-comma
- always-remove-listener
# - avoid-border-all Micro-optimization to avoid a const constructor.
# - avoid-returning-widgets This one is nice but has a lot of false positives.
Expand Down
24 changes: 10 additions & 14 deletions packages/devtools_app/benchmark/devtools_benchmarks_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import 'test_infra/project_root_directory.dart';

const _isWasmScore = 'isWasm';

const _extraScores = [
totalUiFrameAverage,
_isWasmScore,
];
const _extraScores = [totalUiFrameAverage, _isWasmScore];

/// Tests that the DevTools web benchmarks are run and reported correctly.
void main() {
Expand All @@ -43,23 +40,22 @@ Future<void> _runBenchmarks({bool useWasm = false}) async {
final taskResult = await serveWebBenchmark(
benchmarkAppDirectory: projectRootDirectory(),
entryPoint: generateBenchmarkEntryPoint(useWasm: useWasm),
compilationOptions: useWasm
? const CompilationOptions.wasm()
: const CompilationOptions.js(),
compilationOptions:
useWasm
? const CompilationOptions.wasm()
: const CompilationOptions.js(),
treeShakeIcons: false,
benchmarkPath: benchmarkPath(useWasm: useWasm),
);
stdout.writeln('Web benchmark tests finished.');

expect(
taskResult.scores.keys,
hasLength(DevToolsBenchmark.values.length),
);
expect(taskResult.scores.keys, hasLength(DevToolsBenchmark.values.length));

for (final benchmarkName in DevToolsBenchmark.values.map((e) => e.id)) {
final expectedMetrics = expectedBenchmarkMetrics(useWasm: useWasm)
.map((BenchmarkMetric metric) => metric.label)
.toList();
final expectedMetrics =
expectedBenchmarkMetrics(
useWasm: useWasm,
).map((BenchmarkMetric metric) => metric.label).toList();
const expectedComputations = BenchmarkMetricComputation.values;
final scores = taskResult.scores[benchmarkName] ?? [];
expect(
Expand Down
14 changes: 7 additions & 7 deletions packages/devtools_app/benchmark/scripts/args.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ extension BenchmarkArgsExtension on ArgParser {
void addSaveToFileOption(BenchmarkResultsOutputType type) {
addOption(
BenchmarkArgument.saveToFile.flagName,
help: 'Saves the benchmark results to a ${type.name} file at the '
help:
'Saves the benchmark results to a ${type.name} file at the '
'provided path (absolute).',
valueHelp: '/Users/me/Downloads/output.${type.name}',
);
Expand All @@ -39,7 +40,8 @@ extension BenchmarkArgsExtension on ArgParser {
addOption(
BenchmarkArgument.averageOf.flagName,
defaultsTo: '1',
help: 'The number of times to run the benchmark. The returned results '
help:
'The number of times to run the benchmark. The returned results '
'will be the average of all the benchmark runs when this value is '
'greater than 1.',
valueHelp: '5',
Expand All @@ -49,7 +51,8 @@ extension BenchmarkArgsExtension on ArgParser {
void addBaselineOption({String? additionalHelp}) {
addOption(
BenchmarkArgument.baseline.flagName,
help: 'The baseline benchmark data to compare the test benchmark run to. '
help:
'The baseline benchmark data to compare the test benchmark run to. '
'${additionalHelp ?? ''}',
valueHelp: '/Users/me/Downloads/baseline.json',
);
Expand All @@ -73,7 +76,4 @@ enum BenchmarkArgument {
}

/// The file types that benchmark results may be written to.
enum BenchmarkResultsOutputType {
csv,
json,
}
enum BenchmarkResultsOutputType { csv, json }
10 changes: 6 additions & 4 deletions packages/devtools_app/benchmark/scripts/compare_benchmarks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ void main(List<String> args) {
}
}

final baselineResults =
BenchmarkResults.parse(jsonDecode(baselineFile.readAsStringSync()));
final testResults =
BenchmarkResults.parse(jsonDecode(testFile.readAsStringSync()));
final baselineResults = BenchmarkResults.parse(
jsonDecode(baselineFile.readAsStringSync()),
);
final testResults = BenchmarkResults.parse(
jsonDecode(testFile.readAsStringSync()),
);
compareBenchmarks(
baselineResults,
testResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void main(List<String> args) async {

class CsvBuilder {
CsvBuilder({this.saveToLocation})
: assert(saveToLocation == null || saveToLocation.endsWith('.csv'));
: assert(saveToLocation == null || saveToLocation.endsWith('.csv'));

final _sb = StringBuffer();

Expand All @@ -108,26 +108,22 @@ class CsvBuilder {
// TODO(kenz): automatically detect these and write them to the CSV.
const flutter = '<enter manually by running \'flutter --version\'>';
const devtools = '<enter manually by running \'git log\'>';
writeLines(
[
'Version info:',
'Flutter: $flutter',
'DevTools: $devtools',
'',
'Results:',
],
);
writeLines([
'Version info:',
'Flutter: $flutter',
'DevTools: $devtools',
'',
'Results:',
]);

// Write the headers.
writeLine(
[
'Benchmark Name',
'Metric',
'Value (micros)',
'Delta (micros)',
'Delta (%)',
],
);
writeLine([
'Benchmark Name',
'Metric',
'Value (micros)',
'Delta (micros)',
'Delta (%)',
]);
}

void writeLine(List<String> content) {
Expand Down Expand Up @@ -157,11 +153,7 @@ class CsvBuilder {
final downloadsDir = Directory.fromUri(
Uri.parse(
// We need the leading slash so that this is an absolute path.
'/${p.join(
currentDirectoryParts[0],
currentDirectoryParts[1],
'Downloads',
)}',
'/${p.join(currentDirectoryParts[0], currentDirectoryParts[1], 'Downloads')}',
),
);
if (downloadsDir.existsSync()) {
Expand Down Expand Up @@ -233,7 +225,8 @@ class _Args extends BenchmarkArgsBase {
)
..addOption(
BenchmarkArgument.test.flagName,
help: 'The test benchmark data (dart2wasm) to use for this performance'
help:
'The test benchmark data (dart2wasm) to use for this performance'
' diff. When specified, this script will use the benchmark data at '
'the specified path instead of generating a new benchmark run for '
'the dart2wasm data. This file path should point to a JSON file that '
Expand Down
12 changes: 7 additions & 5 deletions packages/devtools_app/benchmark/scripts/run_benchmarks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ Future<BenchmarkResults> runBenchmarks({
await serveWebBenchmark(
benchmarkAppDirectory: projectRootDirectory(),
entryPoint: generateBenchmarkEntryPoint(useWasm: useWasm),
compilationOptions: useWasm
? const CompilationOptions.wasm()
: const CompilationOptions.js(),
compilationOptions:
useWasm
? const CompilationOptions.wasm()
: const CompilationOptions.js(),
treeShakeIcons: false,
benchmarkPath: benchmarkPath(useWasm: useWasm),
headless: !useBrowser,
Expand Down Expand Up @@ -86,8 +87,9 @@ void printAndMaybeSaveResults({
required String? saveToFileLocation,
}) {
final resultsAsMap = benchmarkResults.toJson();
final resultsAsJsonString =
const JsonEncoder.withIndent(' ').convert(resultsAsMap);
final resultsAsJsonString = const JsonEncoder.withIndent(
' ',
).convert(resultsAsMap);

if (saveToFileLocation != null) {
final location = Uri.parse(saveToFileLocation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import '../devtools_recorder.dart';
typedef RecorderFactory = Recorder Function();

final benchmarks = <String, RecorderFactory>{
DevToolsBenchmark.navigateThroughOfflineScreens.id: () => DevToolsRecorder(
DevToolsBenchmark.navigateThroughOfflineScreens.id:
() => DevToolsRecorder(
benchmark: DevToolsBenchmark.navigateThroughOfflineScreens,
),
DevToolsBenchmark.offlineCpuProfilerScreen.id: () => DevToolsRecorder(
DevToolsBenchmark.offlineCpuProfilerScreen.id:
() => DevToolsRecorder(
benchmark: DevToolsBenchmark.offlineCpuProfilerScreen,
),
DevToolsBenchmark.offlinePerformanceScreen.id: () => DevToolsRecorder(
DevToolsBenchmark.offlinePerformanceScreen.id:
() => DevToolsRecorder(
benchmark: DevToolsBenchmark.offlinePerformanceScreen,
),
};
3 changes: 2 additions & 1 deletion packages/devtools_app/benchmark/test_infra/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const _benchmarkInitialPage = '';

const _wasmQueryParameters = {'wasm': 'true'};

String benchmarkPath({required bool useWasm}) => Uri(
String benchmarkPath({required bool useWasm}) =>
Uri(
path: _benchmarkInitialPage,
queryParameters: useWasm ? _wasmQueryParameters : null,
).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'common.dart';
/// A recorder that measures frame building durations for the DevTools.
class DevToolsRecorder extends WidgetRecorder {
DevToolsRecorder({required this.benchmark})
: super(name: benchmark.id, useCustomWarmUp: true);
: super(name: benchmark.id, useCustomWarmUp: true);

/// The name of the DevTools benchmark to be run.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import 'package:path/path.dart' as path;

bool _hasPubspec(Directory directory) {
return directory.listSync().any(
(entity) =>
FileSystemEntity.isFileSync(entity.path) &&
path.basename(entity.path) == 'pubspec.yaml',
);
(entity) =>
FileSystemEntity.isFileSync(entity.path) &&
path.basename(entity.path) == 'pubspec.yaml',
);
}

Directory projectRootDirectory() {
Expand Down
96 changes: 46 additions & 50 deletions packages/devtools_app/benchmark/web_bundle_size_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,58 @@ import 'package:test/test.dart';

// Benchmark size in kB.
const bundleSizeBenchmark = 5200;
const gzipBundleSizeBenchmark = 1500;
const gzipBundleSizeBenchmark = 1550;

void main() {
group('Web Compile', () {
test(
'bundle size',
() async {
final js = path.join(
Directory.current.path,
'build',
'web',
'main.dart.js',
);
test('bundle size', () async {
final js = path.join(
Directory.current.path,
'build',
'web',
'main.dart.js',
);

_logStatus('Building DevTools web app in release mode...');
// These build arguments match the arguments used in the
// tool/lib/commands/build_release.dart command, which is how we build
// DevTools for release.
await _runProcess('flutter', [
'build',
'web',
'--web-renderer',
'canvaskit',
'--pwa-strategy=offline-first',
'--release',
'--no-tree-shake-icons',
]);
_logStatus('Building DevTools web app in release mode...');
// These build arguments match the arguments used in the
// tool/lib/commands/build_release.dart command, which is how we build
// DevTools for release.
await _runProcess('flutter', [
'build',
'web',
'--web-renderer',
'canvaskit',
'--pwa-strategy=offline-first',
'--release',
'--no-tree-shake-icons',
]);

_logStatus('Zipping bundle with gzip...');
await _runProcess('gzip', ['-k', '-f', js]);
_logStatus('Zipping bundle with gzip...');
await _runProcess('gzip', ['-k', '-f', js]);

final bundleSize = await _measureSize(js);
final gzipBundleSize = await _measureSize('$js.gz');
if (bundleSize > bundleSizeBenchmark) {
fail(
'The size the compiled web build "$js" was $bundleSize kB. This is '
'larger than the benchmark that was set at $bundleSizeBenchmark kB.'
'\n\n'
'The build size should be as minimal as possible to reduce the web '
'app\'s initial startup time. If this change is intentional, and'
' expected, please increase the constant "bundleSizeBenchmark".',
);
} else if (gzipBundleSize > gzipBundleSizeBenchmark) {
fail(
'The size the compiled and gzipped web build "$js" was'
' $gzipBundleSize kB. This is larger than the benchmark that was '
'set at $gzipBundleSizeBenchmark kB.\n\n'
'The build size should be as minimal as possible to reduce the '
'web app\'s initial startup time. If this change is intentional, '
'and expected, please increase the constant '
'"gzipBundleSizeBenchmark".',
);
}
},
timeout: const Timeout(Duration(minutes: 5)),
);
final bundleSize = await _measureSize(js);
final gzipBundleSize = await _measureSize('$js.gz');
if (bundleSize > bundleSizeBenchmark) {
fail(
'The size the compiled web build "$js" was $bundleSize kB. This is '
'larger than the benchmark that was set at $bundleSizeBenchmark kB.'
'\n\n'
'The build size should be as minimal as possible to reduce the web '
'app\'s initial startup time. If this change is intentional, and'
' expected, please increase the constant "bundleSizeBenchmark".',
);
} else if (gzipBundleSize > gzipBundleSizeBenchmark) {
fail(
'The size the compiled and gzipped web build "$js" was'
' $gzipBundleSize kB. This is larger than the benchmark that was '
'set at $gzipBundleSizeBenchmark kB.\n\n'
'The build size should be as minimal as possible to reduce the '
'web app\'s initial startup time. If this change is intentional, '
'and expected, please increase the constant '
'"gzipBundleSizeBenchmark".',
);
}
}, timeout: const Timeout(Duration(minutes: 5)));
});
}

Expand Down
Loading

0 comments on commit 4a3a921

Please sign in to comment.