OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Request dependency graph.""" | 5 """Request dependency graph.""" |
6 | 6 |
7 import graph | 7 import graph |
8 import request_track | 8 import request_track |
9 | 9 |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 for (parent_request, child_request, reason) in deps: | 39 for (parent_request, child_request, reason) in deps: |
40 if (parent_request.request_id not in self._nodes_by_id | 40 if (parent_request.request_id not in self._nodes_by_id |
41 or child_request.request_id not in self._nodes_by_id): | 41 or child_request.request_id not in self._nodes_by_id): |
42 continue | 42 continue |
43 parent_node = self._nodes_by_id[parent_request.request_id] | 43 parent_node = self._nodes_by_id[parent_request.request_id] |
44 child_node = self._nodes_by_id[child_request.request_id] | 44 child_node = self._nodes_by_id[child_request.request_id] |
45 edges.append(_Edge(parent_node, child_node, reason)) | 45 edges.append(_Edge(parent_node, child_node, reason)) |
46 self._first_request_node = self._nodes_by_id[self._requests[0].request_id] | 46 self._first_request_node = self._nodes_by_id[self._requests[0].request_id] |
47 self._deps_graph = graph.DirectedGraph(self._nodes_by_id.values(), edges) | 47 self._deps_graph = graph.DirectedGraph(self._nodes_by_id.values(), edges) |
48 | 48 |
| 49 @property |
| 50 def graph(self): |
| 51 """Return the Graph we're based on.""" |
| 52 return self._deps_graph |
| 53 |
49 def UpdateRequestsCost(self, request_id_to_cost): | 54 def UpdateRequestsCost(self, request_id_to_cost): |
50 """Updates the cost of the nodes identified by their request ID. | 55 """Updates the cost of the nodes identified by their request ID. |
51 | 56 |
52 Args: | 57 Args: |
53 request_id_to_cost: {request_id: new_cost} Can be a superset of the | 58 request_id_to_cost: {request_id: new_cost} Can be a superset of the |
54 requests actually present in the graph. | 59 requests actually present in the graph. |
55 | 60 |
56 """ | 61 """ |
57 for node in self._deps_graph.Nodes(): | 62 for node in self._deps_graph.Nodes(): |
58 request_id = node.request.request_id | 63 request_id = node.request.request_id |
59 if request_id in request_id_to_cost: | 64 if request_id in request_id_to_cost: |
60 node.cost = request_id_to_cost[request_id] | 65 node.cost = request_id_to_cost[request_id] |
61 | 66 |
62 def Cost(self, from_first_request=True): | 67 def Cost(self, from_first_request=True): |
63 """Returns the cost of the graph, that is the costliest path. | 68 """Returns the cost of the graph, that is the costliest path. |
64 | 69 |
65 Args: | 70 Args: |
66 from_first_request: (boolean) If True, only considers paths that originate | 71 from_first_request: (boolean) If True, only considers paths that originate |
67 from the first request node. | 72 from the first request node. |
68 """ | 73 """ |
69 if from_first_request: | 74 if from_first_request: |
70 return self._deps_graph.Cost([self._first_request_node]) | 75 return self._deps_graph.Cost([self._first_request_node]) |
71 else: | 76 else: |
72 return self._deps_graph.Cost() | 77 return self._deps_graph.Cost() |
OLD | NEW |