From 9a8c4dfef68b8bcdbf9c29674df5949a480c006a Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Mon, 18 Jun 2018 17:12:14 -0700 Subject: [PATCH] Report compressed/uncompressed size of icudtl, snapshots, and libflutter (#18583) Reported for the hello_world compile benchmark in devicelab for now. --- dev/devicelab/lib/tasks/perf_tests.dart | 86 ++++++++++++++++++++++--- 1 file changed, 78 insertions(+), 8 deletions(-) diff --git a/dev/devicelab/lib/tasks/perf_tests.dart b/dev/devicelab/lib/tasks/perf_tests.dart index 5d81e847e0..d6e45fb311 100644 --- a/dev/devicelab/lib/tasks/perf_tests.dart +++ b/dev/devicelab/lib/tasks/perf_tests.dart @@ -6,6 +6,8 @@ import 'dart:async'; import 'dart:convert' show json; import 'dart:io'; +import 'package:meta/meta.dart'; + import '../framework/adb.dart'; import '../framework/framework.dart'; import '../framework/ios.dart'; @@ -44,7 +46,7 @@ TaskFunction createFlutterGalleryCompileTest() { } TaskFunction createHelloWorldCompileTest() { - return new CompileTest('${flutterDirectory.path}/examples/hello_world').run; + return new CompileTest('${flutterDirectory.path}/examples/hello_world', reportPackageContentSizes: true).run; } TaskFunction createComplexLayoutCompileTest() { @@ -196,9 +198,10 @@ class PerfTest { /// Measures how long it takes to compile a Flutter app and how big the compiled /// code is. class CompileTest { - const CompileTest(this.testDirectory); + const CompileTest(this.testDirectory, { this.reportPackageContentSizes = false }); final String testDirectory; + final bool reportPackageContentSizes; Future run() async { return await inDirectory(testDirectory, () async { @@ -208,7 +211,7 @@ class CompileTest { final Map metrics = {} ..addAll(await _compileAot()) - ..addAll(await _compileApp()) + ..addAll(await _compileApp(reportPackageContentSizes: reportPackageContentSizes)) ..addAll(await _compileDebug()) ..addAll(_suffix(await _compileAot(previewDart2: false), '__dart1')) ..addAll(_suffix(await _compileApp(previewDart2: false), '__dart1')) @@ -266,7 +269,7 @@ class CompileTest { return metrics; } - static Future> _compileApp({ bool previewDart2 = true }) async { + static Future> _compileApp({ bool previewDart2 = true, bool reportPackageContentSizes = false }) async { await flutter('clean'); final Stopwatch watch = new Stopwatch(); int releaseSizeInBytes; @@ -276,6 +279,8 @@ class CompileTest { else options.add('--no-preview-dart-2'); setLocalEngineOptionIfNecessary(options); + final Map metrics = {}; + switch (deviceOperatingSystem) { case DeviceOperatingSystem.ios: options.insert(0, 'ios'); @@ -292,19 +297,25 @@ class CompileTest { watch.start(); await flutter('build', options: options); watch.stop(); - File apk = file('$cwd/build/app/outputs/apk/app.apk'); + String apkPath = '$cwd/build/app/outputs/apk/app.apk'; + File apk = file(apkPath); if (!apk.existsSync()) { // Pre Android SDK 26 path - apk = file('$cwd/build/app/outputs/apk/app-release.apk'); + apkPath = '$cwd/build/app/outputs/apk/app-release.apk'; + apk = file(apkPath); } releaseSizeInBytes = apk.lengthSync(); + if (reportPackageContentSizes) + metrics.addAll(await getSizesFromApk(apkPath)); break; } - return { + metrics.addAll({ 'release_full_compile_millis': watch.elapsedMilliseconds, 'release_size_bytes': releaseSizeInBytes, - }; + }); + + return metrics; } static Future> _compileDebug({ bool previewDart2 = true }) async { @@ -349,6 +360,40 @@ class CompileTest { return _kSdkNameToMetricNameMapping[sdkName]; } + + static Future> getSizesFromApk(String apkPath) async { + final String output = await eval('unzip', ['-v', apkPath]); + final List lines = output.split('\n'); + final Map fileToMetadata = {}; + + // First three lines are header, last two lines are footer. + for (int i = 3; i < lines.length - 2; i++) { + final _UnzipListEntry entry = new _UnzipListEntry.fromLine(lines[i]); + fileToMetadata[entry.path] = entry; + } + + final _UnzipListEntry icudtl = fileToMetadata['assets/icudtl.dat']; + final _UnzipListEntry libflutter = fileToMetadata['lib/armeabi-v7a/libflutter.so']; + final _UnzipListEntry isolateSnapshotData = fileToMetadata['assets/isolate_snapshot_data']; + final _UnzipListEntry isolateSnapshotInstr = fileToMetadata['assets/isolate_snapshot_instr']; + final _UnzipListEntry vmSnapshotData = fileToMetadata['assets/vm_snapshot_data']; + final _UnzipListEntry vmSnapshotInstr = fileToMetadata['assets/vm_snapshot_instr']; + + return { + 'icudtl_uncompressed_bytes': icudtl.uncompressedSize, + 'icudtl_compressed_bytes': icudtl.compressedSize, + 'libflutter_uncompressed_bytes': libflutter.uncompressedSize, + 'libflutter_compressed_bytes': libflutter.compressedSize, + 'snapshot_uncompressed_bytes': isolateSnapshotData.uncompressedSize + + isolateSnapshotInstr.uncompressedSize + + vmSnapshotData.uncompressedSize + + vmSnapshotInstr.uncompressedSize, + 'snapshot_compressed_bytes': isolateSnapshotData.compressedSize + + isolateSnapshotInstr.compressedSize + + vmSnapshotData.compressedSize + + vmSnapshotInstr.compressedSize, + }; + } } /// Measure application memory usage. @@ -471,3 +516,28 @@ class AndroidBackButtonMemoryTest { }); } } + +class _UnzipListEntry { + factory _UnzipListEntry.fromLine(String line) { + final List data = line.trim().split(new RegExp('\\s+')); + assert(data.length == 8); + return new _UnzipListEntry._( + uncompressedSize: int.parse(data[0]), + compressedSize: int.parse(data[2]), + path: data[7], + ); + } + + _UnzipListEntry._({ + @required this.uncompressedSize, + @required this.compressedSize, + @required this.path, + }) : assert(uncompressedSize != null), + assert(compressedSize != null), + assert(compressedSize <= uncompressedSize), + assert(path != null); + + final int uncompressedSize; + final int compressedSize; + final String path; +}