Send a crash report when a hung process is detected.
[chromium-blink-merge.git] / tools / perf / PRESUBMIT.py
blobad11c24a0e1183ed359e668afe0b68963da89012
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 sys
15 def _CommonChecks(input_api, output_api):
16 """Performs common checks, which includes running pylint."""
17 results = []
18 old_sys_path = sys.path
19 try:
20 # Modules in tools/perf depend on telemetry.
21 sys.path = [os.path.join(os.pardir, 'telemetry')] + sys.path
22 results.extend(input_api.canned_checks.RunPylint(
23 input_api, output_api, black_list=[], pylintrc='pylintrc'))
24 results.extend(_CheckJson(input_api, output_api))
25 results.extend(_CheckWprShaFiles(input_api, output_api))
26 finally:
27 sys.path = old_sys_path
28 return results
31 def _CheckWprShaFiles(input_api, output_api):
32 """Check whether the wpr sha files have matching URLs."""
33 from telemetry.util import cloud_storage
34 results = []
35 for affected_file in input_api.AffectedFiles(include_deletes=False):
36 filename = affected_file.AbsoluteLocalPath()
37 if not filename.endswith('wpr.sha1'):
38 continue
39 expected_hash = cloud_storage.ReadHash(filename)
40 is_wpr_file_uploaded = any(
41 cloud_storage.Exists(bucket, expected_hash)
42 for bucket in cloud_storage.BUCKET_ALIASES.itervalues())
43 if not is_wpr_file_uploaded:
44 wpr_filename = filename[:-5]
45 results.append(output_api.PresubmitError(
46 'There is no URLs matched for wpr sha file %s.\n'
47 'You can upload your new wpr archive file with the command:\n'
48 'depot_tools/upload_to_google_storage.py --bucket '
49 '<Your pageset\'s bucket> %s.\nFor more info: see '
50 'http://www.chromium.org/developers/telemetry/'
51 'record_a_page_set#TOC-Upload-the-recording-to-Cloud-Storage' %
52 (filename, wpr_filename)))
53 return results
56 def _CheckJson(input_api, output_api):
57 """Checks whether JSON files in this change can be parsed."""
58 for affected_file in input_api.AffectedFiles(include_deletes=False):
59 filename = affected_file.AbsoluteLocalPath()
60 if os.path.splitext(filename)[1] != '.json':
61 continue
62 try:
63 input_api.json.load(open(filename))
64 except ValueError:
65 return [output_api.PresubmitError('Error parsing JSON in %s!' % filename)]
66 return []
69 def CheckChangeOnUpload(input_api, output_api):
70 report = []
71 report.extend(_CommonChecks(input_api, output_api))
72 return report
75 def CheckChangeOnCommit(input_api, output_api):
76 report = []
77 report.extend(_CommonChecks(input_api, output_api))
78 return report