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

Side by Side Diff: tools/testing/dart/dependency_graph.dart

Issue 21001003: test.py: First step towards support of caching dart2js compilations across runtimes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4
5 library dependency_graph;
6
7 import 'dart:async';
8 import 'utils.dart';
9
10 class Graph {
11 final _nodes = new Set<Node>();
12 final _eventController = new StreamController<GraphEvent>();
13 final _stateCounts = new Map<NodeState, int>();
14 var _eventStream;
15 bool _isSealed = false;
16
17 Graph() {
18 _eventStream = _eventController.stream.asBroadcastStream();
19 }
20
21 Iterable<Node> get nodes => _nodes;
22 Stream<GraphEvent> get events => _eventStream;
23 bool get isSealed => _isSealed;
24
25 int stateCount(NodeState state) {
26 int count = _stateCounts[state];
27 return count == null ? 0 : count;
28 }
29
30 void DumpCounts() {
31 for (var state in _stateCounts.keys) {
32 print("Count[$state] = ${_stateCounts[state]}");
33 }
34 }
35
36 void sealGraph() {
37 assert(!_isSealed);
38 _isSealed = true;
39 _emitEvent(new GraphSealedEvent());
40 }
41
42 Node newNode(Object userData, Iterable<Node> dependencies) {
43 assert(!_isSealed);
44
45 var node = new Node._(userData);
46 _nodes.add(node);
47
48 for (var dependency in dependencies) {
49 dependency._neededFor.add(node);
50 node._dependencies.add(dependency);
51 }
52
53 _emitEvent(new NodeAddedEvent(node));
54
55 _stateCounts.putIfAbsent(node.state, () => 0);
56 _stateCounts[node.state] += 1;
57
58 return node;
59 }
60
61 void changeState(Node node, NodeState newState) {
62 var fromState = node.state;
63 node._state = newState;
64
65 _stateCounts[fromState] -= 1;
66 _stateCounts.putIfAbsent(newState, () => 0);
67 _stateCounts[newState] += 1;
68
69 _emitEvent(new StateChangedEvent(node, fromState, newState));
70 }
71
72 _emitEvent(GraphEvent event) {
73 Timer.run(() {
ricow1 2013/07/30 09:30:11 add a comment stating why we do this asynchronousl
kustermann 2013/07/31 15:53:54 Done.
74 _eventController.add(event);
75 });
76 }
77 }
78
79 class Node extends UniqueObject {
ricow1 2013/07/30 09:30:11 I like the fact that these instance variables are
kustermann 2013/07/31 15:53:54 Yes.
80 final Object _userData;
81 NodeState _state = NodeState.Initialized;
82 Set<Node> _dependencies = new Set<Node>();
83 Set<Node> _neededFor = new Set<Node>();
84
85 Node._(this._userData);
86
87 Object get userData => _userData;
88 NodeState get state => _state;
89 Iterable<Node> get dependencies => _dependencies;
90 Iterable<Node> get neededFor => _neededFor;
91 }
92
93 class NodeState extends UniqueObject {
94 static NodeState Initialized = new NodeState._("Initialized");
95 static NodeState Waiting = new NodeState._("Waiting");
96 static NodeState Enqueing = new NodeState._("Enqueing");
ricow1 2013/07/30 09:30:11 Enqueing -> enqueuing
kustermann 2013/07/31 15:53:54 Done.
97 static NodeState Processing = new NodeState._("Running");
98 static NodeState Successfull = new NodeState._("Successfull");
ricow1 2013/07/30 09:30:11 Successfull -> Successful
kustermann 2013/07/31 15:53:54 Done.
99 static NodeState Failed = new NodeState._("Failed");
100 static NodeState UnableToRun = new NodeState._("UnableToRun");
101
102 final String name;
103
104 NodeState._(this.name);
105
106 String toString() => name;
107 }
108
109 abstract class GraphEvent {}
110
111 class GraphSealedEvent extends GraphEvent {}
112
113 class NodeAddedEvent extends GraphEvent {
114 final Node node;
115
116 NodeAddedEvent(this.node);
117 }
118
119 class StateChangedEvent extends GraphEvent {
120 final Node node;
121 final NodeState from;
122 final NodeState to;
123
124 StateChangedEvent(this.node, this.from, this.to);
125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698