Chromium Code Reviews

Unified Diff: sdk/lib/_internal/pub/lib/src/utils.dart

Issue 600293002: Add some additional annotations for tracking pub performance. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Index: sdk/lib/_internal/pub/lib/src/utils.dart
diff --git a/sdk/lib/_internal/pub/lib/src/utils.dart b/sdk/lib/_internal/pub/lib/src/utils.dart
index aea04010794a0f3284673ed13b826bed1c4ca84c..4daec903e75bca57081a61caad8008ec9e37dba0 100644
--- a/sdk/lib/_internal/pub/lib/src/utils.dart
+++ b/sdk/lib/_internal/pub/lib/src/utils.dart
@@ -163,6 +163,16 @@ String padRight(String source, int length) {
return result.toString();
}
+/// Pads [source] to [length] by adding [char]s at the beginning.
+///
+/// If [char] is `null`, it defaults to a space.
+String padLeft(String source, int length, [String char]) {
+ if (char == null) char = ' ';
+ if (source.length >= length) return source;
+
+ return char * (length - source.length) + source;
+}
+
/// Returns a labelled sentence fragment starting with [name] listing the
/// elements [iter].
///
@@ -707,8 +717,17 @@ String niceDuration(Duration duration) {
var result = duration.inMinutes > 0 ? "${duration.inMinutes}:" : "";
var s = duration.inSeconds % 59;
- var ms = (duration.inMilliseconds % 1000) ~/ 100;
- return result + "$s.${ms}s";
+ var ms = duration.inMilliseconds % 1000;
+
+ // If we're using verbose logging, be more verbose but more accurate when
+ // reporting timing information.
+ if (log.verbosity.isLevelVisible(log.Level.FINE)) {
+ ms = padLeft(ms.toString(), 3, '0');
+ } else {
+ ms ~/= 100;
+ }
+
+ return "$result$s.${ms}s";
}
/// Decodes a URL-encoded string.
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/entrypoint.dart ('k') | sdk/lib/_internal/pub_generated/lib/src/barback/asset_environment.dart » ('j') | no next file with comments »

Powered by Google App Engine