1# Copyright 2014 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5from core import perf_benchmark 6 7from contrib.cluster_telemetry import ct_benchmarks_util 8from contrib.cluster_telemetry import page_set 9from contrib.cluster_telemetry import repaint_helpers 10 11from telemetry import benchmark 12from telemetry import story 13 14from py_utils import discover 15 16from measurements import skpicture_printer 17 18 19def _MatchPageSetName(story_set_name, story_set_base_dir): 20 story_sets = discover.DiscoverClasses(story_set_base_dir, story_set_base_dir, 21 story.StorySet).values() 22 for s in story_sets: 23 if story_set_name == s.Name(): 24 return s 25 return None 26 27 28@benchmark.Info(emails=['rmistry@chromium.org']) 29class SkpicturePrinter(perf_benchmark.PerfBenchmark): 30 31 @classmethod 32 def AddBenchmarkCommandLineArgs(cls, parser): 33 parser.add_option('--page-set-name', action='store', type='string') 34 parser.add_option('--page-set-base-dir', action='store', type='string') 35 parser.add_option('-s', '--skp-outdir', 36 help='Output directory for the SKP files') 37 38 @classmethod 39 def ProcessCommandLineArgs(cls, parser, args): 40 if not args.page_set_name: 41 parser.error('Please specify --page-set-name') 42 if not args.page_set_base_dir: 43 parser.error('Please specify --page-set-base-dir') 44 if not args.skp_outdir: 45 parser.error('Please specify --skp-outdir') 46 47 @classmethod 48 def Name(cls): 49 return 'skpicture_printer' 50 51 def CreatePageTest(self, options): 52 return skpicture_printer.SkpicturePrinter(options.skp_outdir) 53 54 def CreateStorySet(self, options): 55 story_set_class = _MatchPageSetName(options.page_set_name, 56 options.page_set_base_dir) 57 return story_set_class() 58 59 60class SkpicturePrinterCT(perf_benchmark.PerfBenchmark): 61 """Captures SKPs for Cluster Telemetry.""" 62 63 @classmethod 64 def Name(cls): 65 return 'skpicture_printer_ct' 66 67 @classmethod 68 def AddBenchmarkCommandLineArgs(cls, parser): 69 ct_benchmarks_util.AddBenchmarkCommandLineArgs(parser) 70 parser.add_option('-s', '--skp-outdir', 71 default=None, 72 help='Output directory for the SKP files') 73 74 @classmethod 75 def ProcessCommandLineArgs(cls, parser, args): 76 ct_benchmarks_util.ValidateCommandLineArgs(parser, args) 77 78 def CreatePageTest(self, options): 79 return skpicture_printer.SkpicturePrinter(options.skp_outdir) 80 81 def CreateStorySet(self, options): 82 return page_set.CTPageSet( 83 options.urls_list, options.user_agent, options.archive_data_file, 84 run_page_interaction_callback=repaint_helpers.WaitThenRepaint) 85