Add long running gmail memory benchmark for background tab.
[chromium-blink-merge.git] / tools / perf / PRESUBMIT.py
blob99ba8d5cb651308d9b40423ed3cbdb981c31666b
1 # Copyright 2012 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.
5 """Presubmit script for changes affecting tools/perf/.
7 See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
8 for more details about the presubmit API built into depot_tools.
9 """
11 import os
12 import re
13 import sys
16 def _CommonChecks(input_api, output_api):
17 """Performs common checks, which includes running pylint."""
18 results = []
19 old_sys_path = sys.path
20 try:
21 # Modules in tools/perf depend on telemetry.
22 sys.path = [os.path.join(os.pardir, 'telemetry')] + sys.path
23 results.extend(input_api.canned_checks.RunPylint(
24 input_api, output_api, black_list=[], pylintrc='pylintrc'))
25 results.extend(_CheckJson(input_api, output_api))
26 results.extend(_CheckWprShaFiles(input_api, output_api))
27 finally:
28 sys.path = old_sys_path
29 return results
32 def _CheckWprShaFiles(input_api, output_api):
33 """Check whether the wpr sha files have matching URLs."""
34 from catapult_base import cloud_storage
35 results = []
36 for affected_file in input_api.AffectedFiles(include_deletes=False):
37 filename = affected_file.AbsoluteLocalPath()
38 if not filename.endswith('wpr.sha1'):
39 continue
40 expected_hash = cloud_storage.ReadHash(filename)
41 is_wpr_file_uploaded = any(
42 cloud_storage.Exists(bucket, expected_hash)
43 for bucket in cloud_storage.BUCKET_ALIASES.itervalues())
44 if not is_wpr_file_uploaded:
45 wpr_filename = filename[:-5]
46 results.append(output_api.PresubmitError(
47 'There is no URLs matched for wpr sha file %s.\n'
48 'You can upload your new wpr archive file with the command:\n'
49 'depot_tools/upload_to_google_storage.py --bucket '
50 '<Your pageset\'s bucket> %s.\nFor more info: see '
51 'http://www.chromium.org/developers/telemetry/'
52 'record_a_page_set#TOC-Upload-the-recording-to-Cloud-Storage' %
53 (filename, wpr_filename)))
54 return results
57 def _CheckJson(input_api, output_api):
58 """Checks whether JSON files in this change can be parsed."""
59 for affected_file in input_api.AffectedFiles(include_deletes=False):
60 filename = affected_file.AbsoluteLocalPath()
61 if os.path.splitext(filename)[1] != '.json':
62 continue
63 try:
64 input_api.json.load(open(filename))
65 except ValueError:
66 return [output_api.PresubmitError('Error parsing JSON in %s!' % filename)]
67 return []
70 def CheckChangeOnUpload(input_api, output_api):
71 report = []
72 report.extend(_CommonChecks(input_api, output_api))
73 return report
76 def CheckChangeOnCommit(input_api, output_api):
77 report = []
78 report.extend(_CommonChecks(input_api, output_api))
79 return report
82 def _IsBenchmarksModified(change):
83 """Checks whether CL contains any modification to Telemetry benchmarks."""
84 for affected_file in change.AffectedFiles():
85 affected_file_path = affected_file.LocalPath()
86 file_path, _ = os.path.splitext(affected_file_path)
87 if (os.path.join('tools', 'perf', 'benchmarks') in file_path or
88 os.path.join('tools', 'perf', 'measurements') in file_path):
89 return True
90 return False
93 def PostUploadHook(cl, change, output_api):
94 """git cl upload will call this hook after the issue is created/modified.
96 This hook adds extra try bots list to the CL description in order to run
97 Telemetry benchmarks on Perf trybots in addtion to CQ trybots if the CL
98 contains any changes to Telemetry benchmarks.
99 """
100 benchmarks_modified = _IsBenchmarksModified(change)
101 rietveld_obj = cl.RpcServer()
102 issue = cl.issue
103 original_description = rietveld_obj.get_description(issue)
104 if not benchmarks_modified or re.search(
105 r'^CQ_EXTRA_TRYBOTS=.*', original_description, re.M | re.I):
106 return []
108 results = []
109 bots = [
110 'linux_perf_bisect',
111 'mac_perf_bisect',
112 'win_perf_bisect',
113 'android_nexus5_perf_bisect'
115 bots = ['tryserver.chromium.perf:%s' % s for s in bots]
116 bots_string = ';'.join(bots)
117 description = original_description
118 description += '\nCQ_EXTRA_TRYBOTS=%s' % bots_string
119 results.append(output_api.PresubmitNotifyResult(
120 'Automatically added Perf trybots to run Telemetry benchmarks on CQ.'))
122 if description != original_description:
123 rietveld_obj.update_description(issue, description)
125 return results