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

Side by Side Diff: tools/perf/profile_creators/history_profile_extender.py

Issue 914253005: Telemetry: Create new profile creator large_profile_creator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase against top of tree. Created 5 years, 10 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
OLDNEW
(Empty)
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 import tempfile
5 import os
6
7 from profile_creators import fast_navigation_profile_extender
8
9
10 class HistoryProfileExtender(
11 fast_navigation_profile_extender.FastNavigationProfileExtender):
12 """This extender navigates Chrome to a large number of URIs pointing to local
13 files. It continues running until the history DB becomes full."""
14 _HISTORY_DB_MAX_SIZE_IN_MB = 10
15
16 def __init__(self):
17 super(HistoryProfileExtender, self).__init__()
18
19 # A list of paths of temporary files. The instance is responsible for
20 # making sure that the files are deleted before they are removed from this
21 # list.
22 self._file_paths = []
23
24 def GetUrlsToNavigate(self, maximum_batch_size):
25 """Superclass override.
26
27 This method makes temporary files. It returns URIs to these files, which
28 allows Chrome to populate its history database by navigating to these files
29 on the local file system.
30
31 This method fills the member |_file_paths| with the absolute paths of the
32 temporary files, which must be removed at a later point in time.
33 """
34 urls = []
35 for _ in range(maximum_batch_size):
36 suffix = "reallylongsuffixintendedtoartificiallyincreasethelengthoftheurl"
37 handle, path = tempfile.mkstemp(suffix=suffix)
38 os.close(handle)
39 self._file_paths.append(path)
40
41 file_url = "file://" + path
42 urls.append(file_url)
43
44 return urls
45
46 def ShouldExit(self):
47 """Superclass override."""
48 return self._IsHistoryDBAtMaxSize()
49
50 def NumTabs(self):
51 """Superclass override.
52
53 Navigating to local files is really fast, so the batch size should be extra
54 large.
55 """
56 return super(HistoryProfileExtender, self).NumTabs() * 4
57
58 def TearDown(self):
59 """Superclass override."""
60 super(HistoryProfileExtender, self).TearDown()
61 for path in self._file_paths:
62 os.remove(path)
63 self._file_paths = []
64
65 def FinishedNavigationOfBatch(self):
66 """Superclass override."""
67 for path in self._file_paths:
68 os.remove(path)
69 self._file_paths = []
70
71 def _IsHistoryDBAtMaxSize(self):
72 """Whether the history DB has reached its maximum size."""
73 history_db_path = os.path.join(self.profile_path, "Default", "History")
74 stat_info = os.stat(history_db_path)
75 size = stat_info.st_size
76
77 max_size_threshold = 0.95
78 max_size = ((10**6 * HistoryProfileExtender._HISTORY_DB_MAX_SIZE_IN_MB) *
79 max_size_threshold)
80 return size > max_size
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698