| 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' |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 confidence = float(resource.number_of_hits) / ( | 77 confidence = float(resource.number_of_hits) / ( |
| 78 resource.number_of_hits + resource.number_of_misses) | 78 resource.number_of_hits + resource.number_of_misses) |
| 79 if resource.number_of_hits < 2 or confidence < .7: | 79 if resource.number_of_hits < 2 or confidence < .7: |
| 80 continue | 80 continue |
| 81 self._PrettyPrintResource(resource) | 81 self._PrettyPrintResource(resource) |
| 82 | 82 |
| 83 def DumpOriginDatabaseRow(domain, primary_key, proto): | 83 def DumpOriginDatabaseRow(domain, primary_key, proto): |
| 84 from resource_prefetch_predictor_pb2 import OriginData | 84 from resource_prefetch_predictor_pb2 import OriginData |
| 85 entry = OriginData() | 85 entry = OriginData() |
| 86 entry.ParseFromString(proto) | 86 entry.ParseFromString(proto) |
| 87 # For the offset, see kWindowsEpochDeltaMicroseconds in | 87 # For the offset, see kTimeTToMicrosecondsOffset in base/time/time.h. |
| 88 # base/time/time_posix.cc. | |
| 89 last_visit_timestamp = int(entry.last_visit_time / 1e6 - 11644473600) | 88 last_visit_timestamp = int(entry.last_visit_time / 1e6 - 11644473600) |
| 90 formatted_last_visit_time = datetime.datetime.utcfromtimestamp( | 89 formatted_last_visit_time = datetime.datetime.utcfromtimestamp( |
| 91 last_visit_timestamp).strftime('%Y-%m-%d %H:%M:%S') | 90 last_visit_timestamp).strftime('%Y-%m-%d %H:%M:%S') |
| 92 print '''host: %s | 91 print '''host: %s |
| 93 last_visit_time: %s | 92 last_visit_time: %s |
| 94 origins:''' % (entry.host, formatted_last_visit_time) | 93 origins:''' % (entry.host, formatted_last_visit_time) |
| 95 for origin_stat in entry.origins: | 94 for origin_stat in entry.origins: |
| 96 print ''' origin: %s | 95 print ''' origin: %s |
| 97 number_of_hits: %d | 96 number_of_hits: %d |
| 98 number_of_misses: %d | 97 number_of_misses: %d |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 try: | 154 try: |
| 156 database_copy = CreateCompatibleDatabaseCopy(args.database_filename) | 155 database_copy = CreateCompatibleDatabaseCopy(args.database_filename) |
| 157 DatabaseStats(database_copy, args.domain) | 156 DatabaseStats(database_copy, args.domain) |
| 158 finally: | 157 finally: |
| 159 if os.path.exists(database_copy): | 158 if os.path.exists(database_copy): |
| 160 os.remove(database_copy) | 159 os.remove(database_copy) |
| 161 | 160 |
| 162 | 161 |
| 163 if __name__ == '__main__': | 162 if __name__ == '__main__': |
| 164 main() | 163 main() |
| OLD | NEW |