Merge lp:~jelmer/brz/no-time-clock into lp:brz

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~jelmer/brz/no-time-clock
Merge into: lp:brz
Diff against target: 223 lines (+27/-29)
6 files modified
breezy/bzr/smart/medium.py (+2/-2)
breezy/bzr/smart/protocol.py (+10/-10)
breezy/bzr/smart/request.py (+2/-2)
breezy/graph.py (+2/-2)
breezy/osutils.py (+6/-9)
tools/time_graph.py (+5/-4)
To merge this branch: bzr merge lp:~jelmer/brz/no-time-clock
Reviewer Review Type Date Requested Status
Martin Packman Approve
Review via email: mp+363892@code.launchpad.net

Description of the change

Use time.perf_counter, which is replacing time.clock.

time.clock is going away in Python 3.8.

Also, rename osutils.timer_func to perf_counter for consistency.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Looks good, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'breezy/bzr/smart/medium.py'
--- breezy/bzr/smart/medium.py 2018-11-18 14:23:08 +0000
+++ breezy/bzr/smart/medium.py 2019-03-03 00:01:27 +0000
@@ -433,13 +433,13 @@
433 self.finished = True433 self.finished = True
434434
435 def _write_out(self, bytes):435 def _write_out(self, bytes):
436 tstart = osutils.timer_func()436 tstart = osutils.perf_counter()
437 osutils.send_all(self.socket, bytes, self._report_activity)437 osutils.send_all(self.socket, bytes, self._report_activity)
438 if 'hpss' in debug.debug_flags:438 if 'hpss' in debug.debug_flags:
439 thread_id = _thread.get_ident()439 thread_id = _thread.get_ident()
440 trace.mutter('%12s: [%s] %d bytes to the socket in %.3fs'440 trace.mutter('%12s: [%s] %d bytes to the socket in %.3fs'
441 % ('wrote', thread_id, len(bytes),441 % ('wrote', thread_id, len(bytes),
442 osutils.timer_func() - tstart))442 osutils.perf_counter() - tstart))
443443
444444
445class SmartServerPipeStreamMedium(SmartServerStreamMedium):445class SmartServerPipeStreamMedium(SmartServerStreamMedium):
446446
=== modified file 'breezy/bzr/smart/protocol.py'
--- breezy/bzr/smart/protocol.py 2018-11-22 22:15:05 +0000
+++ breezy/bzr/smart/protocol.py 2019-03-03 00:01:27 +0000
@@ -639,7 +639,7 @@
639 mutter('hpss call: %s', repr(args)[1:-1])639 mutter('hpss call: %s', repr(args)[1:-1])
640 if getattr(self._request._medium, 'base', None) is not None:640 if getattr(self._request._medium, 'base', None) is not None:
641 mutter(' (to %s)', self._request._medium.base)641 mutter(' (to %s)', self._request._medium.base)
642 self._request_start_time = osutils.timer_func()642 self._request_start_time = osutils.perf_counter()
643 self._write_args(args)643 self._write_args(args)
644 self._request.finished_writing()644 self._request.finished_writing()
645 self._last_verb = args[0]645 self._last_verb = args[0]
@@ -655,7 +655,7 @@
655 mutter(' (to %s)',655 mutter(' (to %s)',
656 self._request._medium._path)656 self._request._medium._path)
657 mutter(' %d bytes', len(body))657 mutter(' %d bytes', len(body))
658 self._request_start_time = osutils.timer_func()658 self._request_start_time = osutils.perf_counter()
659 if 'hpssdetail' in debug.debug_flags:659 if 'hpssdetail' in debug.debug_flags:
660 mutter('hpss body content: %s', body)660 mutter('hpss body content: %s', body)
661 self._write_args(args)661 self._write_args(args)
@@ -675,7 +675,7 @@
675 if getattr(self._request._medium, '_path', None) is not None:675 if getattr(self._request._medium, '_path', None) is not None:
676 mutter(' (to %s)',676 mutter(' (to %s)',
677 self._request._medium._path)677 self._request._medium._path)
678 self._request_start_time = osutils.timer_func()678 self._request_start_time = osutils.perf_counter()
679 self._write_args(args)679 self._write_args(args)
680 readv_bytes = self._serialise_offsets(body)680 readv_bytes = self._serialise_offsets(body)
681 bytes = self._encode_bulk_data(readv_bytes)681 bytes = self._encode_bulk_data(readv_bytes)
@@ -707,7 +707,7 @@
707 if 'hpss' in debug.debug_flags:707 if 'hpss' in debug.debug_flags:
708 if self._request_start_time is not None:708 if self._request_start_time is not None:
709 mutter(' result: %6.3fs %s',709 mutter(' result: %6.3fs %s',
710 osutils.timer_func() - self._request_start_time,710 osutils.perf_counter() - self._request_start_time,
711 repr(result)[1:-1])711 repr(result)[1:-1])
712 self._request_start_time = None712 self._request_start_time = None
713 else:713 else:
@@ -1173,9 +1173,9 @@
11731173
1174 def _trace(self, action, message, extra_bytes=None, include_time=False):1174 def _trace(self, action, message, extra_bytes=None, include_time=False):
1175 if self._response_start_time is None:1175 if self._response_start_time is None:
1176 self._response_start_time = osutils.timer_func()1176 self._response_start_time = osutils.perf_counter()
1177 if include_time:1177 if include_time:
1178 t = '%5.3fs ' % (time.clock() - self._response_start_time)1178 t = '%5.3fs ' % (osutils.perf_counter() - self._response_start_time)
1179 else:1179 else:
1180 t = ''1180 t = ''
1181 if extra_bytes is None:1181 if extra_bytes is None:
@@ -1318,7 +1318,7 @@
1318 base = getattr(self._medium_request._medium, 'base', None)1318 base = getattr(self._medium_request._medium, 'base', None)
1319 if base is not None:1319 if base is not None:
1320 mutter(' (to %s)', base)1320 mutter(' (to %s)', base)
1321 self._request_start_time = osutils.timer_func()1321 self._request_start_time = osutils.perf_counter()
1322 self._write_protocol_version()1322 self._write_protocol_version()
1323 self._write_headers(self._headers)1323 self._write_headers(self._headers)
1324 self._write_structure(args)1324 self._write_structure(args)
@@ -1336,7 +1336,7 @@
1336 if path is not None:1336 if path is not None:
1337 mutter(' (to %s)', path)1337 mutter(' (to %s)', path)
1338 mutter(' %d bytes', len(body))1338 mutter(' %d bytes', len(body))
1339 self._request_start_time = osutils.timer_func()1339 self._request_start_time = osutils.perf_counter()
1340 self._write_protocol_version()1340 self._write_protocol_version()
1341 self._write_headers(self._headers)1341 self._write_headers(self._headers)
1342 self._write_structure(args)1342 self._write_structure(args)
@@ -1355,7 +1355,7 @@
1355 path = getattr(self._medium_request._medium, '_path', None)1355 path = getattr(self._medium_request._medium, '_path', None)
1356 if path is not None:1356 if path is not None:
1357 mutter(' (to %s)', path)1357 mutter(' (to %s)', path)
1358 self._request_start_time = osutils.timer_func()1358 self._request_start_time = osutils.perf_counter()
1359 self._write_protocol_version()1359 self._write_protocol_version()
1360 self._write_headers(self._headers)1360 self._write_headers(self._headers)
1361 self._write_structure(args)1361 self._write_structure(args)
@@ -1372,7 +1372,7 @@
1372 path = getattr(self._medium_request._medium, '_path', None)1372 path = getattr(self._medium_request._medium, '_path', None)
1373 if path is not None:1373 if path is not None:
1374 mutter(' (to %s)', path)1374 mutter(' (to %s)', path)
1375 self._request_start_time = osutils.timer_func()1375 self._request_start_time = osutils.perf_counter()
1376 self.body_stream_started = False1376 self.body_stream_started = False
1377 self._write_protocol_version()1377 self._write_protocol_version()
1378 self._write_headers(self._headers)1378 self._write_headers(self._headers)
13791379
=== modified file 'breezy/bzr/smart/request.py'
--- breezy/bzr/smart/request.py 2018-11-11 04:08:32 +0000
+++ breezy/bzr/smart/request.py 2019-03-03 00:01:27 +0000
@@ -309,7 +309,7 @@
309 self.finished_reading = False309 self.finished_reading = False
310 self._command = None310 self._command = None
311 if 'hpss' in debug.debug_flags:311 if 'hpss' in debug.debug_flags:
312 self._request_start_time = osutils.timer_func()312 self._request_start_time = osutils.perf_counter()
313 self._thread_id = get_ident()313 self._thread_id = get_ident()
314314
315 def _trace(self, action, message, extra_bytes=None, include_time=False):315 def _trace(self, action, message, extra_bytes=None, include_time=False):
@@ -318,7 +318,7 @@
318 # that just putting it in a helper doesn't help a lot. And some state318 # that just putting it in a helper doesn't help a lot. And some state
319 # is taken from the instance.319 # is taken from the instance.
320 if include_time:320 if include_time:
321 t = '%5.3fs ' % (osutils.timer_func() - self._request_start_time)321 t = '%5.3fs ' % (osutils.perf_counter() - self._request_start_time)
322 else:322 else:
323 t = ''323 t = ''
324 if extra_bytes is None:324 if extra_bytes is None:
325325
=== modified file 'breezy/graph.py'
--- breezy/graph.py 2018-11-16 12:20:11 +0000
+++ breezy/graph.py 2019-03-03 00:01:27 +0000
@@ -612,11 +612,11 @@
612 # In the common case, we don't need to spider out far here, so612 # In the common case, we don't need to spider out far here, so
613 # avoid doing extra work.613 # avoid doing extra work.
614 if step_all_unique:614 if step_all_unique:
615 tstart = time.clock()615 tstart = osutils.perf_counter()
616 nodes = all_unique_searcher.step()616 nodes = all_unique_searcher.step()
617 common_to_all_unique_nodes.update(nodes)617 common_to_all_unique_nodes.update(nodes)
618 if 'graph' in debug.debug_flags:618 if 'graph' in debug.debug_flags:
619 tdelta = time.clock() - tstart619 tdelta = osutils.perf_counter() - tstart
620 trace.mutter('all_unique_searcher step() took %.3fs'620 trace.mutter('all_unique_searcher step() took %.3fs'
621 'for %d nodes (%d total), iteration: %s',621 'for %d nodes (%d total), iteration: %s',
622 tdelta, len(nodes), len(all_unique_searcher.seen),622 tdelta, len(nodes), len(all_unique_searcher.seen),
623623
=== modified file 'breezy/osutils.py'
--- breezy/osutils.py 2018-11-17 18:49:41 +0000
+++ breezy/osutils.py 2019-03-03 00:01:27 +0000
@@ -70,15 +70,6 @@
70 )70 )
7171
7272
73# Cross platform wall-clock time functionality with decent resolution.
74# On Linux ``time.clock`` returns only CPU time. On Windows, ``time.time()``
75# only has a resolution of ~15ms. Note that ``time.clock()`` is not
76# synchronized with ``time.time()``, this is only meant to be used to find
77# delta times by subtracting from another call to this function.
78timer_func = time.time
79if sys.platform == 'win32':
80 timer_func = time.clock
81
82# On win32, O_BINARY is used to indicate the file should73# On win32, O_BINARY is used to indicate the file should
83# be opened in binary mode, rather than text mode.74# be opened in binary mode, rather than text mode.
84# On other platforms, O_BINARY doesn't exist, because75# On other platforms, O_BINARY doesn't exist, because
@@ -2609,3 +2600,9 @@
2609 if sys.platform == "win32" and win32utils._is_pywintypes_error(evalue):2600 if sys.platform == "win32" and win32utils._is_pywintypes_error(evalue):
2610 return True2601 return True
2611 return False2602 return False
2603
2604
2605if PY3:
2606 perf_counter = time.perf_counter
2607else:
2608 perf_counter = time.clock
26122609
=== modified file 'tools/time_graph.py'
--- tools/time_graph.py 2018-11-16 12:20:11 +0000
+++ tools/time_graph.py 2019-03-03 00:01:27 +0000
@@ -8,6 +8,7 @@
8 branch,8 branch,
9 commands,9 commands,
10 graph,10 graph,
11 osutils,
11 ui,12 ui,
12 trace,13 trace,
13 _known_graph_py,14 _known_graph_py,
@@ -24,7 +25,7 @@
24trace.enable_default_logging()25trace.enable_default_logging()
25ui.ui_factory = text.TextUIFactory()26ui.ui_factory = text.TextUIFactory()
2627
27begin = time.clock()28begin = osutils.perf_counter()
28if len(args) >= 1:29if len(args) >= 1:
29 b = branch.Branch.open(args[0])30 b = branch.Branch.open(args[0])
30else:31else:
@@ -33,7 +34,7 @@
33 g = b.repository.get_graph()34 g = b.repository.get_graph()
34 parent_map = dict(p for p in g.iter_ancestry([b.last_revision()])35 parent_map = dict(p for p in g.iter_ancestry([b.last_revision()])
35 if p[1] is not None)36 if p[1] is not None)
36end = time.clock()37end = osutils.perf_counter()
3738
38print('Found %d nodes, loaded in %.3fs' % (len(parent_map), end - begin))39print('Found %d nodes, loaded in %.3fs' % (len(parent_map), end - begin))
3940
@@ -73,13 +74,13 @@
73 graph._counters[1] = 074 graph._counters[1] = 0
74 graph._counters[2] = 075 graph._counters[2] = 0
7576
76 begin = time.clock()77 begin = osutils.perf_counter()
77 g = graph_klass(parent_map)78 g = graph_klass(parent_map)
78 if opts.lsprof is not None:79 if opts.lsprof is not None:
79 heads = commands.apply_lsprofiled(opts.lsprof, all_heads_comp, g, comb)80 heads = commands.apply_lsprofiled(opts.lsprof, all_heads_comp, g, comb)
80 else:81 else:
81 heads = all_heads_comp(g, comb)82 heads = all_heads_comp(g, comb)
82 end = time.clock()83 end = osutils.perf_counter()
83 return dict(elapsed=(end - begin), graph=g, heads=heads)84 return dict(elapsed=(end - begin), graph=g, heads=heads)
8485
85def report(name, g):86def report(name, g):

Subscribers

People subscribed via source and target branches