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

Side by Side Diff: telemetry/telemetry/page/cache_temperature.py

Issue 3013213002: Add methods for cache_temperature: ClearCache, WarmCache (Closed)
Patch Set: Created 3 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 with MarkTelemetryInternal(browser, 'clear_cache'):
59 any_tab = browser.tabs[0]
shimazu 2017/09/19 09:37:31 nit: |tab| seems enough.
yukiy 2017/09/21 08:23:44 Done.
60 any_tab.ClearCache(force=True)
61
62 def AvoidDoubleHashNavigation(page, browser):
63 if '#' in page.url:
shimazu 2017/09/19 09:37:31 nit: The opposite condition might be better to red
kouhei (in TOK) 2017/09/19 09:38:51 Would you mind keeping AvoidDoubleHashNavigation a
nednguyen 2017/09/19 09:50:05 +1. If the purpose is to make the EnsurePageCacheT
yukiy 2017/09/21 08:23:44 Done.
yukiy 2017/09/21 08:23:44 I chatted with kouhei@, and decided not to do this
yukiy 2017/09/21 08:23:44 Acknowledged.
64 # Navigate to inexistent URL to avoid in-page hash navigation.
65 # Note: Unlike PCv1, PCv2 iterates the same URL for different cache
66 # configurations. This may issue blink in-page hash navigations,
67 # which isn't intended here.
68 with MarkTelemetryInternal(browser, 'avoid_double_hash_navigation'):
69 tab = browser.tabs[0]
70 tab.Navigate("http://does.not.exist")
71 tab.WaitForDocumentReadyStateToBeComplete()
72
73 def WarmCache(page, browser):
74 with MarkTelemetryInternal(browser, 'warm_cache'):
75 tab = browser.tabs[0]
76 tab.Navigate(page.url)
77 py_utils.WaitFor(tab.HasReachedQuiescence, 60)
78 tab.WaitForDocumentReadyStateToBeComplete()
79 tab.Navigate("about:blank")
80 tab.WaitForDocumentReadyStateToBeComplete()
81
57 def EnsurePageCacheTemperature(page, browser, previous_page=None): 82 def EnsurePageCacheTemperature(page, browser, previous_page=None):
58 temperature = page.cache_temperature 83 temperature = page.cache_temperature
59 logging.info('PageCacheTemperature: %s', temperature) 84 logging.info('PageCacheTemperature: %s', temperature)
60
61 if temperature == ANY: 85 if temperature == ANY:
62 return 86 return
63
64 if temperature == COLD: 87 if temperature == COLD:
65 with MarkTelemetryInternal(browser, 'clear_cache'): 88 ClearCache(browser)
66 any_tab = browser.tabs[0]
67 any_tab.ClearCache(force=True)
68 elif temperature == WARM: 89 elif temperature == WARM:
69 if (previous_page is not None and 90 if (previous_page is not None and
70 previous_page.url == page.url and 91 previous_page.url == page.url and
71 (previous_page.cache_temperature == COLD or 92 (previous_page.cache_temperature == COLD or
72 previous_page.cache_temperature == WARM)): 93 previous_page.cache_temperature == WARM)):
73 if '#' in page.url: 94 AvoidDoubleHashNavigation(page, browser)
74 # Navigate to inexistent URL to avoid in-page hash navigation.
75 # Note: Unlike PCv1, PCv2 iterates the same URL for different cache
76 # configurations. This may issue blink in-page hash navigations,
77 # which isn't intended here.
78 with MarkTelemetryInternal(browser, 'avoid_double_hash_navigation'):
79 tab = browser.tabs[0]
80 tab.Navigate("http://does.not.exist")
81 tab.WaitForDocumentReadyStateToBeComplete()
82 return 95 return
83 96 WarmCache(page, browser)
84 with MarkTelemetryInternal(browser, 'warm_cache'):
85 tab = browser.tabs[0]
86 tab.Navigate(page.url)
87 py_utils.WaitFor(tab.HasReachedQuiescence, 60)
88 tab.WaitForDocumentReadyStateToBeComplete()
89 tab.Navigate("about:blank")
90 tab.WaitForDocumentReadyStateToBeComplete()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698