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

Unified Diff: tools/telemetry/telemetry/page_filter.py

Issue 12034007: Telemetry: add a page filter for excluding pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review (nduca) Created 7 years, 11 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/telemetry/telemetry/multi_page_benchmark_runner.py ('k') | tools/telemetry/telemetry/page_runner.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/page_filter.py
diff --git a/tools/telemetry/telemetry/page_filter.py b/tools/telemetry/telemetry/page_filter.py
new file mode 100644
index 0000000000000000000000000000000000000000..0aaa68e522c657900ea38407dcf37294c90fd554
--- /dev/null
+++ b/tools/telemetry/telemetry/page_filter.py
@@ -0,0 +1,40 @@
+# Copyright (c) 2013 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 optparse
+import re
+
+class PageFilter(object):
+ """Filters pages in the page set based on command line flags."""
+
+ def __init__(self, options):
+ if options.page_filter:
+ try:
+ self._page_regex = re.compile(options.page_filter)
+ except re.error:
+ raise Exception('--page-filter: invalid regex')
+ else:
+ self._page_regex = None
+
+ if options.page_filter_exclude:
+ try:
+ self._page_exclude_regex = re.compile(options.page_filter_exclude)
+ except re.error:
+ raise Exception('--page-filter-exclude: invalid regex')
+ else:
+ self._page_exclude_regex = None
+
+ def IsSelected(self, page):
+ if self._page_exclude_regex and self._page_exclude_regex.search(page.url):
+ return False
+ if self._page_regex:
+ return self._page_regex.search(page.url)
+
+ @staticmethod
+ def AddCommandLineOptions(parser):
+ group = optparse.OptionGroup(parser, 'Page filtering options')
+ group.add_option('--page-filter', dest='page_filter',
+ help='Use only pages whose URLs match the given filter regexp.')
+ group.add_option('--page-filter-exclude', dest='page_filter_exclude',
+ help='Exclude pages whose URLs match the given filter regexp.')
+ parser.add_option_group(group)
« no previous file with comments | « tools/telemetry/telemetry/multi_page_benchmark_runner.py ('k') | tools/telemetry/telemetry/page_runner.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698