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

Unified Diff: tools/perf/page_sets/system_health/browsing_stories.py

Issue 2118293002: Add benchmark that imitates news reading. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 5 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 | « tools/perf/benchmarks/news.py ('k') | tools/perf/page_sets/system_health/platforms.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/perf/page_sets/system_health/browsing_stories.py
diff --git a/tools/perf/page_sets/system_health/browsing_stories.py b/tools/perf/page_sets/system_health/browsing_stories.py
new file mode 100644
index 0000000000000000000000000000000000000000..aed6f35dda9849d944e69f2ff7f6f6400a6bdfd1
--- /dev/null
+++ b/tools/perf/page_sets/system_health/browsing_stories.py
@@ -0,0 +1,222 @@
+# Copyright 2016 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 sys
+
+from page_sets.system_health import platforms
+from page_sets.system_health import system_health_story
+
+from telemetry import story
+
+
+class _BrowsingStory(system_health_story.SystemHealthStory):
+ """Abstract base class for browsing stories.
+
+ A browsing story visits items on the main page. Subclasses provide
+ CSS selector to identify the items and implement interaction using
+ the helper methods of this class.
+ """
+
+ IS_SINGLE_PAGE_APP = False
+ ITEM_SELECTOR = NotImplemented
+ ITEMS_TO_VISIT = 4
+
+ def __init__(self, story_set):
+ super(_BrowsingStory, self).__init__(
+ story_set, take_memory_measurement=False)
+
+ def _Item(self, index):
petrcermak 2016/07/08 12:46:03 nit: I think that this should be called something
ulan 2016/07/08 13:57:56 I inlined this function in NavigateToItem.
+ return 'document.querySelectorAll(\'%s\')[%d]' % (
petrcermak 2016/07/08 12:46:03 nit: I suggest you use " inside the string to avoi
ulan 2016/07/08 13:57:56 Done.
+ self.ITEM_SELECTOR, index)
+
+ def _WaitForItem(self, action_runner, index):
petrcermak 2016/07/08 12:46:03 Do you expect any subclass to override _WaitForIte
ulan 2016/07/08 13:57:57 Done. I thought that the media browsing benchmark
+ action_runner.WaitForElement(element_function=self._Item(index))
+
+ def _ClickItem(self, action_runner, index):
+ action_runner.ClickElement(element_function=self._Item(index))
+
+ def _WaitForNavigation(self, action_runner):
+ if not self.IS_SINGLE_PAGE_APP:
+ action_runner.WaitForNavigate()
+
+ def _NavigateBack(self, action_runner):
+ action_runner.ExecuteJavaScript('window.history.back()')
+ self._WaitForNavigation(action_runner)
+
+
+class _NewsBrowsingStory(_BrowsingStory):
+ """Abstract base class for news user stories.
+
+ A news story imitates browsing a news website:
+ 1. Load the main page.
+ 2. Open and scroll the first news item.
+ 3. Go back to the main page and scroll it.
+ 4. Open and scroll the second news item.
+ 5. Go back to the main page and scroll it.
+ 6. etc.
+ """
+
+ ITEM_READ_TIME_IN_SECONDS = 3
+ ITEM_SCROLL_REPEAT = 2
+ MAIN_PAGE_SCROLL_REPEAT = 0
+
+ def RunPageInteractions(self, action_runner):
ulan 2016/07/08 10:50:55 This one is not calling the SystemHealthStory.RunP
petrcermak 2016/07/08 12:46:03 I think that the best solution would be to move th
ulan 2016/07/08 13:57:57 I am using _DidLoadDocument as a hook to do specia
petrcermak 2016/07/08 15:06:28 I don't think that's true. You get action_runner.t
ulan 2016/07/08 15:40:47 Very nice, thank you! I didn't think about that. D
+ action_runner.tab.WaitForDocumentReadyStateToBeComplete()
+ self._DidLoadDocument(action_runner)
+ for i in xrange(self.ITEMS_TO_VISIT):
+ self._NavigateToNewsItem(action_runner, i)
+ self._ReadNewsItem(action_runner)
+ self._NavigateBack(action_runner)
+ self._ScrollMainPage(action_runner)
+
+ def _NavigateToNewsItem(self, action_runner, index):
petrcermak 2016/07/08 12:46:03 Why is this method not defined on _BrowsingStory?
ulan 2016/07/08 13:57:57 Done.
+ self._WaitForItem(action_runner, index)
petrcermak 2016/07/08 12:46:03 These methods build the item selector twice unnece
ulan 2016/07/08 13:57:56 Done, but I left WaitForNavigation in separate fun
petrcermak 2016/07/12 12:53:19 Acknowledged.
+ self._ClickItem(action_runner, index)
+ self._WaitForNavigation(action_runner)
+
+ def _ReadNewsItem(self, action_runner):
+ action_runner.tab.WaitForDocumentReadyStateToBeComplete()
+ action_runner.Wait(self.ITEM_READ_TIME_IN_SECONDS)
+ action_runner.RepeatableBrowserDrivenScroll(
+ repeat_count=self.ITEM_SCROLL_REPEAT)
+
+ def _ScrollMainPage(self, action_runner):
+ action_runner.tab.WaitForDocumentReadyStateToBeComplete()
+ action_runner.RepeatableBrowserDrivenScroll(
+ repeat_count=self.MAIN_PAGE_SCROLL_REPEAT)
+
+
+##############################################################################
+# News browsing stories.
+##############################################################################
+
nednguyen 2016/07/08 12:54:42 Looks like we don't cover any non-US news pages he
Hannes Payer (out of office) 2016/07/08 13:52:54 Hacker news is nice because it goes to other webpa
ulan 2016/07/08 13:57:57 Petr suggested to sync load:news and browse:news.
nednguyen 2016/07/08 14:01:35 Ah, that's a good point. Those I think we should u
nednguyen 2016/07/08 14:17:14 Keeping reddit is fine. I suggest we replace hacke
petrcermak 2016/07/08 15:06:29 Facebook and Twitter are in load:social. I suggest
ulan 2016/07/08 15:40:47 Changed facebook and twitter to browse:social. I'
petrcermak 2016/07/08 15:58:39 SGTM. Thanks :-)
+
+class RedditDesktopStory(_NewsBrowsingStory):
+ """The top website in http://www.alexa.com/topsites/category/News"""
+ NAME = 'browse:news:reddit'
+ URL = 'https://www.reddit.com/top/?sort=top&t=week'
+ SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY
+ ITEM_SELECTOR = '.thing .title > a'
+
+
+class RedditMobileStory(_NewsBrowsingStory):
+ """The top website in http://www.alexa.com/topsites/category/News"""
+ NAME = 'browse:news:reddit'
+ URL = 'https://m.reddit.com/?sort=top&time=week'
+ SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY
+ ITEM_SELECTOR = '.PostHeader__post-title-line'
+ IS_SINGLE_PAGE_APP = True
+
+
+class CnnStory(_NewsBrowsingStory):
+ """The second top website in http://www.alexa.com/topsites/category/News"""
+ NAME = 'browse:news:cnn'
+ URL = 'http://edition.cnn.com/'
+ ITEM_SELECTOR = '.cd__content > h3 > a'
+ # TODO(ulan): Enable this story on mobile once it uses less memory and
+ # does not crash with OOM.
+ SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY
+
+
+class NytimesMobileStory(_NewsBrowsingStory):
+ """The third top website in http://www.alexa.com/topsites/category/News"""
+ NAME = 'browse:news:nytimes'
+ URL = 'http://mobile.nytimes.com'
+ SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY
+ ITEM_SELECTOR = '.sfgAsset-link'
+ # Visiting more items causes OOM.
+ ITEMS_TO_VISIT = 2
+
+
+class NytimesDesktopStory(_NewsBrowsingStory):
+ """The third top website in http://www.alexa.com/topsites/category/News"""
+ NAME = 'browse:news:nytimes'
+ URL = 'http://www.nytimes.com'
+ SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY
+ ITEM_SELECTOR = '.story-heading > a'
+
+
+class HackerNewsStory(_NewsBrowsingStory):
+ NAME = 'browse:news:hackernews'
+ URL = 'https://news.ycombinator.com'
+ ITEM_SELECTOR = '.athing .title > a'
+
+
+# Facebook on desktop is not interesting because it embeds post comments
+# directly in the main timeline.
+class FacebookMobileStory(_NewsBrowsingStory):
+ NAME = 'browse:news:facebook'
+ URL = 'https://facebook.com/natgeo'
+ ITEM_SELECTOR = 'article ._5msj'
+ SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY
+
+
+class TwitterMobileStory(_NewsBrowsingStory):
+ NAME = 'browse:news:twitter'
+ URL = 'https://mobile.twitter.com/cnnbrk'
+ ITEM_SELECTOR = '.Tweet-text'
+ SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY
+
+
+class TwitterDesktopStory(_NewsBrowsingStory):
+ NAME = 'browse:news:twitter'
+ URL = 'https://twitter.com/cnnbrk'
+ ITEM_SELECTOR = '.tweet-text'
+ SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY
+ IS_SINGLE_PAGE_APP = True
+
+
+class WashingtonPostMobileStory(_NewsBrowsingStory):
+ """Progressive website"""
+ NAME = 'browse:news:washingtonpost'
+ URL = 'https://www.washingtonpost.com/pwa'
+ SUPPORTED_PLATFORMS = platforms.MOBILE_ONLY
+ ITEM_SELECTOR = '.hed > a'
+ IS_SINGLE_PAGE_APP = True
+
+ def _DidLoadDocument(self, action_runner):
+ # Close the popup window.
+ action_runner.ClickElement(selector='.close')
+
+
+class WashingtonPostDesktopStory(_NewsBrowsingStory):
+ NAME = 'browse:news:washingtonpost'
+ URL = 'https://www.washingtonpost.com'
+ SUPPORTED_PLATFORMS = platforms.DESKTOP_ONLY
+ ITEM_SELECTOR = '.headline > a'
+
+
+##############################################################################
+# Browsing story sets.
+##############################################################################
+
petrcermak 2016/07/08 12:46:03 nit: please add a second blank line here (there sh
ulan 2016/07/08 13:57:57 Done.
+def IterAllStoryClasses():
petrcermak 2016/07/08 12:46:03 This will also return the _NewsBrowsingStory abstr
ulan 2016/07/08 13:57:57 Done.
+ return system_health_story.IterAllStoryClasses(
+ sys.modules[__name__], _BrowsingStory)
+
+
+def IterAllNewsBrowsingStoryClasses():
petrcermak 2016/07/08 12:46:03 I'd make this private for the time being (leading
ulan 2016/07/08 13:57:56 Done.
+ return system_health_story.IterAllStoryClasses(
+ sys.modules[__name__], _NewsBrowsingStory)
+
+
+class _NewsBrowsingStorySet(story.StorySet):
+ PLATFORM = NotImplemented
+
+ def __init__(self):
+ super(_NewsBrowsingStorySet, self).__init__(
+ archive_data_file=('../data/news_%s.json' % self.PLATFORM),
+ cloud_storage_bucket=story.PARTNER_BUCKET)
+ for story_class in IterAllNewsBrowsingStoryClasses():
+ if self.PLATFORM not in story_class.SUPPORTED_PLATFORMS:
+ continue
+ self.AddStory(story_class(self))
+
+
+class DesktopNewsStorySet(_NewsBrowsingStorySet):
+ PLATFORM = platforms.DESKTOP
+
+
+class MobileNewsStorySet(_NewsBrowsingStorySet):
+ PLATFORM = platforms.MOBILE
« no previous file with comments | « tools/perf/benchmarks/news.py ('k') | tools/perf/page_sets/system_health/platforms.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698