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

Side by Side Diff: tools/resource_prefetch_predictor/prefetch_predictor_tool.py

Issue 2195503003: predictors: Add the request priority to the reource_prefetch_predictor DB. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compile fix. Created 4 years, 4 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 | « chrome/browser/predictors/resource_prefetch_predictor_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2016 The Chromium Authors. All rights reserved. 2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Inspection of the prefetch predictor database. 6 """Inspection of the prefetch predictor database.
7 7
8 On Android, the database can be extracted using: 8 On Android, the database can be extracted using:
9 adb pull \ 9 adb pull \
10 '/data/user/0/$package_name/app_chrome/Default/Network Action Predictor' 10 '/data/user/0/$package_name/app_chrome/Default/Network Action Predictor'
(...skipping 13 matching lines...) Expand all
24 24
25 25
26 class Entry(object): 26 class Entry(object):
27 """Represents an entry in the predictor database.""" 27 """Represents an entry in the predictor database."""
28 HEADER = ( 28 HEADER = (
29 'score,main_page_url,resource_type,number_of_hits,number_of_misses,' 29 'score,main_page_url,resource_type,number_of_hits,number_of_misses,'
30 'consecutive_misses,average_position,confidence,resource_url') 30 'consecutive_misses,average_position,confidence,resource_url')
31 31
32 def __init__( 32 def __init__(
33 self, main_page_url, resource_url, resource_type, number_of_hits, 33 self, main_page_url, resource_url, resource_type, number_of_hits,
34 number_of_misses, consecutive_misses, average_position): 34 number_of_misses, consecutive_misses, average_position, priority):
35 self.main_page_url = main_page_url 35 self.main_page_url = main_page_url
36 self.resource_url = resource_url 36 self.resource_url = resource_url
37 self.resource_type = resource_type 37 self.resource_type = resource_type
38 self.number_of_hits = int(number_of_hits) 38 self.number_of_hits = int(number_of_hits)
39 self.number_of_misses = int(number_of_misses) 39 self.number_of_misses = int(number_of_misses)
40 self.consecutive_misses = int(consecutive_misses) 40 self.consecutive_misses = int(consecutive_misses)
41 self.average_position = int(average_position) 41 self.average_position = int(average_position)
42 self.priority = int(priority)
42 self.confidence = float(number_of_hits) / ( 43 self.confidence = float(number_of_hits) / (
43 number_of_hits + number_of_misses) 44 number_of_hits + number_of_misses)
44 self.score = self._Score() 45 self.score = self._Score()
45 46
46 def _Score(self): 47 def _Score(self):
47 """Mirrors ResourcePrefetchPredictorTables::ResourceRow::UpdateScore.""" 48 """Mirrors ResourcePrefetchPredictorTables::ResourceRow::UpdateScore."""
48 multiplier = 1 49 multiplier = 1
49 if self.resource_type in (ResourceType.STYLESHEET, ResourceType.SCRIPT, 50 if self.resource_type in (ResourceType.STYLESHEET, ResourceType.SCRIPT,
50 ResourceType.FONT_RESOURCE): 51 ResourceType.FONT_RESOURCE):
51 multiplier = 2 52 multiplier = 2
52 return multiplier * 100 - self.average_position 53 return multiplier * 100 - self.average_position
53 54
54 @classmethod 55 @classmethod
55 def FromRow(cls, row): 56 def FromRow(cls, row):
56 """Builds an entry from a database row.""" 57 """Builds an entry from a database row."""
57 return Entry(*row) 58 return Entry(*row)
58 59
59 def __str__(self): 60 def __str__(self):
60 return '%f,%s,%d,%d,%d,%d,%d,%f\t%s' % ( 61 return '%f,%s,%d,%d,%d,%d,%d,%f,%d\t%s' % (
61 self.score, self.main_page_url, self.resource_type, 62 self.score, self.main_page_url, self.resource_type,
62 self.number_of_hits, self.number_of_misses, self.consecutive_misses, 63 self.number_of_hits, self.number_of_misses, self.consecutive_misses,
63 self.average_position, self.confidence, self.resource_url) 64 self.average_position, self.confidence, self.priority,
65 self.resource_url)
64 66
65 67
66 def FilterAndSort(entries, domain): 68 def FilterAndSort(entries, domain):
67 """Filters and sorts the entries to be prefetched for a given domain. 69 """Filters and sorts the entries to be prefetched for a given domain.
68 70
69 Uses the default thresholds defined in resource_prefetch_common.cc. 71 Uses the default thresholds defined in resource_prefetch_common.cc.
70 """ 72 """
71 result = filter( 73 result = filter(
72 lambda x: ((domain is None or x.main_page_url == domain) 74 lambda x: ((domain is None or x.main_page_url == domain)
73 and x.confidence > .7 75 and x.confidence > .7
74 and x.number_of_hits >= 2), entries) 76 and x.number_of_hits >= 2), entries)
75 return sorted(result, key=operator.attrgetter('score'), reverse=True) 77 return sorted(result, key=operator.attrgetter('score'), reverse=True)
76 78
77 79
78 def DatabaseStats(filename, domain): 80 def DatabaseStats(filename, domain):
79 connection = sqlite3.connect(filename) 81 connection = sqlite3.connect(filename)
80 c = connection.cursor() 82 c = connection.cursor()
81 query = ('SELECT main_page_url, resource_url, resource_type, number_of_hits, ' 83 query = ('SELECT main_page_url, resource_url, resource_type, number_of_hits, '
82 'number_of_misses, consecutive_misses, average_position ' 84 'number_of_misses, consecutive_misses, average_position, priority '
83 'FROM resource_prefetch_predictor_host') 85 'FROM resource_prefetch_predictor_host')
84 entries = [Entry.FromRow(row) for row in c.execute(query)] 86 entries = [Entry.FromRow(row) for row in c.execute(query)]
85 prefetched = FilterAndSort(entries, domain) 87 prefetched = FilterAndSort(entries, domain)
86 print Entry.HEADER 88 print Entry.HEADER
87 for x in prefetched: 89 for x in prefetched:
88 print x 90 print x
89 91
90 92
91 def main(): 93 def main():
92 parser = argparse.ArgumentParser() 94 parser = argparse.ArgumentParser()
93 parser.add_argument('-f', dest='database_filename', required=True, 95 parser.add_argument('-f', dest='database_filename', required=True,
94 help='Path to the database') 96 help='Path to the database')
95 parser.add_argument('-d', dest='domain', default=None, help='Domain') 97 parser.add_argument('-d', dest='domain', default=None, help='Domain')
96 args = parser.parse_args() 98 args = parser.parse_args()
97 DatabaseStats(args.database_filename, args.domain) 99 DatabaseStats(args.database_filename, args.domain)
98 100
99 101
100 if __name__ == '__main__': 102 if __name__ == '__main__':
101 main() 103 main()
OLDNEW
« no previous file with comments | « chrome/browser/predictors/resource_prefetch_predictor_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698