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

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

Issue 2168083002: tools: Add a tool to dump the resource_prefetch_predictor database. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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/resource_prefetch_predictor/OWNERS ('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
(Empty)
1 #!/usr/bin/python
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
4 # found in the LICENSE file.
5
6 """Inspection of the prefetch predictor database."""
7
8 import argparse
9 import operator
10 import sqlite3
11
12 class ResourceType(object):
13 STYLESHEET = 2
14 SCRIPT = 3
15
16
17 class Entry(object):
18 def __init__(
19 self, main_page_url, resource_url, resource_type, number_of_hits,
20 number_of_misses, consecutive_misses, average_position):
21 self.main_page_url = main_page_url
22 self.resource_url = resource_url
23 self.resource_type = resource_type
24 self.number_of_hits = int(number_of_hits)
25 self.number_of_misses = int(number_of_misses)
26 self.consecutive_misses = int(consecutive_misses)
27 self.average_position = int(average_position)
28 self.confidence = float(number_of_hits) / (
29 number_of_hits + number_of_misses)
30 self.score = self._Score()
31
32 def _Score(self):
mattcary 2016/07/21 14:04:29 Add a comment about where this score calculation c
Benoit L 2016/07/21 14:48:42 /facepalm Forgot to upload the latest revision of
33 multiplier = 1
34 if self.resource_type in (ResourceType.STYLESHEET, ResourceType.SCRIPT):
35 multiplier = 2
36 return multiplier * 100 - self.average_position
37
38 @classmethod
39 def FromRow(cls, row):
40 return Entry(*row)
41
42 HEADER = (
43 'score,main_page_url,resource_type,number_of_hits,number_of_misses,'
44 'consecutive_misses,average_position,confidence,resource_url')
45
46 def __str__(self):
47 return '%f,%s,%d,%d,%d,%d,%d,%f\t%s' % (
48 self.score, self.main_page_url, self.resource_type,
49 self.number_of_hits, self.number_of_misses, self.consecutive_misses,
50 self.average_position, self.confidence, self.resource_url)
51
52
53 def FilterAndSort(entries, domain):
54 result = filter(
mattcary 2016/07/21 14:04:29 Ditto about where these threshold come from.
Benoit L 2016/07/21 14:48:42 Done.
55 lambda x: ((domain is None or x.main_page_url == domain)
56 and x.confidence > .7
57 and x.number_of_hits >= 2), entries)
58 return sorted(result, key=operator.attrgetter('score'), reverse=True)
59
60
61 def DatabaseStats(filename, domain):
62 connection = sqlite3.connect(filename)
63 c = connection.cursor()
64 query = 'SELECT * FROM resource_prefetch_predictor_host'
mattcary 2016/07/21 14:04:29 It would be safer to name the fields that you're e
Benoit L 2016/07/21 14:48:42 Thanks! Done.
65 entries = [Entry.FromRow(row) for row in c.execute(query)]
66 prefetched = FilterAndSort(entries, domain)
67 print Entry.HEADER
68 for x in prefetched:
69 print x
70
71
72 def main():
73 parser = argparse.ArgumentParser()
74 parser.add_argument('-f', dest='database_filename', required=True,
75 help='Path to the database')
76 parser.add_argument('-d', dest='domain', default=None, help='Domain')
77 args = parser.parse_args()
78 DatabaseStats(args.database_filename, args.domain)
79
80
81 if __name__ == '__main__':
82 main()
OLDNEW
« no previous file with comments | « tools/resource_prefetch_predictor/OWNERS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698