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

Proposed by Jelmer Vernooij on 2019-03-02
Status: Merged
Approved by: Jelmer Vernooij on 2019-03-03
Approved revision: 7292
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 2019-03-02 Approve on 2019-03-03
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.
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
1=== modified file 'breezy/bzr/smart/medium.py'
2--- breezy/bzr/smart/medium.py 2018-11-18 14:23:08 +0000
3+++ breezy/bzr/smart/medium.py 2019-03-03 00:01:27 +0000
4@@ -433,13 +433,13 @@
5 self.finished = True
6
7 def _write_out(self, bytes):
8- tstart = osutils.timer_func()
9+ tstart = osutils.perf_counter()
10 osutils.send_all(self.socket, bytes, self._report_activity)
11 if 'hpss' in debug.debug_flags:
12 thread_id = _thread.get_ident()
13 trace.mutter('%12s: [%s] %d bytes to the socket in %.3fs'
14 % ('wrote', thread_id, len(bytes),
15- osutils.timer_func() - tstart))
16+ osutils.perf_counter() - tstart))
17
18
19 class SmartServerPipeStreamMedium(SmartServerStreamMedium):
20
21=== modified file 'breezy/bzr/smart/protocol.py'
22--- breezy/bzr/smart/protocol.py 2018-11-22 22:15:05 +0000
23+++ breezy/bzr/smart/protocol.py 2019-03-03 00:01:27 +0000
24@@ -639,7 +639,7 @@
25 mutter('hpss call: %s', repr(args)[1:-1])
26 if getattr(self._request._medium, 'base', None) is not None:
27 mutter(' (to %s)', self._request._medium.base)
28- self._request_start_time = osutils.timer_func()
29+ self._request_start_time = osutils.perf_counter()
30 self._write_args(args)
31 self._request.finished_writing()
32 self._last_verb = args[0]
33@@ -655,7 +655,7 @@
34 mutter(' (to %s)',
35 self._request._medium._path)
36 mutter(' %d bytes', len(body))
37- self._request_start_time = osutils.timer_func()
38+ self._request_start_time = osutils.perf_counter()
39 if 'hpssdetail' in debug.debug_flags:
40 mutter('hpss body content: %s', body)
41 self._write_args(args)
42@@ -675,7 +675,7 @@
43 if getattr(self._request._medium, '_path', None) is not None:
44 mutter(' (to %s)',
45 self._request._medium._path)
46- self._request_start_time = osutils.timer_func()
47+ self._request_start_time = osutils.perf_counter()
48 self._write_args(args)
49 readv_bytes = self._serialise_offsets(body)
50 bytes = self._encode_bulk_data(readv_bytes)
51@@ -707,7 +707,7 @@
52 if 'hpss' in debug.debug_flags:
53 if self._request_start_time is not None:
54 mutter(' result: %6.3fs %s',
55- osutils.timer_func() - self._request_start_time,
56+ osutils.perf_counter() - self._request_start_time,
57 repr(result)[1:-1])
58 self._request_start_time = None
59 else:
60@@ -1173,9 +1173,9 @@
61
62 def _trace(self, action, message, extra_bytes=None, include_time=False):
63 if self._response_start_time is None:
64- self._response_start_time = osutils.timer_func()
65+ self._response_start_time = osutils.perf_counter()
66 if include_time:
67- t = '%5.3fs ' % (time.clock() - self._response_start_time)
68+ t = '%5.3fs ' % (osutils.perf_counter() - self._response_start_time)
69 else:
70 t = ''
71 if extra_bytes is None:
72@@ -1318,7 +1318,7 @@
73 base = getattr(self._medium_request._medium, 'base', None)
74 if base is not None:
75 mutter(' (to %s)', base)
76- self._request_start_time = osutils.timer_func()
77+ self._request_start_time = osutils.perf_counter()
78 self._write_protocol_version()
79 self._write_headers(self._headers)
80 self._write_structure(args)
81@@ -1336,7 +1336,7 @@
82 if path is not None:
83 mutter(' (to %s)', path)
84 mutter(' %d bytes', len(body))
85- self._request_start_time = osutils.timer_func()
86+ self._request_start_time = osutils.perf_counter()
87 self._write_protocol_version()
88 self._write_headers(self._headers)
89 self._write_structure(args)
90@@ -1355,7 +1355,7 @@
91 path = getattr(self._medium_request._medium, '_path', None)
92 if path is not None:
93 mutter(' (to %s)', path)
94- self._request_start_time = osutils.timer_func()
95+ self._request_start_time = osutils.perf_counter()
96 self._write_protocol_version()
97 self._write_headers(self._headers)
98 self._write_structure(args)
99@@ -1372,7 +1372,7 @@
100 path = getattr(self._medium_request._medium, '_path', None)
101 if path is not None:
102 mutter(' (to %s)', path)
103- self._request_start_time = osutils.timer_func()
104+ self._request_start_time = osutils.perf_counter()
105 self.body_stream_started = False
106 self._write_protocol_version()
107 self._write_headers(self._headers)
108
109=== modified file 'breezy/bzr/smart/request.py'
110--- breezy/bzr/smart/request.py 2018-11-11 04:08:32 +0000
111+++ breezy/bzr/smart/request.py 2019-03-03 00:01:27 +0000
112@@ -309,7 +309,7 @@
113 self.finished_reading = False
114 self._command = None
115 if 'hpss' in debug.debug_flags:
116- self._request_start_time = osutils.timer_func()
117+ self._request_start_time = osutils.perf_counter()
118 self._thread_id = get_ident()
119
120 def _trace(self, action, message, extra_bytes=None, include_time=False):
121@@ -318,7 +318,7 @@
122 # that just putting it in a helper doesn't help a lot. And some state
123 # is taken from the instance.
124 if include_time:
125- t = '%5.3fs ' % (osutils.timer_func() - self._request_start_time)
126+ t = '%5.3fs ' % (osutils.perf_counter() - self._request_start_time)
127 else:
128 t = ''
129 if extra_bytes is None:
130
131=== modified file 'breezy/graph.py'
132--- breezy/graph.py 2018-11-16 12:20:11 +0000
133+++ breezy/graph.py 2019-03-03 00:01:27 +0000
134@@ -612,11 +612,11 @@
135 # In the common case, we don't need to spider out far here, so
136 # avoid doing extra work.
137 if step_all_unique:
138- tstart = time.clock()
139+ tstart = osutils.perf_counter()
140 nodes = all_unique_searcher.step()
141 common_to_all_unique_nodes.update(nodes)
142 if 'graph' in debug.debug_flags:
143- tdelta = time.clock() - tstart
144+ tdelta = osutils.perf_counter() - tstart
145 trace.mutter('all_unique_searcher step() took %.3fs'
146 'for %d nodes (%d total), iteration: %s',
147 tdelta, len(nodes), len(all_unique_searcher.seen),
148
149=== modified file 'breezy/osutils.py'
150--- breezy/osutils.py 2018-11-17 18:49:41 +0000
151+++ breezy/osutils.py 2019-03-03 00:01:27 +0000
152@@ -70,15 +70,6 @@
153 )
154
155
156-# Cross platform wall-clock time functionality with decent resolution.
157-# On Linux ``time.clock`` returns only CPU time. On Windows, ``time.time()``
158-# only has a resolution of ~15ms. Note that ``time.clock()`` is not
159-# synchronized with ``time.time()``, this is only meant to be used to find
160-# delta times by subtracting from another call to this function.
161-timer_func = time.time
162-if sys.platform == 'win32':
163- timer_func = time.clock
164-
165 # On win32, O_BINARY is used to indicate the file should
166 # be opened in binary mode, rather than text mode.
167 # On other platforms, O_BINARY doesn't exist, because
168@@ -2609,3 +2600,9 @@
169 if sys.platform == "win32" and win32utils._is_pywintypes_error(evalue):
170 return True
171 return False
172+
173+
174+if PY3:
175+ perf_counter = time.perf_counter
176+else:
177+ perf_counter = time.clock
178
179=== modified file 'tools/time_graph.py'
180--- tools/time_graph.py 2018-11-16 12:20:11 +0000
181+++ tools/time_graph.py 2019-03-03 00:01:27 +0000
182@@ -8,6 +8,7 @@
183 branch,
184 commands,
185 graph,
186+ osutils,
187 ui,
188 trace,
189 _known_graph_py,
190@@ -24,7 +25,7 @@
191 trace.enable_default_logging()
192 ui.ui_factory = text.TextUIFactory()
193
194-begin = time.clock()
195+begin = osutils.perf_counter()
196 if len(args) >= 1:
197 b = branch.Branch.open(args[0])
198 else:
199@@ -33,7 +34,7 @@
200 g = b.repository.get_graph()
201 parent_map = dict(p for p in g.iter_ancestry([b.last_revision()])
202 if p[1] is not None)
203-end = time.clock()
204+end = osutils.perf_counter()
205
206 print('Found %d nodes, loaded in %.3fs' % (len(parent_map), end - begin))
207
208@@ -73,13 +74,13 @@
209 graph._counters[1] = 0
210 graph._counters[2] = 0
211
212- begin = time.clock()
213+ begin = osutils.perf_counter()
214 g = graph_klass(parent_map)
215 if opts.lsprof is not None:
216 heads = commands.apply_lsprofiled(opts.lsprof, all_heads_comp, g, comb)
217 else:
218 heads = all_heads_comp(g, comb)
219- end = time.clock()
220+ end = osutils.perf_counter()
221 return dict(elapsed=(end - begin), graph=g, heads=heads)
222
223 def report(name, g):

Subscribers

People subscribed via source and target branches