Print time of long running hook actions

We can use this to evaluate the usefulness of making hooks run in parallel.

Review URL: https://chromiumcodereview.appspot.com/18851005

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@211446 0039d316-1c4b-4281-b951-d872f2087c98
experimental/szager/collated-output
ilevy@chromium.org 12 years ago
parent 2327994797
commit c28d377739

@ -81,6 +81,7 @@ import posixpath
import pprint import pprint
import re import re
import sys import sys
import time
import urllib import urllib
import urlparse import urlparse
@ -780,6 +781,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
self._hooks_ran = True self._hooks_ran = True
for hook in self.GetHooks(options): for hook in self.GetHooks(options):
try: try:
start_time = time.time()
gclient_utils.CheckCallAndFilterAndHeader( gclient_utils.CheckCallAndFilterAndHeader(
hook, cwd=self.root.root_dir, always=True) hook, cwd=self.root.root_dir, always=True)
except (gclient_utils.Error, subprocess2.CalledProcessError), e: except (gclient_utils.Error, subprocess2.CalledProcessError), e:
@ -788,6 +790,11 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
# differently from VC failures. # differently from VC failures.
print >> sys.stderr, 'Error: %s' % str(e) print >> sys.stderr, 'Error: %s' % str(e)
sys.exit(2) sys.exit(2)
finally:
elapsed_time = time.time() - start_time
if elapsed_time > 10:
print "Hook '%s' took %.2f secs" % (
gclient_utils.CommandToStr(hook), elapsed_time)
def subtree(self, include_all): def subtree(self, include_all):
"""Breadth first recursion excluding root node.""" """Breadth first recursion excluding root node."""

@ -7,6 +7,7 @@
import codecs import codecs
import logging import logging
import os import os
import pipes
import Queue import Queue
import re import re
import stat import stat
@ -182,6 +183,11 @@ def safe_makedirs(tree):
raise raise
def CommandToStr(args):
"""Converts an arg list into a shell escaped string."""
return ' '.join(pipes.quote(arg) for arg in args)
def CheckCallAndFilterAndHeader(args, always=False, header=None, **kwargs): def CheckCallAndFilterAndHeader(args, always=False, header=None, **kwargs):
"""Adds 'header' support to CheckCallAndFilter. """Adds 'header' support to CheckCallAndFilter.
@ -192,7 +198,7 @@ def CheckCallAndFilterAndHeader(args, always=False, header=None, **kwargs):
stdout = kwargs.setdefault('stdout', sys.stdout) stdout = kwargs.setdefault('stdout', sys.stdout)
if header is None: if header is None:
header = "\n________ running '%s' in '%s'\n" % ( header = "\n________ running '%s' in '%s'\n" % (
' '.join(args), kwargs.get('cwd', '.')) CommandToStr(args), kwargs.get('cwd', '.'))
if always: if always:
stdout.write(header) stdout.write(header)

@ -28,7 +28,7 @@ class GclientUtilsUnittest(GclientUtilBase):
"""General gclient_utils.py tests.""" """General gclient_utils.py tests."""
def testMembersChanged(self): def testMembersChanged(self):
members = [ members = [
'Annotated', 'AutoFlush', 'CheckCallAndFilter', 'Annotated', 'AutoFlush', 'CheckCallAndFilter', 'CommandToStr',
'CheckCallAndFilterAndHeader', 'Error', 'ExecutionQueue', 'FileRead', 'CheckCallAndFilterAndHeader', 'Error', 'ExecutionQueue', 'FileRead',
'FileWrite', 'FindFileUpwards', 'FindGclientRoot', 'FileWrite', 'FindFileUpwards', 'FindGclientRoot',
'GetGClientRootAndEntries', 'GetEditor', 'IsDateRevision', 'GetGClientRootAndEntries', 'GetEditor', 'IsDateRevision',
@ -37,9 +37,9 @@ class GclientUtilsUnittest(GclientUtilBase):
'PrintableObject', 'RunEditor', 'GCLIENT_CHILDREN', 'PrintableObject', 'RunEditor', 'GCLIENT_CHILDREN',
'GCLIENT_CHILDREN_LOCK', 'GClientChildren', 'GCLIENT_CHILDREN_LOCK', 'GClientChildren',
'SplitUrlRevision', 'SyntaxErrorToError', 'UpgradeToHttps', 'Wrapper', 'SplitUrlRevision', 'SyntaxErrorToError', 'UpgradeToHttps', 'Wrapper',
'WorkItem', 'codecs', 'lockedmethod', 'logging', 'os', 'Queue', 're', 'WorkItem', 'codecs', 'lockedmethod', 'logging', 'os', 'pipes', 'Queue',
'rmtree', 'safe_makedirs', 'stat', 'subprocess', 'subprocess2', 'sys', 're', 'rmtree', 'safe_makedirs', 'stat', 'subprocess', 'subprocess2',
'tempfile', 'threading', 'time', 'urlparse', 'sys', 'tempfile', 'threading', 'time', 'urlparse',
] ]
# If this test fails, you should add the relevant test. # If this test fails, you should add the relevant test.
self.compareMembers(gclient_utils, members) self.compareMembers(gclient_utils, members)

Loading…
Cancel
Save