This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tool to get breakdown of deferred libraries by size
R=sigmund@google.com Review URL: https://codereview.chromium.org//2201903004 .
- Loading branch information
1 parent
44ab8ea
commit 75d3e7b
Showing
13 changed files
with
135 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.buildlog | ||
.DS_Store | ||
.idea | ||
*.iml | ||
.pub/ | ||
.settings/ | ||
build/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
/// This tool gives a breakdown of code size by deferred part in the program. | ||
library dart2js_info.bin.deferred_library_size; | ||
|
||
import 'dart:math'; | ||
|
||
import 'package:dart2js_info/info.dart'; | ||
import 'package:dart2js_info/src/util.dart'; | ||
|
||
main(args) async { | ||
// TODO(het): Would be faster to only parse the 'outputUnits' part | ||
var info = await infoFromFile(args.first); | ||
var sizeByImport = getSizeByImport(info); | ||
printSizes(sizeByImport, info.program.size); | ||
} | ||
|
||
class ImportSize { | ||
final String import; | ||
final int size; | ||
|
||
const ImportSize(this.import, this.size); | ||
|
||
String toString() { | ||
return '$import: $size'; | ||
} | ||
} | ||
|
||
void printSizes(Map<String, int> sizeByImport, int programSize) { | ||
var importSizes = <ImportSize>[]; | ||
sizeByImport.forEach((import, size) { | ||
importSizes.add(new ImportSize(import, size)); | ||
}); | ||
// Sort by size, largest first. | ||
importSizes.sort((a, b) => b.size - a.size); | ||
var longest = importSizes.fold('Percent of code deferred'.length, | ||
(longest, importSize) => max(longest, importSize.import.length)); | ||
|
||
_printRow(label, data, {int width: 15}) { | ||
print('${label.toString().padRight(longest + 1)}' | ||
'${data.toString().padLeft(width)}'); | ||
} | ||
|
||
print(''); | ||
print('Size by library'); | ||
print('-' * (longest + 16)); | ||
for (var importSize in importSizes) { | ||
// TODO(het): split into specific and shared size | ||
_printRow(importSize.import, importSize.size); | ||
} | ||
print('-' * (longest + 16)); | ||
|
||
var mainChunkSize = sizeByImport['main']; | ||
var deferredSize = programSize - mainChunkSize; | ||
var percentDeferred = (deferredSize * 100 / programSize).toStringAsFixed(2); | ||
_printRow('Main chunk size', mainChunkSize); | ||
_printRow('Deferred code size', deferredSize); | ||
_printRow('Percent of code deferred', '$percentDeferred%'); | ||
} | ||
|
||
Map<String, int> getSizeByImport(AllInfo info) { | ||
var sizeByImport = <String, int>{}; | ||
for (var outputUnit in info.outputUnits) { | ||
if (outputUnit.name == 'main' || outputUnit.name == null) { | ||
sizeByImport['main'] = outputUnit.size; | ||
} else { | ||
for (var import in outputUnit.imports) { | ||
sizeByImport.putIfAbsent(import, () => 0); | ||
sizeByImport[import] += outputUnit.size; | ||
} | ||
} | ||
} | ||
return sizeByImport; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters