Chromium Code Reviews| Index: tools/perf/profile_creators/history_profile_extender.py |
| diff --git a/tools/perf/profile_creators/history_profile_extender.py b/tools/perf/profile_creators/history_profile_extender.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fdd932db257a2f23d1d20cc0493013185546e3bf |
| --- /dev/null |
| +++ b/tools/perf/profile_creators/history_profile_extender.py |
| @@ -0,0 +1,78 @@ |
| +# Copyright 2015 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +import multiprocessing |
| +import tempfile |
| +import os |
| + |
| +from profile_creators import fast_navigation_profile_extender |
| + |
| + |
| +class HistoryProfileExtender( |
| + fast_navigation_profile_extender.FastNavigationProfileExtender): |
| + """This extender navigates Chrome to a large number of URIs pointing to local |
| + files. It continues running until the history DB becomes full.""" |
| + _HISTORY_DB_MAX_SIZE_IN_MB = 10 |
| + |
| + def __init__(self): |
| + # The rate limiting factors are the speed of page navigation, and the speed |
| + # of python bindings. The former is larger than the latter, so having a |
| + # large batch size skews the amortized average time per page load towards |
| + # the latter. |
| + batch_size = multiprocessing.cpu_count() * 2 |
| + super(HistoryProfileExtender, self).__init__(batch_size) |
| + |
| + # A list of paths of temporary files. The instance is responsible for |
| + # making sure that the files are deleted before they are removed from this |
| + # list. |
| + self._file_paths = [] |
| + |
| + def GetUrlsToNavigate(self, maximum_batch_size): |
| + """Superclass override. |
| + |
| + This method makes temporary files. It returns URIs to these files, which |
| + allows Chrome to populate its history database by navigating to these files |
| + on the local file system. |
| + |
| + This method fills the member |_file_paths| with the absolute paths of the |
| + temporary files, which must be removed at a later point in time. |
| + """ |
| + urls = [] |
| + for _ in range(maximum_batch_size): |
| + suffix = "reallylongsuffixintendedtoartificiallyincreasethelengthoftheurl" |
|
nednguyen
2015/02/19 00:33:32
Can you add some comment about why we want a long
erikchen
2015/02/19 01:56:03
Done.
|
| + handle, path = tempfile.mkstemp(suffix=suffix) |
| + os.close(handle) |
| + self._file_paths.append(path) |
| + |
| + file_url = "file://" + path |
| + urls.append(file_url) |
| + |
| + return urls |
| + |
| + def ShouldExitAfterBatchNavigation(self): |
| + """Superclass override.""" |
| + return self._IsHistoryDBAtMaxSize() |
| + |
| + def TearDown(self): |
| + """Superclass override.""" |
| + super(HistoryProfileExtender, self).TearDown() |
| + for path in self._file_paths: |
| + os.remove(path) |
| + self._file_paths = [] |
| + |
| + def CleanUpAfterBatchNavigation(self): |
| + """Superclass override.""" |
| + for path in self._file_paths: |
| + os.remove(path) |
|
nednguyen
2015/02/19 00:33:32
You can move TemporaryFile which is deleted on clo
erikchen
2015/02/19 01:56:03
For a full explanation, see my earlier response. I
|
| + self._file_paths = [] |
| + |
| + def _IsHistoryDBAtMaxSize(self): |
| + """Whether the history DB has reached its maximum size.""" |
| + history_db_path = os.path.join(self.profile_path, "Default", "History") |
| + stat_info = os.stat(history_db_path) |
| + size = stat_info.st_size |
| + |
| + max_size_threshold = 0.95 |
| + max_size = ((10**6 * HistoryProfileExtender._HISTORY_DB_MAX_SIZE_IN_MB) * |
|
nednguyen
2015/02/19 00:33:32
Technically, this should be 2 ** 20?
erikchen
2015/02/19 01:56:03
Done.
|
| + max_size_threshold) |
| + return size > max_size |