Commit 1d302153 authored by Yuheng Huang's avatar Yuheng Huang Committed by Chromium LUCI CQ

Tab Search: refactor benchmark story

Break up tabs related functionality to MultiTabStory to be more
reusable in other features.

Bug: 1099917
Change-Id: I7e1310ee4c680383b5347e1f046b7bb718e35837
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2631465
Commit-Queue: Yuheng Huang <yuhengh@chromium.org>
Reviewed-by: default avatarThomas Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844341}
parent bbf596a2
...@@ -42,7 +42,7 @@ tools/perf/run_benchmark run desktop_ui --browser-executable=out/Default/chrome ...@@ -42,7 +42,7 @@ tools/perf/run_benchmark run desktop_ui --browser-executable=out/Default/chrome
There are 3 ways to add metrics to the benchmarking code There are 3 ways to add metrics to the benchmarking code
1. Add UMA metrics to your code and include them in the [story definition](../../../../tools/perf/page_sets/tab_search_story.py). The listed UMA metrics will show up on the result page automatically. 1. Add UMA metrics to your code and include them in the [story definition](../../../../tools/perf/page_sets/desktop_ui/tab_search_story.py). The listed UMA metrics will show up on the result page automatically.
2. Add C++ trace with name starts with "webui_metric:". Make sure your trace has category "browser" or add other categories that you use to the story definition. For example: 2. Add C++ trace with name starts with "webui_metric:". Make sure your trace has category "browser" or add other categories that you use to the story definition. For example:
```c++ ```c++
void Foo::DoWork() { void Foo::DoWork() {
......
# Copyright 2021 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
MEASURE_FRAME_TIME_SCRIPT = '''
window.__webui_startMeasuringFrameTime = function(name) {
if (window.__webui_onRequestAnimationFrame) {
window.__webui_stopMeasuringFrameTime();
}
window.__webui_onRequestAnimationFrame = function() {
const now = performance.now();
if (window.__webui_lastAnimationFrameTime) {
performance.mark(
`${name}:${now - window.__webui_lastAnimationFrameTime}:benchmark_value`);
}
window.__webui_lastAnimationFrameTime = now;
if (window.__webui_onRequestAnimationFrame) {
window.__webui_lastRequestId = requestAnimationFrame(
window.__webui_onRequestAnimationFrame);
}
}
window.__webui_lastRequestId = requestAnimationFrame(
window.__webui_onRequestAnimationFrame);
}
window.__webui_stopMeasuringFrameTime = function() {
if (window.__webui_lastRequestId) {
cancelAnimationFrame(window.__webui_lastRequestId);
}
window.__webui_lastRequestId = null;
window.__webui_onRequestAnimationFrame = null;
window.__webui_lastAnimationFrameTime = null;
}
'''
START_MEASURING_FRAME_TIME = '''
window.__webui_startMeasuringFrameTime('%s')
'''
STOP_MEASURING_FRAME_TIME = '''
window.__webui_stopMeasuringFrameTime()
'''
MEASURE_JS_MEMORY = '''
performance.mark(
`%s:${performance.memory.usedJSHeapSize}:benchmark_value`);
'''
# Copyright 2021 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
import py_utils
from page_sets.desktop_ui.js_utils import MEASURE_FRAME_TIME_SCRIPT, \
START_MEASURING_FRAME_TIME, STOP_MEASURING_FRAME_TIME
from telemetry.page import page
class MultiTabStory(page.Page):
"""Base class for stories to open tabs with a list of urls"""
def __init__(self, story_set, extra_browser_args=None):
super(MultiTabStory, self).__init__(url=self.URL,
name=self.NAME,
page_set=story_set,
extra_browser_args=extra_browser_args)
def RunNavigateSteps(self, action_runner):
url_list = self.URL_LIST
tabs = action_runner.tab.browser.tabs
if len(url_list) > 0:
tabs[0].Navigate('https://' + url_list[0])
for url in url_list[1:]:
new_tab = tabs.New()
new_tab.Navigate('https://' + url)
if self.WAIT_FOR_NETWORK_QUIESCENCE:
for i, url in enumerate(url_list):
try:
tabs[i].action_runner.WaitForNetworkQuiescence()
except py_utils.TimeoutException:
logging.warning('WaitForNetworkQuiescence() timeout, url[%d]: %s' %
(i, url))
def StartMeasuringFrameTime(self, action_runner, name):
action_runner.ExecuteJavaScript(MEASURE_FRAME_TIME_SCRIPT)
action_runner.ExecuteJavaScript(START_MEASURING_FRAME_TIME % name)
def StopMeasuringFrameTime(self, action_runner):
action_runner.ExecuteJavaScript(STOP_MEASURING_FRAME_TIME)
def WillStartTracing(self, chrome_trace_config):
chrome_trace_config.category_filter.AddIncludedCategory('browser')
chrome_trace_config.category_filter.AddIncludedCategory('blink.user_timing')
def GetExtraTracingMetrics(self):
return ['webuiMetric']
...@@ -2,64 +2,12 @@ ...@@ -2,64 +2,12 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import logging
import py_utils import py_utils
from telemetry.page import page from page_sets.desktop_ui.js_utils import MEASURE_JS_MEMORY
from page_sets.desktop_ui.multitab_story import MultiTabStory
from page_sets.desktop_ui.url_list import TOP_URL
from telemetry.internal.actions.action_runner import ActionRunner from telemetry.internal.actions.action_runner import ActionRunner
TOP_URL = [
'google.com',
'youtube.com',
'amazon.com',
'facebook.com',
'zoom.us',
'yahoo.com',
'reddit.com',
'wikipedia.org',
'myshopify.com',
'ebay.com',
'instructure.com',
'office.com',
'netflix.com',
'bing.com',
'live.com',
'microsoft.com',
'espn.com',
'www.indeed.com',
'blogger.com',
'instagram.com',
'mozilla.org',
'cnn.com',
'apple.com',
'zillow.com',
'etsy.com',
'chase.com',
'nytimes.com',
'linkedin.com',
'dropbox.com',
'adobe.com',
'okta.com',
'craigslist.org',
'twitter.com',
'walmart.com',
'aliexpress.com',
'github.com',
'vimeo.com',
'quizlet.com',
'cnbc.com',
'imgur.com',
'wellsfargo.com',
'hulu.com',
'imdb.com',
'salesforce.com',
'homedepot.com',
'indeed.com',
'foxnews.com',
'msn.com',
'spotify.com',
'whatsapp.com',
]
TAB_SEARCH_BENCHMARK_UMA = [ TAB_SEARCH_BENCHMARK_UMA = [
'Tabs.TabSearch.CloseAction', 'Tabs.TabSearch.CloseAction',
'Tabs.TabSearch.NumTabsClosedPerInstance', 'Tabs.TabSearch.NumTabsClosedPerInstance',
...@@ -80,31 +28,9 @@ TAB_SEARCH_BENCHMARK_UMA = [ ...@@ -80,31 +28,9 @@ TAB_SEARCH_BENCHMARK_UMA = [
TAB_SEARCH_URL = 'chrome://tab-search/' TAB_SEARCH_URL = 'chrome://tab-search/'
class TabSearchStory(page.Page): class TabSearchStory(MultiTabStory):
"""Base class for tab search stories""" """Base class for tab search stories"""
def __init__(self, story_set, extra_browser_args=None):
super(TabSearchStory, self).__init__(url=self.URL,
name=self.NAME,
page_set=story_set,
extra_browser_args=extra_browser_args)
def RunNavigateSteps(self, action_runner):
url_list = self.URL_LIST
tabs = action_runner.tab.browser.tabs
if len(url_list) > 0:
tabs[0].Navigate('https://' + url_list[0])
for url in url_list[1:]:
new_tab = tabs.New()
new_tab.Navigate('https://' + url)
if self.WAIT_FOR_NETWORK_QUIESCENCE:
for i, url in enumerate(url_list):
try:
tabs[i].action_runner.WaitForNetworkQuiescence()
except py_utils.TimeoutException:
logging.warning('WaitForNetworkQuiescence() timeout, url[%d]: %s' %
(i, url))
def RunPageInteractions(self, action_runner): def RunPageInteractions(self, action_runner):
tabs = action_runner.tab.browser.tabs tabs = action_runner.tab.browser.tabs
...@@ -192,20 +118,9 @@ class TabSearchStory(page.Page): ...@@ -192,20 +118,9 @@ class TabSearchStory(page.Page):
self.StopMeasuringFrameTime(action_runner) self.StopMeasuringFrameTime(action_runner)
action_runner.Wait(1) action_runner.Wait(1)
def StartMeasuringFrameTime(self, action_runner, name):
action_runner.ExecuteJavaScript(MEASURE_FRAME_TIME_SCRIPT)
action_runner.ExecuteJavaScript(START_MEASURING_FRAME_TIME % name)
def StopMeasuringFrameTime(self, action_runner):
action_runner.ExecuteJavaScript(STOP_MEASURING_FRAME_TIME)
def WillStartTracing(self, chrome_trace_config): def WillStartTracing(self, chrome_trace_config):
super(TabSearchStory, self).WillStartTracing(chrome_trace_config)
chrome_trace_config.EnableUMAHistograms(*TAB_SEARCH_BENCHMARK_UMA) chrome_trace_config.EnableUMAHistograms(*TAB_SEARCH_BENCHMARK_UMA)
chrome_trace_config.category_filter.AddIncludedCategory('browser')
chrome_trace_config.category_filter.AddIncludedCategory('blink.user_timing')
def GetExtraTracingMetrics(self):
return ['webuiMetric']
class TabSearchStoryTop10(TabSearchStory): class TabSearchStoryTop10(TabSearchStory):
...@@ -330,47 +245,3 @@ class TabSearchStoryMeasureMemoryAfter(TabSearchStoryMeasureMemory): ...@@ -330,47 +245,3 @@ class TabSearchStoryMeasureMemoryAfter(TabSearchStoryMeasureMemory):
SCROLL_ELEMENT_FUNCTION = ''' SCROLL_ELEMENT_FUNCTION = '''
document.querySelector('tab-search-app').shadowRoot.getElementById('tabsList') document.querySelector('tab-search-app').shadowRoot.getElementById('tabsList')
''' '''
MEASURE_FRAME_TIME_SCRIPT = '''
window.__webui_startMeasuringFrameTime = function(name) {
if (window.__webui_onRequestAnimationFrame) {
window.__webui_stopMeasuringFrameTime();
}
window.__webui_onRequestAnimationFrame = function() {
const now = performance.now();
if (window.__webui_lastAnimationFrameTime) {
performance.mark(
`${name}:${now - window.__webui_lastAnimationFrameTime}:benchmark_value`);
}
window.__webui_lastAnimationFrameTime = now;
if (window.__webui_onRequestAnimationFrame) {
window.__webui_lastRequestId = requestAnimationFrame(
window.__webui_onRequestAnimationFrame);
}
}
window.__webui_lastRequestId = requestAnimationFrame(
window.__webui_onRequestAnimationFrame);
}
window.__webui_stopMeasuringFrameTime = function() {
if (window.__webui_lastRequestId) {
cancelAnimationFrame(window.__webui_lastRequestId);
}
window.__webui_lastRequestId = null;
window.__webui_onRequestAnimationFrame = null;
window.__webui_lastAnimationFrameTime = null;
}
'''
START_MEASURING_FRAME_TIME = '''
window.__webui_startMeasuringFrameTime('%s')
'''
STOP_MEASURING_FRAME_TIME = '''
window.__webui_stopMeasuringFrameTime()
'''
MEASURE_JS_MEMORY = '''
performance.mark(
`%s:${performance.memory.usedJSHeapSize}:benchmark_value`);
'''
# Copyright 2021 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
TOP_URL = [
'google.com',
'youtube.com',
'amazon.com',
'facebook.com',
'zoom.us',
'yahoo.com',
'reddit.com',
'wikipedia.org',
'myshopify.com',
'ebay.com',
'instructure.com',
'office.com',
'netflix.com',
'bing.com',
'live.com',
'microsoft.com',
'espn.com',
'www.indeed.com',
'blogger.com',
'instagram.com',
'mozilla.org',
'cnn.com',
'apple.com',
'zillow.com',
'etsy.com',
'chase.com',
'nytimes.com',
'linkedin.com',
'dropbox.com',
'adobe.com',
'okta.com',
'craigslist.org',
'twitter.com',
'walmart.com',
'aliexpress.com',
'github.com',
'vimeo.com',
'quizlet.com',
'cnbc.com',
'imgur.com',
'wellsfargo.com',
'hulu.com',
'imdb.com',
'salesforce.com',
'homedepot.com',
'indeed.com',
'foxnews.com',
'msn.com',
'spotify.com',
'whatsapp.com',
]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment