Mercurial > hg
changeset 30975:22fbca1d11ed
mercurial: switch to util.timer for all interval timings
util.timer is now the best available interval timer, at the expense of not
having a known epoch. Let's use it whenever the epoch is irrelevant.
author | Simon Farnsworth <simonfar@fb.com> |
---|---|
date | Wed, 15 Feb 2017 13:17:39 -0800 |
parents | ae5d60bb70c9 |
children | e92daf156d5c |
files | contrib/hgperf contrib/perf.py mercurial/branchmap.py mercurial/dispatch.py mercurial/hook.py mercurial/profiling.py mercurial/repair.py mercurial/streamclone.py mercurial/tags.py mercurial/util.py |
diffstat | 10 files changed, 25 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/contrib/hgperf Wed Feb 15 11:53:59 2017 -0800 +++ b/contrib/hgperf Wed Feb 15 13:17:39 2017 -0800 @@ -55,17 +55,15 @@ import mercurial.util import mercurial.dispatch -import time - def timer(func, title=None): results = [] - begin = time.time() + begin = mercurial.util.timer() count = 0 while True: ostart = os.times() - cstart = time.time() + cstart = mercurial.util.timer() r = func() - cstop = time.time() + cstop = mercurial.util.timer() ostop = os.times() count += 1 a, b = ostart, ostop
--- a/contrib/perf.py Wed Feb 15 11:53:59 2017 -0800 +++ b/contrib/perf.py Wed Feb 15 13:17:39 2017 -0800 @@ -190,13 +190,13 @@ def _timer(fm, func, title=None): results = [] - begin = time.time() + begin = util.timer() count = 0 while True: ostart = os.times() - cstart = time.time() + cstart = util.timer() r = func() - cstop = time.time() + cstop = util.timer() ostop = os.times() count += 1 a, b = ostart, ostop
--- a/mercurial/branchmap.py Wed Feb 15 11:53:59 2017 -0800 +++ b/mercurial/branchmap.py Wed Feb 15 13:17:39 2017 -0800 @@ -9,7 +9,6 @@ import array import struct -import time from .node import ( bin, @@ -21,6 +20,7 @@ encoding, error, scmutil, + util, ) array = array.array @@ -261,7 +261,7 @@ missing heads, and a generator of nodes that are strictly a superset of heads missing, this function updates self to be correct. """ - starttime = time.time() + starttime = util.timer() cl = repo.changelog # collect new branch entries newbranches = {} @@ -314,7 +314,7 @@ self.tiprev = tiprev self.filteredhash = scmutil.filteredhash(repo, self.tiprev) - duration = time.time() - starttime + duration = util.timer() - starttime repo.ui.log('branchcache', 'updated %s branch cache in %.4f seconds\n', repo.filtername, duration)
--- a/mercurial/dispatch.py Wed Feb 15 11:53:59 2017 -0800 +++ b/mercurial/dispatch.py Wed Feb 15 13:17:39 2017 -0800 @@ -123,7 +123,7 @@ return -1 msg = ' '.join(' ' in a and repr(a) or a for a in req.args) - starttime = time.time() + starttime = util.timer() ret = None try: ret = _runcatch(req) @@ -135,7 +135,7 @@ raise ret = -1 finally: - duration = time.time() - starttime + duration = util.timer() - starttime req.ui.flush() req.ui.log("commandfinish", "%s exited %s after %0.2f seconds\n", msg, ret or 0, duration)
--- a/mercurial/hook.py Wed Feb 15 11:53:59 2017 -0800 +++ b/mercurial/hook.py Wed Feb 15 13:17:39 2017 -0800 @@ -9,7 +9,6 @@ import os import sys -import time from .i18n import _ from . import ( @@ -88,7 +87,7 @@ % (hname, funcname)) ui.note(_("calling hook %s: %s\n") % (hname, funcname)) - starttime = time.time() + starttime = util.timer() try: r = obj(ui=ui, repo=repo, hooktype=name, **args) @@ -106,7 +105,7 @@ ui.traceback() return True, True finally: - duration = time.time() - starttime + duration = util.timer() - starttime ui.log('pythonhook', 'pythonhook-%s: %s finished in %0.2f seconds\n', name, funcname, duration) if r: @@ -118,7 +117,7 @@ def _exthook(ui, repo, name, cmd, args, throw): ui.note(_("running hook %s: %s\n") % (name, cmd)) - starttime = time.time() + starttime = util.timer() env = {} # make in-memory changes visible to external process @@ -145,7 +144,7 @@ cwd = pycompat.getcwd() r = ui.system(cmd, environ=env, cwd=cwd) - duration = time.time() - starttime + duration = util.timer() - starttime ui.log('exthook', 'exthook-%s: %s finished in %0.2f seconds\n', name, cmd, duration) if r:
--- a/mercurial/profiling.py Wed Feb 15 11:53:59 2017 -0800 +++ b/mercurial/profiling.py Wed Feb 15 13:17:39 2017 -0800 @@ -8,7 +8,6 @@ from __future__ import absolute_import, print_function import contextlib -import time from .i18n import _ from . import ( @@ -66,7 +65,7 @@ collapse_recursion = True thread = flamegraph.ProfileThread(fp, 1.0 / freq, filter_, collapse_recursion) - start_time = time.clock() + start_time = util.timer() try: thread.start() yield @@ -74,7 +73,7 @@ thread.stop() thread.join() print('Collected %d stack frames (%d unique) in %2.2f seconds.' % ( - time.clock() - start_time, thread.num_frames(), + util.timer() - start_time, thread.num_frames(), thread.num_frames(unique=True))) @contextlib.contextmanager
--- a/mercurial/repair.py Wed Feb 15 11:53:59 2017 -0800 +++ b/mercurial/repair.py Wed Feb 15 13:17:39 2017 -0800 @@ -12,7 +12,6 @@ import hashlib import stat import tempfile -import time from .i18n import _ from .node import short @@ -905,10 +904,10 @@ # the operation nearly instantaneous and atomic (at least in well-behaved # environments). ui.write(_('replacing store...\n')) - tstart = time.time() + tstart = util.timer() util.rename(srcrepo.spath, backupvfs.join('store')) util.rename(dstrepo.spath, srcrepo.spath) - elapsed = time.time() - tstart + elapsed = util.timer() - tstart ui.write(_('store replacement complete; repository was inconsistent for ' '%0.1fs\n') % elapsed)
--- a/mercurial/streamclone.py Wed Feb 15 11:53:59 2017 -0800 +++ b/mercurial/streamclone.py Wed Feb 15 13:17:39 2017 -0800 @@ -8,7 +8,6 @@ from __future__ import absolute_import import struct -import time from .i18n import _ from . import ( @@ -297,7 +296,7 @@ (filecount, util.bytecount(bytecount))) handled_bytes = 0 repo.ui.progress(_('clone'), 0, total=bytecount, unit=_('bytes')) - start = time.time() + start = util.timer() # TODO: get rid of (potential) inconsistency # @@ -340,7 +339,7 @@ # streamclone-ed file at next access repo.invalidate(clearfilecache=True) - elapsed = time.time() - start + elapsed = util.timer() - start if elapsed <= 0: elapsed = 0.001 repo.ui.progress(_('clone'), None)
--- a/mercurial/tags.py Wed Feb 15 11:53:59 2017 -0800 +++ b/mercurial/tags.py Wed Feb 15 13:17:39 2017 -0800 @@ -14,7 +14,6 @@ import array import errno -import time from .node import ( bin, @@ -344,7 +343,7 @@ # potentially expensive search. return ([], {}, valid, None, True) - starttime = time.time() + starttime = util.timer() # Now we have to lookup the .hgtags filenode for every new head. # This is the most expensive part of finding tags, so performance @@ -359,7 +358,7 @@ fnodescache.write() - duration = time.time() - starttime + duration = util.timer() - starttime ui.log('tagscache', '%d/%d cache hits/lookups in %0.4f ' 'seconds\n',
--- a/mercurial/util.py Wed Feb 15 11:53:59 2017 -0800 +++ b/mercurial/util.py Wed Feb 15 13:17:39 2017 -0800 @@ -2797,13 +2797,13 @@ ''' def wrapper(*args, **kwargs): - start = time.time() + start = timer() indent = 2 _timenesting[0] += indent try: return func(*args, **kwargs) finally: - elapsed = time.time() - start + elapsed = timer() - start _timenesting[0] -= indent stderr.write('%s%s: %s\n' % (' ' * _timenesting[0], func.__name__,