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

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

Issue 1837193002: Clovis: update resource sack to use new dependency graph. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 8 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/dependency_graph.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 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 """Compute core set for a page. 5 """Compute core set for a page.
6 6
7 This script is a collection of utilities for working with core sets. 7 This script is a collection of utilities for working with core sets.
8 """ 8 """
9 9
10 import argparse 10 import argparse
11 import glob 11 import glob
12 import json 12 import json
13 import logging 13 import logging
14 import multiprocessing 14 import multiprocessing
15 import os 15 import os
16 import sys 16 import sys
17 17
18 import loading_model 18 import dependency_graph
19 import loading_trace 19 import loading_trace
20 import request_dependencies_lens
20 import resource_sack 21 import resource_sack
21 22
22 23
23 def _Progress(x): 24 def _Progress(x):
24 sys.stderr.write(x + '\n') 25 sys.stderr.write(x + '\n')
25 26
26 27
27 def _PageCore(prefix, graph_set_names, output): 28 def _PageCore(prefix, graph_set_names, output):
28 """Compute the page core over sets defined by graph_set_names.""" 29 """Compute the page core over sets defined by graph_set_names."""
29 assert graph_set_names 30 assert graph_set_names
30 graph_sets = [] 31 graph_sets = []
31 sack = resource_sack.GraphSack() 32 sack = resource_sack.GraphSack()
32 for name in graph_set_names: 33 for name in graph_set_names:
33 name_graphs = [] 34 name_graphs = []
34 _Progress('Processing %s' % name) 35 _Progress('Processing %s' % name)
35 for filename in glob.iglob('-'.join([prefix, name, '*.trace'])): 36 for filename in glob.iglob('-'.join([prefix, name, '*.trace'])):
36 _Progress('Reading %s' % filename) 37 _Progress('Reading %s' % filename)
37 graph = loading_model.ResourceGraph( 38 trace = loading_trace.LoadingTrace.FromJsonFile(filename)
38 loading_trace.LoadingTrace.FromJsonFile(filename)) 39 graph = dependency_graph.RequestDependencyGraph(
40 trace.request_track.GetEvents(),
41 request_dependencies_lens.RequestDependencyLens(trace))
39 sack.ConsumeGraph(graph) 42 sack.ConsumeGraph(graph)
40 name_graphs.append(graph) 43 name_graphs.append(graph)
41 graph_sets.append(name_graphs) 44 graph_sets.append(name_graphs)
42 json.dump({'page_core': [l for l in sack.CoreSet(*graph_sets)], 45 json.dump({'page_core': [l for l in sack.CoreSet(*graph_sets)],
43 'threshold': sack.CORE_THRESHOLD}, 46 'threshold': sack.CORE_THRESHOLD},
44 output, sort_keys=True, indent=2) 47 output, sort_keys=True, indent=2)
45 output.write('\n') 48 output.write('\n')
46 49
47 50
48 def _DoSite(site, graph_sets, input_dir, output_dir): 51 def _DoSite(site, graph_sets, input_dir, output_dir):
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 _Progress('Using threshold %s' % threshold) 86 _Progress('Using threshold %s' % threshold)
84 big_sack = resource_sack.GraphSack() 87 big_sack = resource_sack.GraphSack()
85 graph_sets = [] 88 graph_sets = []
86 for name in graph_set_names: 89 for name in graph_set_names:
87 _Progress('Finding core set for %s' % name) 90 _Progress('Finding core set for %s' % name)
88 sack = resource_sack.GraphSack() 91 sack = resource_sack.GraphSack()
89 sack.CORE_THRESHOLD = threshold 92 sack.CORE_THRESHOLD = threshold
90 this_set = [] 93 this_set = []
91 for filename in glob.iglob('-'.join([prefix, name, '*.trace'])): 94 for filename in glob.iglob('-'.join([prefix, name, '*.trace'])):
92 _Progress('Reading %s' % filename) 95 _Progress('Reading %s' % filename)
93 graph = loading_model.ResourceGraph( 96 trace = loading_trace.LoadingTrace.FromJsonFile(filename)
94 loading_trace.LoadingTrace.FromJsonDict(json.load(open(filename)))) 97 graph = dependency_graph.RequestDependencyGraph(
98 trace.request_track.GetEvents(),
99 request_dependencies_lens.RequestDependencyLens(trace))
95 sack.ConsumeGraph(graph) 100 sack.ConsumeGraph(graph)
96 big_sack.ConsumeGraph(graph) 101 big_sack.ConsumeGraph(graph)
97 this_set.append(graph) 102 this_set.append(graph)
98 core_sets.append({ 103 core_sets.append({
99 'set_name': name, 104 'set_name': name,
100 'core_set': [l for l in sack.CoreSet()] 105 'core_set': [l for l in sack.CoreSet()]
101 }) 106 })
102 graph_sets.append(this_set) 107 graph_sets.append(this_set)
103 json.dump({'core_sets': core_sets, 108 json.dump({'core_sets': core_sets,
104 'page_core': [l for l in big_sack.CoreSet(*graph_sets)]}, 109 'page_core': [l for l in big_sack.CoreSet(*graph_sets)]},
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 'all_cores) using Jaccard index. Outputs on stdout')) 201 'all_cores) using Jaccard index. Outputs on stdout'))
197 compare.add_argument('--a', required=True, help='the first core set JSON') 202 compare.add_argument('--a', required=True, help='the first core set JSON')
198 compare.add_argument('--b', required=True, help='the second core set JSON') 203 compare.add_argument('--b', required=True, help='the second core set JSON')
199 compare.add_argument('--csv', action='store_true', help='output as CSV') 204 compare.add_argument('--csv', action='store_true', help='output as CSV')
200 compare.set_defaults( 205 compare.set_defaults(
201 executor=lambda args: 206 executor=lambda args:
202 _Compare(args.a, args.b, args.csv)) 207 _Compare(args.a, args.b, args.csv))
203 208
204 args = parser.parse_args() 209 args = parser.parse_args()
205 args.executor(args) 210 args.executor(args)
OLDNEW
« no previous file with comments | « no previous file | tools/android/loading/dependency_graph.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698