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

Side by Side Diff: dashboard/dashboard/pinpoint/models/quest_generator.py

Issue 3002903002: [pinpoint] Refactor Quest Generator. (Closed)
Patch Set: Comments Created 3 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2017 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
5 import json
6
7 from dashboard.pinpoint.models import quest as quest_module
8
9
10 def QuestGenerator(request):
11 target = request.get('target')
12 if not target:
13 raise TypeError('Missing "target" argument.')
14
15 if target in ('telemetry_perf_tests', 'telemetry_perf_webview_tests'):
16 return TelemetryQuestGenerator(request)
17
18 return GTestQuestGenerator()
19
20
21 class GTestQuestGenerator(object):
22
23 def Quests(self):
24 # TODO
25 return ()
26
27 def AsDict(self):
28 return {}
29
30 def _Arguments(self):
31 return [
32 '--isolated-script-test-output', '${ISOLATED_OUTDIR}/output.json',
33 '--isolated-script-test-chartjson-output',
34 '${ISOLATED_OUTDIR}/chartjson-output.json',
35 ]
36
37
38 class TelemetryQuestGenerator(object):
39
40 def __init__(self, request):
41 self.configuration = request.get('configuration')
42 self.target = request.get('target')
43 self.dimensions = request.get('dimensions')
44 # TODO: Use the correct browser for Android and 64-bit Windows.
45 self.browser = 'release'
46 self.benchmark = request.get('benchmark')
47 self.story = request.get('story')
48 self.metric = request.get('metric')
49 self.repeat_count = int(request.get('repeat_count', 1))
50
51 # TODO: It's awkward to separate argument validation and quest generation,
52 # because they require the same conditional logic path. Refactor them to
53 # use the same code path. Maybe each Quest should handle validation for the
54 # arguments it requires.
55 if not self.configuration:
56 raise TypeError('Missing "configuration" argument.')
57
58 if not self.target:
59 raise TypeError('Missing "target" argument.')
60
61 if self.dimensions:
62 self.dimensions = json.loads(self.dimensions)
63 if not self.benchmark:
64 raise TypeError('Missing "benchmark" argument.')
65
66 def Quests(self):
67 quests = [quest_module.FindIsolate(self.configuration, self.target)]
68
69 if not self.dimensions:
70 return quests
71
72 quests.append(quest_module.RunTest(self.dimensions, self._Arguments()))
73
74 if not self.metric:
75 return quests
76
77 quests.append(quest_module.ReadChartJsonValue(self.metric, self.story))
78
79 return quests
80
81 def AsDict(self):
82 return {
83 'configuration': self.configuration,
84 'target': self.target,
85 'dimensions': self.dimensions,
86 'browser': self.browser,
87 'benchmark': self.benchmark,
88 'story': self.story,
89 'metric': self.metric,
90 'repeat_count': self.repeat_count,
91 }
92
93 def _Arguments(self):
94 arguments = [self.benchmark]
95
96 if self.story:
97 arguments += ('--story-filter', self.story)
98
99 if self.repeat_count != 1:
100 arguments += ('--pageset-repeat', str(self.repeat_count))
101
102 arguments += ('--browser', self.browser)
103
104 arguments += ('-v', '--upload-results', '--output-format', 'chartjson')
105 arguments += (
106 '--isolated-script-test-output', '${ISOLATED_OUTDIR}/output.json',
107 '--isolated-script-test-chartjson-output',
108 '${ISOLATED_OUTDIR}/chartjson-output.json',
109 )
110
111 return arguments
OLDNEW
« no previous file with comments | « dashboard/dashboard/pinpoint/models/job.py ('k') | dashboard/dashboard/pinpoint/models/quest_generator_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698