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

Unified Diff: telemetry/telemetry/page/cache_temperature.py

Issue 3011263002: Add cache_temperature state "HOT" (Closed)
Patch Set: add decorators 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | telemetry/telemetry/page/cache_temperature_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: telemetry/telemetry/page/cache_temperature.py
diff --git a/telemetry/telemetry/page/cache_temperature.py b/telemetry/telemetry/page/cache_temperature.py
index 3e22d02eac6e41389f4778bb07582113bbae4631..c7ed43e96c423aacbfc1319a6dcaf183c32135ea 100644
--- a/telemetry/telemetry/page/cache_temperature.py
+++ b/telemetry/telemetry/page/cache_temperature.py
@@ -12,17 +12,17 @@ https://docs.google.com/document/u/1/d/12D7tkhZi887g9d0U2askU9JypU_wYiEI7Lw0bfwx
import logging
-import py_utils
-
# Default Cache Temperature. The page doesn't care which browser cache state
# it is run on.
ANY = 'any'
# Emulates cold runs. Clears various caches and data with using tab.ClearCache()
# and tab.ClearDataForOrigin().
COLD = 'cold'
-# Emulates warm runs. Ensures that the page was visited at least once just
-# before the run.
+# Emulates warm runs. Ensures that the page was visited once before the run.
WARM = 'warm'
+# Emulates hot runs. Ensures that the page was visited at least twice before
+# the run.
+HOT = 'hot'
# These regacy states will be removed after chromium test scripts are adapted
# to new states.
@@ -46,7 +46,6 @@ class MarkTelemetryInternal(object):
def __exit__(self, exception_type, exception_value, traceback):
if exception_type:
return True
-
marker = 'telemetry.internal.%s.end' % self.identifier
self.browser.tabs[0].ExecuteJavaScript(
"console.time({{ marker }});", marker=marker)
@@ -54,18 +53,21 @@ class MarkTelemetryInternal(object):
"console.timeEnd({{ marker }});", marker=marker)
return True
-def ClearCache(browser):
+def ClearCacheAndData(browser, url):
tab = browser.tabs[0]
tab.ClearCache(force=True)
+ tab.ClearDataForOrigin(url)
-def WarmCache(page, browser):
- with MarkTelemetryInternal(browser, 'warm_cache'):
+def WarmCache(page, browser, temperature):
+ with MarkTelemetryInternal(browser, 'warm_cache.%s' % temperature):
tab = browser.tabs[0]
- tab.Navigate(page.url)
- py_utils.WaitFor(tab.HasReachedQuiescence, 60)
- tab.WaitForDocumentReadyStateToBeComplete()
+ page.RunNavigateSteps(tab.action_runner)
+ page.RunPageInteractions(tab.action_runner)
tab.Navigate("about:blank")
tab.WaitForDocumentReadyStateToBeComplete()
+ # Stop service worker after each cache warming to ensure service worker
+ # script evaluation will be executed again in next navigation.
+ tab.StopAllServiceWorkers()
def EnsurePageCacheTemperature(page, browser, previous_page=None):
temperature = page.cache_temperature
@@ -84,14 +86,14 @@ def EnsurePageCacheTemperature(page, browser, previous_page=None):
tab = browser.tabs[0]
tab.Navigate("http://does.not.exist")
tab.WaitForDocumentReadyStateToBeComplete()
- ClearCache(browser)
+ ClearCacheAndData(browser, page.url)
elif temperature == WARM:
if (previous_page is not None and
previous_page.url == page.url and
- (previous_page.cache_temperature == COLD or
- previous_page.cache_temperature == WARM)):
+ previous_page.cache_temperature == COLD):
if '#' in page.url:
- # Navigate to inexistent URL to avoid in-page hash navigation.
+ # TODO(crbug.com/768780): Move this operation to tab.Navigate().
+ # This navigates to inexistent URL to avoid in-page hash navigation.
# Note: Unlike PCv1, PCv2 iterates the same URL for different cache
# configurations. This may issue blink in-page hash navigations,
# which isn't intended here.
@@ -99,5 +101,33 @@ def EnsurePageCacheTemperature(page, browser, previous_page=None):
tab = browser.tabs[0]
tab.Navigate("http://does.not.exist")
tab.WaitForDocumentReadyStateToBeComplete()
- return
- WarmCache(page, browser)
+ # Stop all service workers before running tests to measure the starting
+ # time of service worker too.
+ browser.tabs[0].StopAllServiceWorkers()
+ else:
+ ClearCacheAndData(browser, page.url)
+ WarmCache(page, browser, WARM)
+ elif temperature == HOT:
+ if (previous_page is not None and
+ previous_page.url == page.url and
+ previous_page.cache_temperature != ANY):
+ if previous_page.cache_temperature == COLD:
+ WarmCache(page, browser, HOT)
+ else:
+ if '#' in page.url:
+ # TODO(crbug.com/768780): Move this operation to tab.Navigate().
+ # This navigates to inexistent URL to avoid in-page hash navigation.
+ # Note: Unlike PCv1, PCv2 iterates the same URL for different cache
+ # configurations. This may issue blink in-page hash navigations,
+ # which isn't intended here.
+ with MarkTelemetryInternal(browser, 'avoid_double_hash_navigation'):
+ tab = browser.tabs[0]
+ tab.Navigate("http://does.not.exist")
+ tab.WaitForDocumentReadyStateToBeComplete()
+ # Stop all service workers before running tests to measure the starting
+ # time of service worker too.
+ browser.tabs[0].StopAllServiceWorkers()
+ else:
+ ClearCacheAndData(browser, page.url)
+ WarmCache(page, browser, WARM)
+ WarmCache(page, browser, HOT)
« 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