improve the logger ui a bit for elapsed times (#7960)
* improve the logger ui a bit for elapsed times * invert param * update daemon.dart
This commit is contained in:
@@ -151,7 +151,7 @@ Future<String> ensureGradlew() async {
|
||||
? <String>[gradle, 'wrapper']
|
||||
: <String>[gradle, '-q', 'wrapper'];
|
||||
try {
|
||||
Status status = logger.startProgress('Running \'gradle wrapper\'...');
|
||||
Status status = logger.startProgress('Running \'gradle wrapper\'...', expectSlowOperation: true);
|
||||
int exitcode = await runCommandAndStreamOutput(
|
||||
command,
|
||||
workingDirectory: 'android',
|
||||
@@ -204,7 +204,7 @@ Future<Null> buildGradleProject(BuildMode buildMode) async {
|
||||
|
||||
Future<Null> buildGradleProjectV1(String gradlew) async {
|
||||
// Run 'gradlew build'.
|
||||
Status status = logger.startProgress('Running \'gradlew build\'...');
|
||||
Status status = logger.startProgress('Running \'gradlew build\'...', expectSlowOperation: true);
|
||||
int exitcode = await runCommandAndStreamOutput(
|
||||
<String>[fs.file(gradlew).absolute.path, 'build'],
|
||||
workingDirectory: 'android',
|
||||
@@ -223,7 +223,7 @@ Future<Null> buildGradleProjectV2(String gradlew, String buildModeName) async {
|
||||
String assembleTask = "assemble${toTitleCase(buildModeName)}";
|
||||
|
||||
// Run 'gradlew assemble<BuildMode>'.
|
||||
Status status = logger.startProgress('Running \'gradlew $assembleTask\'...');
|
||||
Status status = logger.startProgress('Running \'gradlew $assembleTask\'...', expectSlowOperation: true);
|
||||
String gradlewPath = fs.file(gradlew).absolute.path;
|
||||
List<String> command = logger.isVerbose
|
||||
? <String>[gradlewPath, assembleTask]
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:stack_trace/stack_trace.dart';
|
||||
|
||||
import 'io.dart';
|
||||
import 'platform.dart';
|
||||
import 'utils.dart';
|
||||
|
||||
final AnsiTerminal terminal = new AnsiTerminal();
|
||||
|
||||
@@ -38,11 +39,11 @@ abstract class Logger {
|
||||
///
|
||||
/// [message] is the message to display to the user; [progressId] provides an ID which can be
|
||||
/// used to identify this type of progress (`hot.reload`, `hot.restart`, ...).
|
||||
Status startProgress(String message, { String progressId });
|
||||
Status startProgress(String message, { String progressId, bool expectSlowOperation: false });
|
||||
}
|
||||
|
||||
class Status {
|
||||
void stop({ bool showElapsedTime: true }) { }
|
||||
void stop() { }
|
||||
void cancel() { }
|
||||
}
|
||||
|
||||
@@ -81,13 +82,13 @@ class StdoutLogger extends Logger {
|
||||
void printTrace(String message) { }
|
||||
|
||||
@override
|
||||
Status startProgress(String message, { String progressId }) {
|
||||
Status startProgress(String message, { String progressId, bool expectSlowOperation: false }) {
|
||||
if (_status != null) {
|
||||
// Ignore nested progresses; return a no-op status object.
|
||||
return new Status();
|
||||
} else {
|
||||
if (supportsColor) {
|
||||
_status = new _AnsiStatus(message, () { _status = null; });
|
||||
_status = new _AnsiStatus(message, expectSlowOperation, () { _status = null; });
|
||||
return _status;
|
||||
} else {
|
||||
printStatus(message);
|
||||
@@ -124,7 +125,7 @@ class BufferLogger extends Logger {
|
||||
void printTrace(String message) => _trace.writeln(message);
|
||||
|
||||
@override
|
||||
Status startProgress(String message, { String progressId }) {
|
||||
Status startProgress(String message, { String progressId, bool expectSlowOperation: false }) {
|
||||
printStatus(message);
|
||||
return new Status();
|
||||
}
|
||||
@@ -156,7 +157,7 @@ class VerboseLogger extends Logger {
|
||||
}
|
||||
|
||||
@override
|
||||
Status startProgress(String message, { String progressId }) {
|
||||
Status startProgress(String message, { String progressId, bool expectSlowOperation: false }) {
|
||||
printStatus(message);
|
||||
return new Status();
|
||||
}
|
||||
@@ -249,10 +250,10 @@ class AnsiTerminal {
|
||||
}
|
||||
|
||||
class _AnsiStatus extends Status {
|
||||
_AnsiStatus(this.message, this.onFinish) {
|
||||
_AnsiStatus(this.message, this.expectSlowOperation, this.onFinish) {
|
||||
stopwatch = new Stopwatch()..start();
|
||||
|
||||
stdout.write('${message.padRight(51)} ');
|
||||
stdout.write('${message.padRight(52)} ');
|
||||
stdout.write('${_progress[0]}');
|
||||
|
||||
timer = new Timer.periodic(new Duration(milliseconds: 100), _callback);
|
||||
@@ -261,6 +262,7 @@ class _AnsiStatus extends Status {
|
||||
static final List<String> _progress = <String>['-', r'\', '|', r'/', '-', r'\', '|', '/'];
|
||||
|
||||
final String message;
|
||||
final bool expectSlowOperation;
|
||||
final _FinishCallback onFinish;
|
||||
Stopwatch stopwatch;
|
||||
Timer timer;
|
||||
@@ -273,17 +275,18 @@ class _AnsiStatus extends Status {
|
||||
}
|
||||
|
||||
@override
|
||||
void stop({ bool showElapsedTime: true }) {
|
||||
void stop() {
|
||||
onFinish();
|
||||
|
||||
if (!live)
|
||||
return;
|
||||
live = false;
|
||||
|
||||
if (showElapsedTime) {
|
||||
print('\b\b\b\b\b${stopwatch.elapsedMilliseconds.toString().padLeft(3)}ms');
|
||||
if (expectSlowOperation) {
|
||||
double seconds = stopwatch.elapsedMilliseconds / Duration.MILLISECONDS_PER_SECOND;
|
||||
print('\b\b\b\b\b${seconds.toStringAsFixed(1).padLeft(4)}s');
|
||||
} else {
|
||||
print('\b ');
|
||||
print('\b\b\b\b\b${printWithSeparators(stopwatch.elapsedMilliseconds).toString().padLeft(3)}ms');
|
||||
}
|
||||
|
||||
timer.cancel();
|
||||
|
||||
@@ -54,6 +54,19 @@ String toTitleCase(String str) {
|
||||
/// Return the plural of the given word (`cat(s)`).
|
||||
String pluralize(String word, int count) => count == 1 ? word : word + 's';
|
||||
|
||||
/// Return the value printed with commas every 3 digits.
|
||||
String printWithSeparators(int value) {
|
||||
String str = '$value';
|
||||
|
||||
int index = 3;
|
||||
while (index < str.length) {
|
||||
str = str.substring(0, str.length - index) + ',' + str.substring(str.length - index);
|
||||
index += 4;
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
/// Return the name of an enum item.
|
||||
String getEnumName(dynamic enumItem) {
|
||||
String name = '$enumItem';
|
||||
|
||||
@@ -222,7 +222,7 @@ class MaterialFonts {
|
||||
}
|
||||
|
||||
Future<Null> download() {
|
||||
Status status = logger.startProgress('Downloading Material fonts...');
|
||||
Status status = logger.startProgress('Downloading Material fonts...', expectSlowOperation: true);
|
||||
|
||||
Directory fontsDir = cache.getArtifactDirectory(kName);
|
||||
if (fontsDir.existsSync())
|
||||
@@ -373,7 +373,7 @@ class FlutterEngine {
|
||||
}
|
||||
|
||||
Future<Null> _downloadItem(String message, String url, Directory dest) {
|
||||
Status status = logger.startProgress(message);
|
||||
Status status = logger.startProgress(message, expectSlowOperation: true);
|
||||
return Cache._downloadFileToCache(Uri.parse(url), dest, true).then<Null>((Null value) {
|
||||
status.stop();
|
||||
}).whenComplete(() {
|
||||
|
||||
@@ -52,7 +52,8 @@ class BuildAotCommand extends BuildSubCommand {
|
||||
throwToolExit('Unknown platform: $targetPlatform');
|
||||
|
||||
String typeName = path.basename(tools.getEngineArtifactsDirectory(platform, getBuildMode()).path);
|
||||
Status status = logger.startProgress('Building AOT snapshot in ${getModeName(getBuildMode())} mode ($typeName)...');
|
||||
Status status = logger.startProgress('Building AOT snapshot in ${getModeName(getBuildMode())} mode ($typeName)...',
|
||||
expectSlowOperation: true);
|
||||
String outputPath = await buildAotSnapshot(
|
||||
findMainDartFile(targetFile),
|
||||
platform,
|
||||
|
||||
@@ -534,7 +534,8 @@ Future<Null> buildAndroid(
|
||||
throwToolExit('Failure building APK: unable to find components.');
|
||||
|
||||
String typeName = path.basename(tools.getEngineArtifactsDirectory(platform, buildMode).path);
|
||||
Status status = logger.startProgress('Building APK in ${getModeName(buildMode)} mode ($typeName)...');
|
||||
Status status = logger.startProgress('Building APK in ${getModeName(buildMode)} mode ($typeName)...',
|
||||
expectSlowOperation: true);
|
||||
|
||||
if (flxPath != null && flxPath.isNotEmpty) {
|
||||
if (!fs.isFileSync(flxPath)) {
|
||||
|
||||
@@ -65,7 +65,8 @@ class BuildIOSCommand extends BuildSubCommand {
|
||||
String logTarget = forSimulator ? 'simulator' : 'device';
|
||||
|
||||
String typeName = path.basename(tools.getEngineArtifactsDirectory(TargetPlatform.ios, getBuildMode()).path);
|
||||
Status status = logger.startProgress('Building $app for $logTarget ($typeName)...');
|
||||
Status status = logger.startProgress('Building $app for $logTarget ($typeName)...',
|
||||
expectSlowOperation: true);
|
||||
XcodeBuildResult result = await buildXcodeProject(
|
||||
app: app,
|
||||
mode: getBuildMode(),
|
||||
|
||||
@@ -690,7 +690,7 @@ class NotifyingLogger extends Logger {
|
||||
}
|
||||
|
||||
@override
|
||||
Status startProgress(String message, { String progressId }) {
|
||||
Status startProgress(String message, { String progressId, bool expectSlowOperation: false }) {
|
||||
printStatus(message);
|
||||
return new Status();
|
||||
}
|
||||
@@ -776,7 +776,7 @@ class _AppRunLogger extends Logger {
|
||||
Status _status;
|
||||
|
||||
@override
|
||||
Status startProgress(String message, { String progressId }) {
|
||||
Status startProgress(String message, { String progressId, bool expectSlowOperation: false }) {
|
||||
// Ignore nested progresses; return a no-op status object.
|
||||
if (_status != null)
|
||||
return new Status();
|
||||
@@ -820,7 +820,7 @@ class _AppLoggerStatus implements Status {
|
||||
final String progressId;
|
||||
|
||||
@override
|
||||
void stop({ bool showElapsedTime: true }) {
|
||||
void stop() {
|
||||
logger._status = null;
|
||||
_sendFinished();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class UpdatePackagesCommand extends FlutterCommand {
|
||||
final bool hidden;
|
||||
|
||||
Future<Null> _downloadCoverageData() async {
|
||||
Status status = logger.startProgress("Downloading lcov data for package:flutter...");
|
||||
Status status = logger.startProgress("Downloading lcov data for package:flutter...", expectSlowOperation: true);
|
||||
final List<int> data = await fetchUrl(Uri.parse('https://storage.googleapis.com/flutter_infra/flutter/coverage/lcov.info'));
|
||||
final String coverageDir = path.join(Cache.flutterRoot, 'packages/flutter/coverage');
|
||||
fs.file(path.join(coverageDir, 'lcov.base.info'))
|
||||
|
||||
@@ -47,7 +47,8 @@ Future<Null> pubGet({
|
||||
|
||||
if (!checkLastModified || _shouldRunPubGet(pubSpecYaml: pubSpecYaml, dotPackages: dotPackages)) {
|
||||
String command = upgrade ? 'upgrade' : 'get';
|
||||
Status status = logger.startProgress("Running 'flutter packages $command' in ${path.basename(directory)}...");
|
||||
Status status = logger.startProgress("Running 'flutter packages $command' in ${path.basename(directory)}...",
|
||||
expectSlowOperation: true);
|
||||
int code = await runCommandAndStreamOutput(
|
||||
<String>[sdkBinaryName('pub'), '--verbosity=warning', command, '--no-packages-dir', '--no-precompile'],
|
||||
workingDirectory: directory,
|
||||
|
||||
@@ -6,6 +6,19 @@ import 'package:flutter_tools/src/base/utils.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
void main() {
|
||||
group('utils', () {
|
||||
test('printWithSeparators', () {
|
||||
expect(printWithSeparators(3), '3');
|
||||
expect(printWithSeparators(33), '33');
|
||||
expect(printWithSeparators(333), '333');
|
||||
expect(printWithSeparators(3333), '3,333');
|
||||
expect(printWithSeparators(33333), '33,333');
|
||||
expect(printWithSeparators(333333), '333,333');
|
||||
expect(printWithSeparators(3333333), '3,333,333');
|
||||
expect(printWithSeparators(33333333), '33,333,333');
|
||||
});
|
||||
});
|
||||
|
||||
group('SettingsFile', () {
|
||||
test('parse', () {
|
||||
SettingsFile file = new SettingsFile.parse('''
|
||||
|
||||
Reference in New Issue
Block a user