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

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

Issue 1813723002: clovis: Identify prefetchable resources from dependencies and tracing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 4 years, 9 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 | « tools/android/loading/activity_lens.py ('k') | tools/android/loading/prefetch_view_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
(Empty)
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
3 # found in the LICENSE file.
4
5 """Models the effect of NoState Prefetch from a loading trace.
blundell 2016/03/21 10:07:18 Nit: prefetch_view is a quite generic name. Maybe
blundell 2016/03/21 10:22:04 Also, let's provide a one-sentence description of
Benoit L 2016/03/22 09:32:23 This is intended to simulate prefetch in a generic
6
7 When executed as a script, takes a trace as a command-line arguments and shows
8 how many requests were prefetched.
9 """
10
11 import itertools
12 import operator
13
14 import loading_trace
15 import request_dependencies_lens
16
17
18 class PrefetchSimulationView(object):
19 """Simulates the effect of prefetching resources discoverable by the preload
20 scanner.
21 """
22 def __init__(self, trace, dependencies_lens):
23 """Initializes an instance of PrefetchSimulationView.
24
25 Args:
26 trace: (LoadingTrace) a loading trace.
27 dependencies_lens: (RequestDependencyLens) request dependencies.
28 """
29 self.trace = trace
30 self.dependencies_lens = dependencies_lens
31 self._resource_events = self.trace.tracing_track.Filter(
32 categories=set([u'blink.net']))
33 assert len(self._resource_events.GetEvents()) > 0,\
34 'Was the "blink.net" category enabled at trace collection time?"'
35
36 def ParserDiscoverableRequests(self, request, recurse=False):
blundell 2016/03/21 10:47:16 Should/could this eventually be the same code that
mattcary 2016/03/21 10:54:44 That's an interesting general question: should our
gabadie 2016/03/21 12:55:45 Fly by comment: Sandwich is currently simulating t
37 """Returns a list of requests discovered by the parser from a given request.
38
39 Args:
40 request: (Request) Root request.
41
42 Returns:
43 [Request]
44 """
45 # TODO(lizeb): handle the recursive case.
46 assert not recurse
47 discoverable_requests = [request]
48 first_request = self.dependencies_lens.GetRedirectChain(request)[-1]
49 deps = self.dependencies_lens.GetRequestDependencies()
50 for (first, second, reason) in deps:
51 if first.request_id == first_request.request_id and reason == 'parser':
52 discoverable_requests.append(second)
53 return discoverable_requests
54
55 def ExpandRedirectChains(self, requests):
56 return list(itertools.chain.from_iterable(
57 [self.dependencies_lens.GetRedirectChain(r) for r in requests]))
58
59 def PreloadedRequests(self, request):
60 """Returns the requests that have been preloaded from a given request.
61
62 This list is the set of request that are:
63 - Discoverable by the parser
64 - Found in the trace log.
65
66 Before looking for dependencies, this follows the redirect chain.
67
68 Args:
69 request: (Request) Root request.
70
71 Returns:
72 A list of Request. Does not include the root request. This list is a
73 subset of the one returned by ParserDiscoverableRequests().
74 """
75 # Preload step events are emitted in ResourceFetcher::preloadStarted().
76 preload_step_events = filter(
77 lambda e: e.args.get('step') == 'Preload',
78 self._resource_events.GetEvents())
79 preloaded_urls = set()
80 for preload_step_event in preload_step_events:
81 preload_event = self._resource_events.EventFromStep(preload_step_event)
82 if preload_event:
83 preloaded_urls.add(preload_event.args['url'])
84 parser_requests = self.ParserDiscoverableRequests(request)
85 preloaded_root_requests = filter(
86 lambda r: r.url in preloaded_urls, parser_requests)
87 # We can actually fetch the whole redirect chain.
88 return [request] + list(itertools.chain.from_iterable(
89 [self.dependencies_lens.GetRedirectChain(r)
90 for r in preloaded_root_requests]))
91
92
93 def _PrintSummary(prefetch_view):
94 requests = prefetch_view.trace.request_track.GetEvents()
95 first_request = prefetch_view.trace.request_track.GetEvents()[0]
96 parser_requests = prefetch_view.ExpandRedirectChains(
97 prefetch_view.ParserDiscoverableRequests(first_request))
98 preloaded_requests = prefetch_view.ExpandRedirectChains(
99 prefetch_view.PreloadedRequests(first_request))
100 print '%d requests, %d parser from the main request, %d preloaded' % (
101 len(requests), len(parser_requests), len(preloaded_requests))
102
103
104 def main(filename):
105 trace = loading_trace.LoadingTrace.FromJsonFile(filename)
106 dependencies_lens = request_dependencies_lens.RequestDependencyLens(trace)
107 prefetch_view = PrefetchSimulationView(trace, dependencies_lens)
108 _PrintSummary(prefetch_view)
109
110
111 if __name__ == '__main__':
112 import sys
113 main(sys.argv[1])
OLDNEW
« no previous file with comments | « tools/android/loading/activity_lens.py ('k') | tools/android/loading/prefetch_view_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698