OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """ | 5 """ |
6 Cache temperature specifies how the browser cache should be configured before | 6 Cache temperature specifies how the browser cache should be configured before |
7 the page run. | 7 the page run. |
8 | 8 |
9 See design doc for details: | 9 See design doc for details: |
10 https://docs.google.com/document/u/1/d/12D7tkhZi887g9d0U2askU9JypU_wYiEI7Lw0bfwx
UgA | 10 https://docs.google.com/document/u/1/d/12D7tkhZi887g9d0U2askU9JypU_wYiEI7Lw0bfwx
UgA |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 if exception_type: | 47 if exception_type: |
48 return True | 48 return True |
49 | 49 |
50 marker = 'telemetry.internal.%s.end' % self.identifier | 50 marker = 'telemetry.internal.%s.end' % self.identifier |
51 self.browser.tabs[0].ExecuteJavaScript( | 51 self.browser.tabs[0].ExecuteJavaScript( |
52 "console.time({{ marker }});", marker=marker) | 52 "console.time({{ marker }});", marker=marker) |
53 self.browser.tabs[0].ExecuteJavaScript( | 53 self.browser.tabs[0].ExecuteJavaScript( |
54 "console.timeEnd({{ marker }});", marker=marker) | 54 "console.timeEnd({{ marker }});", marker=marker) |
55 return True | 55 return True |
56 | 56 |
| 57 def ClearCache(browser): |
| 58 tab = browser.tabs[0] |
| 59 tab.ClearCache(force=True) |
| 60 |
| 61 def WarmCache(page, browser): |
| 62 with MarkTelemetryInternal(browser, 'warm_cache'): |
| 63 tab = browser.tabs[0] |
| 64 tab.Navigate(page.url) |
| 65 py_utils.WaitFor(tab.HasReachedQuiescence, 60) |
| 66 tab.WaitForDocumentReadyStateToBeComplete() |
| 67 tab.Navigate("about:blank") |
| 68 tab.WaitForDocumentReadyStateToBeComplete() |
| 69 |
57 def EnsurePageCacheTemperature(page, browser, previous_page=None): | 70 def EnsurePageCacheTemperature(page, browser, previous_page=None): |
58 temperature = page.cache_temperature | 71 temperature = page.cache_temperature |
59 logging.info('PageCacheTemperature: %s', temperature) | 72 logging.info('PageCacheTemperature: %s', temperature) |
60 | |
61 if temperature == ANY: | 73 if temperature == ANY: |
62 return | 74 return |
63 | |
64 if temperature == COLD: | 75 if temperature == COLD: |
65 if previous_page is None: | 76 if previous_page is None: |
66 # DiskCache initialization is performed asynchronously on Chrome start-up. | 77 # DiskCache initialization is performed asynchronously on Chrome start-up. |
67 # Ensure that DiskCache is initialized before starting the measurement to | 78 # Ensure that DiskCache is initialized before starting the measurement to |
68 # avoid performance skew. | 79 # avoid performance skew. |
69 # This is done by navigating to an inexistent URL and then wait for the | 80 # This is done by navigating to an inexistent URL and then wait for the |
70 # navigation to complete. | 81 # navigation to complete. |
71 # TODO(kouhei) Consider moving this logic to PageCyclerStory | 82 # TODO(kouhei) Consider moving this logic to PageCyclerStory |
72 with MarkTelemetryInternal(browser, 'ensure_diskcache'): | 83 with MarkTelemetryInternal(browser, 'ensure_diskcache'): |
73 tab = browser.tabs[0] | 84 tab = browser.tabs[0] |
74 tab.Navigate("http://does.not.exist") | 85 tab.Navigate("http://does.not.exist") |
75 tab.WaitForDocumentReadyStateToBeComplete() | 86 tab.WaitForDocumentReadyStateToBeComplete() |
76 any_tab = browser.tabs[0] | 87 ClearCache(browser) |
77 any_tab.ClearCache(force=True) | |
78 elif temperature == WARM: | 88 elif temperature == WARM: |
79 if (previous_page is not None and | 89 if (previous_page is not None and |
80 previous_page.url == page.url and | 90 previous_page.url == page.url and |
81 (previous_page.cache_temperature == COLD or | 91 (previous_page.cache_temperature == COLD or |
82 previous_page.cache_temperature == WARM)): | 92 previous_page.cache_temperature == WARM)): |
83 if '#' in page.url: | 93 if '#' in page.url: |
84 # Navigate to inexistent URL to avoid in-page hash navigation. | 94 # Navigate to inexistent URL to avoid in-page hash navigation. |
85 # Note: Unlike PCv1, PCv2 iterates the same URL for different cache | 95 # Note: Unlike PCv1, PCv2 iterates the same URL for different cache |
86 # configurations. This may issue blink in-page hash navigations, | 96 # configurations. This may issue blink in-page hash navigations, |
87 # which isn't intended here. | 97 # which isn't intended here. |
88 with MarkTelemetryInternal(browser, 'avoid_double_hash_navigation'): | 98 with MarkTelemetryInternal(browser, 'avoid_double_hash_navigation'): |
89 tab = browser.tabs[0] | 99 tab = browser.tabs[0] |
90 tab.Navigate("http://does.not.exist") | 100 tab.Navigate("http://does.not.exist") |
91 tab.WaitForDocumentReadyStateToBeComplete() | 101 tab.WaitForDocumentReadyStateToBeComplete() |
92 return | 102 return |
93 | 103 WarmCache(page, browser) |
94 with MarkTelemetryInternal(browser, 'warm_cache'): | |
95 tab = browser.tabs[0] | |
96 tab.Navigate(page.url) | |
97 py_utils.WaitFor(tab.HasReachedQuiescence, 60) | |
98 tab.WaitForDocumentReadyStateToBeComplete() | |
99 tab.Navigate("about:blank") | |
100 tab.WaitForDocumentReadyStateToBeComplete() | |
OLD | NEW |