Mercurial > public > mercurial-scm > hg
diff hgext/blackbox.py @ 48573:011f5218ff2d
blackbox: add milliseconds to blackbox logs by default
The current second granularity is often not specific enough to
determine whether an hg command is happening before or after some
other event.
Given that starting a process takes on the order of 1ms (well, for
native processes. It's quite a bit more for python processes),
microseconds seems like unnecessary noise.
This also lines up behavior with the rust version, where we already
switched to millisecond precision.
Differential Revision: https://phab.mercurial-scm.org/D12005
author | Valentin Gatien-Baron <valentin.gatienbaron@gmail.com> |
---|---|
date | Mon, 17 Jan 2022 21:00:33 -0500 |
parents | fe4922564661 |
children | abbecb5cd6f3 |
line wrap: on
line diff
--- a/hgext/blackbox.py Mon Jan 17 20:47:46 2022 -0500 +++ b/hgext/blackbox.py Mon Jan 17 21:00:33 2022 -0500 @@ -101,11 +101,7 @@ b'ignore', default=lambda: [b'chgserver', b'cmdserver', b'extension'], ) -configitem( - b'blackbox', - b'date-format', - default=b'%Y/%m/%d %H:%M:%S', -) +configitem(b'blackbox', b'date-format', default=b'') _lastlogger = loggingutil.proxylogger() @@ -138,7 +134,14 @@ def _log(self, ui, event, msg, opts): default = ui.configdate(b'devel', b'default-date') - date = dateutil.datestr(default, ui.config(b'blackbox', b'date-format')) + dateformat = ui.config(b'blackbox', b'date-format') + if dateformat: + date = dateutil.datestr(default, dateformat) + else: + # We want to display milliseconds (more precision seems + # unnecessary). Since %.3f is not supported, use %f and truncate + # microseconds. + date = dateutil.datestr(default, b'%Y/%m/%d %H:%M:%S.%f')[:-3] user = procutil.getuser() pid = b'%d' % procutil.getpid() changed = b'' @@ -225,7 +228,9 @@ break # count the commands by matching lines like: 2013/01/23 19:13:36 root> - if re.match(br'^\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} .*> .*', line): + if re.match( + br'^\d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2}(.\d*)? .*> .*', line + ): count += 1 output.append(line)