Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(605)

Unified Diff: pkg/analyzer/lib/src/generated/incremental_logger.dart

Issue 774983003: Add logging to the incremental resolver. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Extract logger into a separate library. Remove dart:io dependency. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analysis_server/lib/driver.dart ('k') | pkg/analyzer/lib/src/generated/incremental_resolver.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/incremental_logger.dart
diff --git a/pkg/analyzer/lib/src/generated/incremental_logger.dart b/pkg/analyzer/lib/src/generated/incremental_logger.dart
new file mode 100644
index 0000000000000000000000000000000000000000..695fbc055c388c9f30b7b673c94c0dddfaac9f4e
--- /dev/null
+++ b/pkg/analyzer/lib/src/generated/incremental_logger.dart
@@ -0,0 +1,113 @@
+// Copyright (c) 2014, 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.
+
+library engine.incremental_logger;
+
+
+/**
+ * The shared instance of [Logger] used by several incremental resolution
+ * classes. It is initialized externally by the Analysis Engine client.
+ */
+Logger logger = new NullLogger();
+
+
+/**
+ * A simple hierarchical logger.
+ */
+abstract class Logger {
+ /**
+ * Mark an enter to a new section with the given [name].
+ */
+ void enter(String name);
+
+ /**
+ * Mark an exit from the current sections, logs the duration.
+ */
+ void exit();
+
+ /**
+ * Logs the given [obj].
+ */
+ void log(Object obj);
+}
+
+
+/**
+ * A [Logger] that does nothing.
+ */
+class NullLogger implements Logger {
+ @override
+ void enter(String name) {
+ }
+
+ @override
+ void exit() {
+ }
+
+ @override
+ void log(Object obj) {
+ }
+}
+
+
+/**
+ * A [Logger] that writes to a [StringSink].
+ */
+class StringSinkLogger implements Logger {
+ static const int _MAX_LINE_LENGTH = 512;
+ final StringSink _sink;
+ final List<_LoggerSection> _sectionStack = <_LoggerSection>[];
+ _LoggerSection _section = new _LoggerSection('', 'ROOT');
+
+ StringSinkLogger(this._sink);
+
+ @override
+ void enter(String name) {
+ log('+++ $name');
+ _sectionStack.add(_section);
+ _section = new _LoggerSection(_section.indent + '\t', name);
+ }
+
+ @override
+ void exit() {
+ DateTime now = new DateTime.now();
+ Duration duration = now.difference(_section.start);
+ String message = '--- ${_section.name} in ${duration.inMilliseconds} ms';
+ _section = _sectionStack.removeLast();
+ log(message);
+ }
+
+ @override
+ void log(Object obj) {
+ DateTime now = new DateTime.now();
+ String indent = _section.indent;
+ String objStr = _getObjectString(obj);
+ String line = '[$now] $indent$objStr';
+ _sink.writeln(line);
+ }
+
+ String _getObjectString(Object obj) {
+ if (obj == null) {
+ return 'null';
+ }
+ String str = obj.toString();
+ if (str.length < _MAX_LINE_LENGTH) {
+ return str;
+ }
+ return str.split('\n').map((String line) {
+ if (line.length > _MAX_LINE_LENGTH) {
+ line = line.substring(0, _MAX_LINE_LENGTH) + '...';
+ }
+ return line;
+ }).join('\n');
+ }
+}
+
+
+class _LoggerSection {
+ final DateTime start = new DateTime.now();
+ final String indent;
+ final String name;
+ _LoggerSection(this.indent, this.name);
+}
« no previous file with comments | « pkg/analysis_server/lib/driver.dart ('k') | pkg/analyzer/lib/src/generated/incremental_resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698