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

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

Issue 3011263002: Add cache_temperature state "HOT" (Closed)
Patch Set: add decorators Created 3 years, 2 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 | telemetry/telemetry/page/cache_temperature_unittest.py » ('j') | 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
11 """ 11 """
12 12
13 import logging 13 import logging
14 14
15 import py_utils
16
17 # Default Cache Temperature. The page doesn't care which browser cache state 15 # Default Cache Temperature. The page doesn't care which browser cache state
18 # it is run on. 16 # it is run on.
19 ANY = 'any' 17 ANY = 'any'
20 # Emulates cold runs. Clears various caches and data with using tab.ClearCache() 18 # Emulates cold runs. Clears various caches and data with using tab.ClearCache()
21 # and tab.ClearDataForOrigin(). 19 # and tab.ClearDataForOrigin().
22 COLD = 'cold' 20 COLD = 'cold'
23 # Emulates warm runs. Ensures that the page was visited at least once just 21 # Emulates warm runs. Ensures that the page was visited once before the run.
24 # before the run.
25 WARM = 'warm' 22 WARM = 'warm'
23 # Emulates hot runs. Ensures that the page was visited at least twice before
24 # the run.
25 HOT = 'hot'
26 26
27 # These regacy states will be removed after chromium test scripts are adapted 27 # These regacy states will be removed after chromium test scripts are adapted
28 # to new states. 28 # to new states.
29 PCV1_COLD = COLD 29 PCV1_COLD = COLD
30 PCV1_WARM = WARM 30 PCV1_WARM = WARM
31 31
32 class MarkTelemetryInternal(object): 32 class MarkTelemetryInternal(object):
33 33
34 def __init__(self, browser, identifier): 34 def __init__(self, browser, identifier):
35 self.browser = browser 35 self.browser = browser
36 self.identifier = identifier 36 self.identifier = identifier
37 37
38 def __enter__(self): 38 def __enter__(self):
39 marker = 'telemetry.internal.%s.start' % self.identifier 39 marker = 'telemetry.internal.%s.start' % self.identifier
40 self.browser.tabs[0].ExecuteJavaScript( 40 self.browser.tabs[0].ExecuteJavaScript(
41 "console.time({{ marker }});", marker=marker) 41 "console.time({{ marker }});", marker=marker)
42 self.browser.tabs[0].ExecuteJavaScript( 42 self.browser.tabs[0].ExecuteJavaScript(
43 "console.timeEnd({{ marker }});", marker=marker) 43 "console.timeEnd({{ marker }});", marker=marker)
44 return self 44 return self
45 45
46 def __exit__(self, exception_type, exception_value, traceback): 46 def __exit__(self, exception_type, exception_value, traceback):
47 if exception_type: 47 if exception_type:
48 return True 48 return True
49
50 marker = 'telemetry.internal.%s.end' % self.identifier 49 marker = 'telemetry.internal.%s.end' % self.identifier
51 self.browser.tabs[0].ExecuteJavaScript( 50 self.browser.tabs[0].ExecuteJavaScript(
52 "console.time({{ marker }});", marker=marker) 51 "console.time({{ marker }});", marker=marker)
53 self.browser.tabs[0].ExecuteJavaScript( 52 self.browser.tabs[0].ExecuteJavaScript(
54 "console.timeEnd({{ marker }});", marker=marker) 53 "console.timeEnd({{ marker }});", marker=marker)
55 return True 54 return True
56 55
57 def ClearCache(browser): 56 def ClearCacheAndData(browser, url):
58 tab = browser.tabs[0] 57 tab = browser.tabs[0]
59 tab.ClearCache(force=True) 58 tab.ClearCache(force=True)
59 tab.ClearDataForOrigin(url)
60 60
61 def WarmCache(page, browser): 61 def WarmCache(page, browser, temperature):
62 with MarkTelemetryInternal(browser, 'warm_cache'): 62 with MarkTelemetryInternal(browser, 'warm_cache.%s' % temperature):
63 tab = browser.tabs[0] 63 tab = browser.tabs[0]
64 tab.Navigate(page.url) 64 page.RunNavigateSteps(tab.action_runner)
65 py_utils.WaitFor(tab.HasReachedQuiescence, 60) 65 page.RunPageInteractions(tab.action_runner)
66 tab.WaitForDocumentReadyStateToBeComplete()
67 tab.Navigate("about:blank") 66 tab.Navigate("about:blank")
68 tab.WaitForDocumentReadyStateToBeComplete() 67 tab.WaitForDocumentReadyStateToBeComplete()
68 # Stop service worker after each cache warming to ensure service worker
69 # script evaluation will be executed again in next navigation.
70 tab.StopAllServiceWorkers()
69 71
70 def EnsurePageCacheTemperature(page, browser, previous_page=None): 72 def EnsurePageCacheTemperature(page, browser, previous_page=None):
71 temperature = page.cache_temperature 73 temperature = page.cache_temperature
72 logging.info('PageCacheTemperature: %s', temperature) 74 logging.info('PageCacheTemperature: %s', temperature)
73 if temperature == ANY: 75 if temperature == ANY:
74 return 76 return
75 if temperature == COLD: 77 if temperature == COLD:
76 if previous_page is None: 78 if previous_page is None:
77 # DiskCache initialization is performed asynchronously on Chrome start-up. 79 # DiskCache initialization is performed asynchronously on Chrome start-up.
78 # Ensure that DiskCache is initialized before starting the measurement to 80 # Ensure that DiskCache is initialized before starting the measurement to
79 # avoid performance skew. 81 # avoid performance skew.
80 # This is done by navigating to an inexistent URL and then wait for the 82 # This is done by navigating to an inexistent URL and then wait for the
81 # navigation to complete. 83 # navigation to complete.
82 # TODO(kouhei) Consider moving this logic to PageCyclerStory 84 # TODO(kouhei) Consider moving this logic to PageCyclerStory
83 with MarkTelemetryInternal(browser, 'ensure_diskcache'): 85 with MarkTelemetryInternal(browser, 'ensure_diskcache'):
84 tab = browser.tabs[0] 86 tab = browser.tabs[0]
85 tab.Navigate("http://does.not.exist") 87 tab.Navigate("http://does.not.exist")
86 tab.WaitForDocumentReadyStateToBeComplete() 88 tab.WaitForDocumentReadyStateToBeComplete()
87 ClearCache(browser) 89 ClearCacheAndData(browser, page.url)
88 elif temperature == WARM: 90 elif temperature == WARM:
89 if (previous_page is not None and 91 if (previous_page is not None and
90 previous_page.url == page.url and 92 previous_page.url == page.url and
91 (previous_page.cache_temperature == COLD or 93 previous_page.cache_temperature == COLD):
92 previous_page.cache_temperature == WARM)):
93 if '#' in page.url: 94 if '#' in page.url:
94 # Navigate to inexistent URL to avoid in-page hash navigation. 95 # TODO(crbug.com/768780): Move this operation to tab.Navigate().
96 # This navigates to inexistent URL to avoid in-page hash navigation.
95 # Note: Unlike PCv1, PCv2 iterates the same URL for different cache 97 # Note: Unlike PCv1, PCv2 iterates the same URL for different cache
96 # configurations. This may issue blink in-page hash navigations, 98 # configurations. This may issue blink in-page hash navigations,
97 # which isn't intended here. 99 # which isn't intended here.
98 with MarkTelemetryInternal(browser, 'avoid_double_hash_navigation'): 100 with MarkTelemetryInternal(browser, 'avoid_double_hash_navigation'):
99 tab = browser.tabs[0] 101 tab = browser.tabs[0]
100 tab.Navigate("http://does.not.exist") 102 tab.Navigate("http://does.not.exist")
101 tab.WaitForDocumentReadyStateToBeComplete() 103 tab.WaitForDocumentReadyStateToBeComplete()
102 return 104 # Stop all service workers before running tests to measure the starting
103 WarmCache(page, browser) 105 # time of service worker too.
106 browser.tabs[0].StopAllServiceWorkers()
107 else:
108 ClearCacheAndData(browser, page.url)
109 WarmCache(page, browser, WARM)
110 elif temperature == HOT:
111 if (previous_page is not None and
112 previous_page.url == page.url and
113 previous_page.cache_temperature != ANY):
114 if previous_page.cache_temperature == COLD:
115 WarmCache(page, browser, HOT)
116 else:
117 if '#' in page.url:
118 # TODO(crbug.com/768780): Move this operation to tab.Navigate().
119 # This navigates to inexistent URL to avoid in-page hash navigation.
120 # Note: Unlike PCv1, PCv2 iterates the same URL for different cache
121 # configurations. This may issue blink in-page hash navigations,
122 # which isn't intended here.
123 with MarkTelemetryInternal(browser, 'avoid_double_hash_navigation'):
124 tab = browser.tabs[0]
125 tab.Navigate("http://does.not.exist")
126 tab.WaitForDocumentReadyStateToBeComplete()
127 # Stop all service workers before running tests to measure the starting
128 # time of service worker too.
129 browser.tabs[0].StopAllServiceWorkers()
130 else:
131 ClearCacheAndData(browser, page.url)
132 WarmCache(page, browser, WARM)
133 WarmCache(page, browser, HOT)
OLDNEW
« no previous file with comments | « no previous file | telemetry/telemetry/page/cache_temperature_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698