From 3238d433faa3e31df2c3a8b671be1e225526e7b0 Mon Sep 17 00:00:00 2001 From: Devon Carew Date: Fri, 20 Aug 2021 21:47:25 +0000 Subject: [PATCH] Revise the SDK size benchmark. Change-Id: Iab9b301737e141a9ad95d4f4e9391a06b5788e6c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210760 Reviewed-by: Ben Konyi Commit-Queue: Devon Carew --- .../dart/SDKArtifactSizes.dart | 48 +++++++++---------- .../dart2/SDKArtifactSizes.dart | 48 +++++++++---------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/benchmarks/SDKArtifactSizes/dart/SDKArtifactSizes.dart b/benchmarks/SDKArtifactSizes/dart/SDKArtifactSizes.dart index 291ad67f178..7deaa33a8ed 100644 --- a/benchmarks/SDKArtifactSizes/dart/SDKArtifactSizes.dart +++ b/benchmarks/SDKArtifactSizes/dart/SDKArtifactSizes.dart @@ -33,9 +33,9 @@ const snapshots = [ 'pub', ]; -Future reportArtifactSize(String path, String name) async { +void reportFileSize(String path, String name) { try { - final size = await File(path).length(); + final size = File(path).lengthSync(); print('SDKArtifactSizes.$name(CodeSize): $size'); } on FileSystemException { // Report dummy data for artifacts that don't exist for specific platforms. @@ -43,43 +43,43 @@ Future reportArtifactSize(String path, String name) async { } } -Future main() async { +void reportDirectorySize(String path, String name) async { + final dir = Directory(path); + + try { + final size = dir + .listSync(recursive: true, followLinks: false) + .whereType() + .map((file) => file.lengthSync()) + .fold(0, (a, b) => a + b); + print('SDKArtifactSizes.$name(CodeSize): $size'); + } on FileSystemException { + // Report dummy data on errors. + print('SDKArtifactSizes.$name(CodeSize): 0'); + } +} + +void main() { final topDirIndex = Platform.resolvedExecutable.lastIndexOf(Platform.pathSeparator); final rootDir = Platform.resolvedExecutable.substring(0, topDirIndex); for (final executable in executables) { final executablePath = '$rootDir/dart-sdk/bin/$executable'; - await reportArtifactSize(executablePath, executable); + reportFileSize(executablePath, executable); } for (final lib in libs) { final libPath = '$rootDir/dart-sdk/lib/_internal/$lib'; - await reportArtifactSize(libPath, lib); + reportFileSize(libPath, lib); } for (final snapshot in snapshots) { final snapshotPath = '$rootDir/dart-sdk/bin/snapshots/$snapshot.dart.snapshot'; - await reportArtifactSize(snapshotPath, snapshot); + reportFileSize(snapshotPath, snapshot); } - // Measure the (compressed) sdk size. - final tempDir = Directory.systemTemp.createTempSync('dartdev'); - final sdkArchive = compress(Directory('$rootDir/dart-sdk'), tempDir); - await reportArtifactSize(sdkArchive?.path ?? '', 'sdk'); - tempDir.deleteSync(recursive: true); -} - -File? compress(Directory sourceDir, Directory targetDir) { - final outFile = File('${targetDir.path}/sdk.zip'); - - if (Platform.isMacOS || Platform.isLinux) { - Process.runSync( - 'zip', ['-r', outFile.absolute.path, sourceDir.absolute.path]); - } else { - return null; - } - - return outFile; + // Measure the sdk size. + reportDirectorySize('$rootDir/dart-sdk', 'sdk'); } diff --git a/benchmarks/SDKArtifactSizes/dart2/SDKArtifactSizes.dart b/benchmarks/SDKArtifactSizes/dart2/SDKArtifactSizes.dart index f5b7f05caaa..71e5a48520e 100644 --- a/benchmarks/SDKArtifactSizes/dart2/SDKArtifactSizes.dart +++ b/benchmarks/SDKArtifactSizes/dart2/SDKArtifactSizes.dart @@ -35,9 +35,9 @@ const snapshots = [ 'pub', ]; -Future reportArtifactSize(String path, String name) async { +void reportFileSize(String path, String name) { try { - final size = await File(path).length(); + final size = File(path).lengthSync(); print('SDKArtifactSizes.$name(CodeSize): $size'); } on FileSystemException { // Report dummy data for artifacts that don't exist for specific platforms. @@ -45,43 +45,43 @@ Future reportArtifactSize(String path, String name) async { } } -Future main() async { +void reportDirectorySize(String path, String name) async { + final dir = Directory(path); + + try { + final size = dir + .listSync(recursive: true, followLinks: false) + .whereType() + .map((file) => file.lengthSync()) + .fold(0, (a, b) => a + b); + print('SDKArtifactSizes.$name(CodeSize): $size'); + } on FileSystemException { + // Report dummy data on errors. + print('SDKArtifactSizes.$name(CodeSize): 0'); + } +} + +void main() { final topDirIndex = Platform.resolvedExecutable.lastIndexOf(Platform.pathSeparator); final rootDir = Platform.resolvedExecutable.substring(0, topDirIndex); for (final executable in executables) { final executablePath = '$rootDir/dart-sdk/bin/$executable'; - await reportArtifactSize(executablePath, executable); + reportFileSize(executablePath, executable); } for (final lib in libs) { final libPath = '$rootDir/dart-sdk/lib/_internal/$lib'; - await reportArtifactSize(libPath, lib); + reportFileSize(libPath, lib); } for (final snapshot in snapshots) { final snapshotPath = '$rootDir/dart-sdk/bin/snapshots/$snapshot.dart.snapshot'; - await reportArtifactSize(snapshotPath, snapshot); + reportFileSize(snapshotPath, snapshot); } - // Measure the (compressed) sdk size. - final tempDir = Directory.systemTemp.createTempSync('dartdev'); - final sdkArchive = compress(Directory('$rootDir/dart-sdk'), tempDir); - await reportArtifactSize(sdkArchive?.path ?? '', 'sdk'); - tempDir.deleteSync(recursive: true); -} - -File compress(Directory sourceDir, Directory targetDir) { - final outFile = File('${targetDir.path}/sdk.zip'); - - if (Platform.isMacOS || Platform.isLinux) { - Process.runSync( - 'zip', ['-r', outFile.absolute.path, sourceDir.absolute.path]); - } else { - return null; - } - - return outFile; + // Measure the sdk size. + reportDirectorySize('$rootDir/dart-sdk', 'sdk'); }