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

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

Issue 3011263002: Add cache_temperature state "HOT" (Closed)
Patch Set: call tab.StopAllServiceWorkers() after each navigation 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
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..bedd33a9ddea26c2d3d6c1a7c4db55d9dcdddf3e 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,19 @@ 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()
+ tab.StopAllServiceWorkers()
def EnsurePageCacheTemperature(page, browser, previous_page=None):
temperature = page.cache_temperature
@@ -84,12 +84,11 @@ 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.
# Note: Unlike PCv1, PCv2 iterates the same URL for different cache
@@ -99,5 +98,28 @@ def EnsurePageCacheTemperature(page, browser, previous_page=None):
tab = browser.tabs[0]
tab.Navigate("http://does.not.exist")
tab.WaitForDocumentReadyStateToBeComplete()
- return
- WarmCache(page, browser)
+ browser.tabs[0].StopAllServiceWorkers()
kouhei (in TOK) 2017/09/26 04:40:52 Would you add a comment why this is needed?
yukiy 2017/09/26 05:23:32 Done. Also added a comment for StopAllServiceWorke
+ 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:
+ # Navigate 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()
+ browser.tabs[0].StopAllServiceWorkers()
+ else:
+ ClearCacheAndData(browser, page.url)
+ WarmCache(page, browser, WARM)
+ WarmCache(page, browser, HOT)

Powered by Google App Engine
This is Rietveld 408576698