Commit 37127ecd authored by alexilin's avatar alexilin Committed by Commit bot

predictors: db tool workaround to solve sqlite3 compatibility problem.

Current version of python sqilte3 library hasn't support of views. But new
sqlite3 binary used in chrome implicitly creates MmapStatus view everytime that
causes incompatibility problem. This workaround creates a temporary copy of
given database and deletes the view through sqlite3 command line tool that has
support of views.

BUG=631966

Review-Url: https://codereview.chromium.org/2620053002
Cr-Commit-Position: refs/heads/master@{#442945}
parent 3bbebdae
...@@ -13,6 +13,7 @@ adb pull \ ...@@ -13,6 +13,7 @@ adb pull \
import argparse import argparse
import sqlite3 import sqlite3
import os
from resource_prefetch_predictor_pb2 import (PrefetchData, ResourceData) from resource_prefetch_predictor_pb2 import (PrefetchData, ResourceData)
...@@ -77,6 +78,15 @@ class Entry(object): ...@@ -77,6 +78,15 @@ class Entry(object):
continue continue
self._PrettyPrintResource(resource) self._PrettyPrintResource(resource)
# The version of python sqlite3 library we have in Ubuntu 14.04 LTS doesn't
# support views but command line util does.
# TODO(alexilin): get rid of this when python sqlite3 adds view support.
def CreateCompatibleDatabaseCopy(filename):
import tempfile, shutil, subprocess
_, tmpfile = tempfile.mkstemp()
shutil.copy2(filename, tmpfile)
subprocess.call(['sqlite3', tmpfile, 'DROP VIEW MmapStatus'])
return tmpfile
def DatabaseStats(filename, domain): def DatabaseStats(filename, domain):
connection = sqlite3.connect(filename) connection = sqlite3.connect(filename)
...@@ -94,7 +104,12 @@ def main(): ...@@ -94,7 +104,12 @@ def main():
help='Path to the database') help='Path to the database')
parser.add_argument('-d', dest='domain', default=None, help='Domain') parser.add_argument('-d', dest='domain', default=None, help='Domain')
args = parser.parse_args() args = parser.parse_args()
DatabaseStats(args.database_filename, args.domain) try:
database_copy = CreateCompatibleDatabaseCopy(args.database_filename)
DatabaseStats(database_copy, args.domain)
finally:
if os.path.exists(database_copy):
os.remove(database_copy)
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment