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

Side by Side Diff: pkg/compiler/lib/src/common/tasks.dart

Issue 1383483006: Extract DiagnosticReporter implementation from Compiler. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart2js.common.tasks; 5 library dart2js.common.tasks;
6 6
7 import 'dart:profiler' show 7 import 'dart:profiler' show
8 UserTag; 8 UserTag;
9 import '../compiler.dart' show 9 import '../compiler.dart' show
10 Compiler; 10 Compiler;
11 import '../diagnostics/diagnostic_listener.dart' show
12 DiagnosticReporter;
11 import '../elements/elements.dart' show 13 import '../elements/elements.dart' show
12 Element; 14 Element;
13 15
14 typedef void DeferredAction(); 16 typedef void DeferredAction();
15 17
16 class DeferredTask { 18 class DeferredTask {
17 final Element element; 19 final Element element;
18 final DeferredAction action; 20 final DeferredAction action;
19 21
20 DeferredTask(this.element, this.action); 22 DeferredTask(this.element, this.action);
21 } 23 }
22 24
23 class CompilerTask { 25 class CompilerTask {
24 final Compiler compiler; 26 final Compiler compiler;
25 final Stopwatch watch; 27 final Stopwatch watch;
26 UserTag profilerTag; 28 UserTag profilerTag;
27 final Map<String, GenericTask> _subtasks = <String, GenericTask>{}; 29 final Map<String, GenericTask> _subtasks = <String, GenericTask>{};
28 30
29 CompilerTask(Compiler compiler) 31 CompilerTask(Compiler compiler)
30 : this.compiler = compiler, 32 : this.compiler = compiler,
31 watch = (compiler.verbose) ? new Stopwatch() : null; 33 watch = (compiler.verbose) ? new Stopwatch() : null;
32 34
35 DiagnosticReporter get reporter => compiler.reporter;
36
33 String get name => "Unknown task '${this.runtimeType}'"; 37 String get name => "Unknown task '${this.runtimeType}'";
34 38
35 int get timing { 39 int get timing {
36 if (watch == null) return 0; 40 if (watch == null) return 0;
37 int total = watch.elapsedMilliseconds; 41 int total = watch.elapsedMilliseconds;
38 for (GenericTask subtask in _subtasks.values) { 42 for (GenericTask subtask in _subtasks.values) {
39 total += subtask.timing; 43 total += subtask.timing;
40 } 44 }
41 return total; 45 return total;
42 } 46 }
(...skipping 16 matching lines...) Expand all
59 return action(); 63 return action();
60 } finally { 64 } finally {
61 watch.stop(); 65 watch.stop();
62 oldTag.makeCurrent(); 66 oldTag.makeCurrent();
63 if (previous != null) previous.watch.start(); 67 if (previous != null) previous.watch.start();
64 compiler.measuredTask = previous; 68 compiler.measuredTask = previous;
65 } 69 }
66 } 70 }
67 71
68 measureElement(Element element, action()) { 72 measureElement(Element element, action()) {
69 compiler.withCurrentElement(element, () => measure(action)); 73 reporter.withCurrentElement(element, () => measure(action));
70 } 74 }
71 75
72 /// Measure the time spent in [action] (if in verbose mode) and accumulate it 76 /// Measure the time spent in [action] (if in verbose mode) and accumulate it
73 /// under a subtask with the given name. 77 /// under a subtask with the given name.
74 measureSubtask(String name, action()) { 78 measureSubtask(String name, action()) {
75 if (watch == null) return action(); 79 if (watch == null) return action();
76 // Use a nested CompilerTask for the measurement to ensure nested [measure] 80 // Use a nested CompilerTask for the measurement to ensure nested [measure]
77 // calls work correctly. The subtasks will never themselves have nested 81 // calls work correctly. The subtasks will never themselves have nested
78 // subtasks because they are not accessible outside. 82 // subtasks because they are not accessible outside.
79 GenericTask subtask = _subtasks.putIfAbsent(name, 83 GenericTask subtask = _subtasks.putIfAbsent(name,
80 () => new GenericTask(name, compiler)); 84 () => new GenericTask(name, compiler));
81 return subtask.measure(action); 85 return subtask.measure(action);
82 } 86 }
83 87
84 Iterable<String> get subtasks => _subtasks.keys; 88 Iterable<String> get subtasks => _subtasks.keys;
85 89
86 int getSubtaskTime(String subtask) => _subtasks[subtask].timing; 90 int getSubtaskTime(String subtask) => _subtasks[subtask].timing;
87 } 91 }
88 92
89 class GenericTask extends CompilerTask { 93 class GenericTask extends CompilerTask {
90 final String name; 94 final String name;
91 95
92 GenericTask(this.name, Compiler compiler) 96 GenericTask(this.name, Compiler compiler)
93 : super(compiler); 97 : super(compiler);
94 } 98 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698