From 2bdc49fadc41444341baae26d9688173be2bc77f Mon Sep 17 00:00:00 2001 From: Bruce Dawson Date: Fri, 21 May 2021 19:13:03 +0000 Subject: [PATCH] Warn on long presubmits, like on long hooks Presubmits when uploading occasionally take a very long time - over a minute - and after the fact there is no easy way to know why. This makes fixes to slow presubmits take longer. This change builds on crrev.com/c/2532895 to print a message when any individual presubmit function takes longer than ten seconds. During normal usage this is a NOP but it will presumably find the long poles when presubmits are running particularly slowly. This is similar to gclient runhooks where any hooks that take longer than ten seconds have their run time printed. Change-Id: If57ed35d7a7d221f6380e9b97cf72af56f75e441 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2911594 Reviewed-by: Dirk Pranke Commit-Queue: Bruce Dawson --- presubmit_support.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/presubmit_support.py b/presubmit_support.py index 90cac72e8..8c72f7e8a 100755 --- a/presubmit_support.py +++ b/presubmit_support.py @@ -1678,8 +1678,11 @@ class PresubmitExecuter(object): e_value), e_tb) + elapsed_time = time_time() - start_time + if elapsed_time > 10.0: + sys.stdout.write( + '%s took %.1fs to run.\n' % (function_name, elapsed_time)) if sink: - elapsed_time = time_time() - start_time status = rdb_wrapper.STATUS_PASS if any(r.fatal for r in result): status = rdb_wrapper.STATUS_FAIL