Commit 58542b7f authored by Edward Lesmes's avatar Edward Lesmes Committed by LUCI CQ

gclient: Report hook metrics

Change-Id: I34eed860f9fd68c2382cdcf955f2f5e10ebb31c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2946936
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: 's avatarAnthony Polito <apolito@google.com>
parent 6d099d54
......@@ -245,19 +245,31 @@ class Hook(object):
if cmd[0] == 'vpython' and _detect_host_os() == 'win':
cmd[0] += '.bat'
exit_code = 2
try:
start_time = time.time()
gclient_utils.CheckCallAndFilter(
cmd, cwd=self.effective_cwd, print_stdout=True, show_header=True,
always_show_header=self._verbose)
exit_code = 0
except (gclient_utils.Error, subprocess2.CalledProcessError) as e:
# Use a discrete exit status code of 2 to indicate that a hook action
# failed. Users of this script may wish to treat hook action failures
# differently from VC failures.
print('Error: %s' % str(e), file=sys.stderr)
sys.exit(2)
sys.exit(exit_code)
finally:
elapsed_time = time.time() - start_time
metrics.collector.add_repeated('hooks', {
'action': gclient_utils.CommandToStr(cmd),
'name': self._name,
'cwd': os.path.relpath(
os.path.normpath(self.effective_cwd),
self._cwd_base),
'condition': self._condition,
'execution_time': elapsed_time,
'exit_code': exit_code,
})
if elapsed_time > 10:
print("Hook '%s' took %.2f secs" % (
gclient_utils.CommandToStr(cmd), elapsed_time))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment