Improve canned checks output

When CheckLongLines finds problems it prints the first five, but this
gives no indication as to whether there are just five, or hundreds.
This change prints the number of long lines found.

The snapshot function in PanProjectChecks prints the elapsed time for
long checks, however it has two issues that make it inconvenient. One is
that it prints the time in ms which sounds great until you get a warning
that one of the checks is taking 2041373 ms (not kidding, although now
fixed) which is tricky to read. The other problem is that it was
actually measuring CPU time, not wall-clock time. This changes it to
print the time in seconds (to 0.1 seconds) and to measure elapsed
time.

Bug: 1309977
Change-Id: I7564a8cdf7bb3349b10ebbddbfe179188d4bf309
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3587726
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
changes/26/3587726/2
Bruce Dawson 3 years ago committed by LUCI CQ
parent 4b2e0bd8a4
commit ab2e7f8f2e

@ -584,7 +584,8 @@ def CheckLongLines(input_api, output_api, maxlen, source_file_filter=None):
errors += check_python_long_lines(
py_file_list, error_formatter=format_error)
if errors:
msg = 'Found lines longer than %s characters (first 5 shown).' % maxlen
msg = 'Found %d lines longer than %s characters (first 5 shown).' % (
len(errors), maxlen)
return [output_api.PresubmitPromptWarning(msg, items=errors[:5])]
return []
@ -1377,14 +1378,11 @@ def PanProjectChecks(input_api, output_api,
snapshot_memory = []
def snapshot(msg):
"""Measures & prints performance warning if a rule is running slow."""
if input_api.sys.version_info.major == 2:
dt2 = input_api.time.clock()
else:
dt2 = input_api.time.process_time()
dt2 = input_api.time.time()
if snapshot_memory:
delta_ms = int(1000*(dt2 - snapshot_memory[0]))
if delta_ms > 500:
print(" %s took a long time: %dms" % (snapshot_memory[1], delta_ms))
delta_s = dt2 - snapshot_memory[0]
if delta_s > 0.5:
print(" %s took a long time: %.1fs" % (snapshot_memory[1], delta_s))
snapshot_memory[:] = (dt2, msg)
snapshot("checking owners files format")

Loading…
Cancel
Save