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

Side by Side Diff: tools/android/loading/loading_model.py

Issue 1708223005: Loading model test tweak. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: push up MakeGraph Created 4 years, 10 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
« no previous file with comments | « no previous file | tools/android/loading/loading_model_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 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 """Models for loading in chrome. 5 """Models for loading in chrome.
6 6
7 (Redirect the following to the general model module once we have one) 7 (Redirect the following to the general model module once we have one)
8 A model is an object with the following methods. 8 A model is an object with the following methods.
9 CostMs(): return the cost of the model in milliseconds. 9 CostMs(): return the cost of the model in milliseconds.
10 Set(): set model-specific parameters. 10 Set(): set model-specific parameters.
(...skipping 13 matching lines...) Expand all
24 import dag 24 import dag
25 import loading_trace 25 import loading_trace
26 import request_dependencies_lens 26 import request_dependencies_lens
27 import request_track 27 import request_track
28 28
29 class ResourceGraph(object): 29 class ResourceGraph(object):
30 """A model of loading by a DAG of resource dependencies. 30 """A model of loading by a DAG of resource dependencies.
31 31
32 See model parameters in Set(). 32 See model parameters in Set().
33 """ 33 """
34 # The lens to build request dependencies. Exposed here for subclasses in
35 # unittesting.
36 REQUEST_LENS = request_dependencies_lens.RequestDependencyLens
37
34 EDGE_KIND_KEY = 'edge_kind' 38 EDGE_KIND_KEY = 'edge_kind'
35 EDGE_KINDS = request_track.Request.INITIATORS + ( 39 EDGE_KINDS = request_track.Request.INITIATORS + (
36 'script_inferred', 'after-load', 'before-load', 'timing') 40 'script_inferred', 'after-load', 'before-load', 'timing')
37 def __init__(self, trace, content_lens=None, frame_lens=None, 41 def __init__(self, trace, content_lens=None, frame_lens=None,
38 activity=None): 42 activity=None):
39 """Create from a LoadingTrace (or json of a trace). 43 """Create from a LoadingTrace (or json of a trace).
40 44
41 Args: 45 Args:
42 trace: (LoadingTrace/JSON) Loading trace or JSON of a trace. 46 trace: (LoadingTrace/JSON) Loading trace or JSON of a trace.
43 content_lens: (ContentClassificationLens) Lens used to annotate the 47 content_lens: (ContentClassificationLens) Lens used to annotate the
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 index_by_request[request] = next_index 474 index_by_request[request] = next_index
471 node = dag.Node(next_index) 475 node = dag.Node(next_index)
472 node_info = self._NodeInfo(node, request) 476 node_info = self._NodeInfo(node, request)
473 if self._content_lens: 477 if self._content_lens:
474 node_info.SetRequestContent( 478 node_info.SetRequestContent(
475 self._content_lens.IsAdRequest(request), 479 self._content_lens.IsAdRequest(request),
476 self._content_lens.IsTrackingRequest(request)) 480 self._content_lens.IsTrackingRequest(request))
477 self._nodes.append(node) 481 self._nodes.append(node)
478 self._node_info.append(node_info) 482 self._node_info.append(node_info)
479 483
480 dependencies = request_dependencies_lens.RequestDependencyLens( 484 dependencies = self.REQUEST_LENS(trace).GetRequestDependencies()
481 trace).GetRequestDependencies()
482 for dep in dependencies: 485 for dep in dependencies:
483 (parent_rq, child_rq, reason) = dep 486 (parent_rq, child_rq, reason) = dep
484 parent = self._node_info[index_by_request[parent_rq]] 487 parent = self._node_info[index_by_request[parent_rq]]
485 child = self._node_info[index_by_request[child_rq]] 488 child = self._node_info[index_by_request[child_rq]]
486 edge_cost = request_track.TimeBetween(parent_rq, child_rq, reason) 489 edge_cost = request_track.TimeBetween(parent_rq, child_rq, reason)
487 if edge_cost < 0: 490 if edge_cost < 0:
488 edge_cost = 0 491 edge_cost = 0
489 if child.StartTime() < parent.StartTime(): 492 if child.StartTime() < parent.StartTime():
490 logging.error('Inverted dependency: %s->%s', 493 logging.error('Inverted dependency: %s->%s',
491 parent.ShortName(), child.ShortName()) 494 parent.ShortName(), child.ShortName())
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 """ 610 """
608 image_to_info = {} 611 image_to_info = {}
609 for n in self._node_info: 612 for n in self._node_info:
610 if (n.ContentType() is not None and 613 if (n.ContentType() is not None and
611 n.ContentType().startswith('image') and 614 n.ContentType().startswith('image') and
612 self.FilterAds(n)): 615 self.FilterAds(n)):
613 key = str((n.Url(), n.ShortName(), n.StartTime())) 616 key = str((n.Url(), n.ShortName(), n.StartTime()))
614 assert key not in image_to_info, n.Url() 617 assert key not in image_to_info, n.Url()
615 image_to_info[key] = n 618 image_to_info[key] = n
616 return image_to_info 619 return image_to_info
OLDNEW
« no previous file with comments | « no previous file | tools/android/loading/loading_model_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698