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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
Index: tools/testing/dart/dependency_graph.dart
diff --git a/tools/testing/dart/dependency_graph.dart b/tools/testing/dart/dependency_graph.dart
new file mode 100644
index 0000000000000000000000000000000000000000..bc0a6218780f192ce7a9b8ba550c61701df31f9d
--- /dev/null
+++ b/tools/testing/dart/dependency_graph.dart
@@ -0,0 +1,125 @@
+// Copyright (c) 2013, 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 dependency_graph;
+
+import 'dart:async';
+import 'utils.dart';
+
+class Graph {
+ final _nodes = new Set<Node>();
+ final _eventController = new StreamController<GraphEvent>();
+ final _stateCounts = new Map<NodeState, int>();
+ var _eventStream;
+ bool _isSealed = false;
+
+ Graph() {
+ _eventStream = _eventController.stream.asBroadcastStream();
+ }
+
+ Iterable<Node> get nodes => _nodes;
+ Stream<GraphEvent> get events => _eventStream;
+ bool get isSealed => _isSealed;
+
+ int stateCount(NodeState state) {
+ int count = _stateCounts[state];
+ return count == null ? 0 : count;
+ }
+
+ void DumpCounts() {
+ for (var state in _stateCounts.keys) {
+ print("Count[$state] = ${_stateCounts[state]}");
+ }
+ }
+
+ void sealGraph() {
+ assert(!_isSealed);
+ _isSealed = true;
+ _emitEvent(new GraphSealedEvent());
+ }
+
+ Node newNode(Object userData, Iterable<Node> dependencies) {
+ assert(!_isSealed);
+
+ var node = new Node._(userData);
+ _nodes.add(node);
+
+ for (var dependency in dependencies) {
+ dependency._neededFor.add(node);
+ node._dependencies.add(dependency);
+ }
+
+ _emitEvent(new NodeAddedEvent(node));
+
+ _stateCounts.putIfAbsent(node.state, () => 0);
+ _stateCounts[node.state] += 1;
+
+ return node;
+ }
+
+ void changeState(Node node, NodeState newState) {
+ var fromState = node.state;
+ node._state = newState;
+
+ _stateCounts[fromState] -= 1;
+ _stateCounts.putIfAbsent(newState, () => 0);
+ _stateCounts[newState] += 1;
+
+ _emitEvent(new StateChangedEvent(node, fromState, newState));
+ }
+
+ _emitEvent(GraphEvent event) {
+ 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.
+ _eventController.add(event);
+ });
+ }
+}
+
+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.
+ final Object _userData;
+ NodeState _state = NodeState.Initialized;
+ Set<Node> _dependencies = new Set<Node>();
+ Set<Node> _neededFor = new Set<Node>();
+
+ Node._(this._userData);
+
+ Object get userData => _userData;
+ NodeState get state => _state;
+ Iterable<Node> get dependencies => _dependencies;
+ Iterable<Node> get neededFor => _neededFor;
+}
+
+class NodeState extends UniqueObject {
+ static NodeState Initialized = new NodeState._("Initialized");
+ static NodeState Waiting = new NodeState._("Waiting");
+ static NodeState Enqueing = new NodeState._("Enqueing");
ricow1 2013/07/30 09:30:11 Enqueing -> enqueuing
kustermann 2013/07/31 15:53:54 Done.
+ static NodeState Processing = new NodeState._("Running");
+ static NodeState Successfull = new NodeState._("Successfull");
ricow1 2013/07/30 09:30:11 Successfull -> Successful
kustermann 2013/07/31 15:53:54 Done.
+ static NodeState Failed = new NodeState._("Failed");
+ static NodeState UnableToRun = new NodeState._("UnableToRun");
+
+ final String name;
+
+ NodeState._(this.name);
+
+ String toString() => name;
+}
+
+abstract class GraphEvent {}
+
+class GraphSealedEvent extends GraphEvent {}
+
+class NodeAddedEvent extends GraphEvent {
+ final Node node;
+
+ NodeAddedEvent(this.node);
+}
+
+class StateChangedEvent extends GraphEvent {
+ final Node node;
+ final NodeState from;
+ final NodeState to;
+
+ StateChangedEvent(this.node, this.from, this.to);
+}

Powered by Google App Engine
This is Rietveld 408576698