| OLD | NEW |
| 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' |
| 11 predictor_db | 11 predictor_db |
| 12 """ | 12 """ |
| 13 | 13 |
| 14 import argparse | 14 import argparse |
| 15 import operator | 15 import operator |
| 16 import sqlite3 | 16 import sqlite3 |
| 17 | 17 |
| 18 | 18 |
| 19 class ResourceType(object): | 19 class ResourceType(object): |
| 20 """Partially mirrors content::ResourceType.""" |
| 20 STYLESHEET = 2 | 21 STYLESHEET = 2 |
| 21 SCRIPT = 3 | 22 SCRIPT = 3 |
| 23 FONT_RESOURCE = 5 |
| 22 | 24 |
| 23 | 25 |
| 24 class Entry(object): | 26 class Entry(object): |
| 25 """Represents an entry in the predictor database.""" | 27 """Represents an entry in the predictor database.""" |
| 26 HEADER = ( | 28 HEADER = ( |
| 27 '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,' |
| 28 'consecutive_misses,average_position,confidence,resource_url') | 30 'consecutive_misses,average_position,confidence,resource_url') |
| 29 | 31 |
| 30 def __init__( | 32 def __init__( |
| 31 self, main_page_url, resource_url, resource_type, number_of_hits, | 33 self, main_page_url, resource_url, resource_type, number_of_hits, |
| 32 number_of_misses, consecutive_misses, average_position): | 34 number_of_misses, consecutive_misses, average_position): |
| 33 self.main_page_url = main_page_url | 35 self.main_page_url = main_page_url |
| 34 self.resource_url = resource_url | 36 self.resource_url = resource_url |
| 35 self.resource_type = resource_type | 37 self.resource_type = resource_type |
| 36 self.number_of_hits = int(number_of_hits) | 38 self.number_of_hits = int(number_of_hits) |
| 37 self.number_of_misses = int(number_of_misses) | 39 self.number_of_misses = int(number_of_misses) |
| 38 self.consecutive_misses = int(consecutive_misses) | 40 self.consecutive_misses = int(consecutive_misses) |
| 39 self.average_position = int(average_position) | 41 self.average_position = int(average_position) |
| 40 self.confidence = float(number_of_hits) / ( | 42 self.confidence = float(number_of_hits) / ( |
| 41 number_of_hits + number_of_misses) | 43 number_of_hits + number_of_misses) |
| 42 self.score = self._Score() | 44 self.score = self._Score() |
| 43 | 45 |
| 44 def _Score(self): | 46 def _Score(self): |
| 45 """Mirrors ResourcePrefetchPredictorTables::ResourceRow::UpdateScore.""" | 47 """Mirrors ResourcePrefetchPredictorTables::ResourceRow::UpdateScore.""" |
| 46 multiplier = 1 | 48 multiplier = 1 |
| 47 if self.resource_type in (ResourceType.STYLESHEET, ResourceType.SCRIPT): | 49 if self.resource_type in (ResourceType.STYLESHEET, ResourceType.SCRIPT, |
| 50 ResourceType.FONT_RESOURCE): |
| 48 multiplier = 2 | 51 multiplier = 2 |
| 49 return multiplier * 100 - self.average_position | 52 return multiplier * 100 - self.average_position |
| 50 | 53 |
| 51 @classmethod | 54 @classmethod |
| 52 def FromRow(cls, row): | 55 def FromRow(cls, row): |
| 53 """Builds an entry from a database row.""" | 56 """Builds an entry from a database row.""" |
| 54 return Entry(*row) | 57 return Entry(*row) |
| 55 | 58 |
| 56 def __str__(self): | 59 def __str__(self): |
| 57 return '%f,%s,%d,%d,%d,%d,%d,%f\t%s' % ( | 60 return '%f,%s,%d,%d,%d,%d,%d,%f\t%s' % ( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 parser = argparse.ArgumentParser() | 92 parser = argparse.ArgumentParser() |
| 90 parser.add_argument('-f', dest='database_filename', required=True, | 93 parser.add_argument('-f', dest='database_filename', required=True, |
| 91 help='Path to the database') | 94 help='Path to the database') |
| 92 parser.add_argument('-d', dest='domain', default=None, help='Domain') | 95 parser.add_argument('-d', dest='domain', default=None, help='Domain') |
| 93 args = parser.parse_args() | 96 args = parser.parse_args() |
| 94 DatabaseStats(args.database_filename, args.domain) | 97 DatabaseStats(args.database_filename, args.domain) |
| 95 | 98 |
| 96 | 99 |
| 97 if __name__ == '__main__': | 100 if __name__ == '__main__': |
| 98 main() | 101 main() |
| OLD | NEW |