From ab2e7f8f2e2199c8743862c6ed0c5f049861b308 Mon Sep 17 00:00:00 2001 From: Bruce Dawson Date: Fri, 15 Apr 2022 18:52:45 +0000 Subject: [PATCH] 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 Commit-Queue: Bruce Dawson --- presubmit_canned_checks.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 1d7499e25..d1b436004 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -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")