Rev 17: Workaround an overflow in time.clock() at 2147s into a process. in http://bzr.arbash-meinel.com/plugins/test_graph
John Arbash Meinel
john at arbash-meinel.com
Tue Dec 18 20:48:08 GMT 2007
At http://bzr.arbash-meinel.com/plugins/test_graph
------------------------------------------------------------
revno: 17
revision-id:john at arbash-meinel.com-20071218204527-m7pv9htd8lkcay4c
parent: john at arbash-meinel.com-20071218183511-jlolconm0a4gtuh3
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: test_graph
timestamp: Tue 2007-12-18 14:45:27 -0600
message:
Workaround an overflow in time.clock() at 2147s into a process.
modified:
graph_testing.py graph_testing.py-20071210194758-1pwa1q7e3wnjf418-2
-------------- next part --------------
=== modified file 'graph_testing.py'
--- a/graph_testing.py 2007-12-18 18:35:11 +0000
+++ b/graph_testing.py 2007-12-18 20:45:27 +0000
@@ -29,6 +29,30 @@
)
+class Timer(object):
+ """A simple timing class to track a child function."""
+
+ def __init__(self):
+ self._start = None
+ self._end = None
+
+ def start(self):
+ self._start = time.clock()
+
+ def end(self):
+ self._end = time.clock()
+ return self.elapsed()
+
+ def elapsed(self):
+ delta = self._end - self._start
+ if delta < 0:
+ # time.clock() seems to be a 32-bit counter of microseconds
+ # since start. So when it rolls over, we need to adjust the
+ # heads time by 2**32usec
+ delta += 4294.967296 # 2**32/10**6
+ return delta
+
+
class GraphTester(object):
def __init__(self, rev_graph):
@@ -115,6 +139,8 @@
if self.hold_graph:
graph = a_branch.repository.get_graph()
+ timer = Timer()
+
pb = ui.ui_factory.nested_progress_bar()
for idx, revision_id in enumerate(reversed(self.interesting)):
pb.update('processing', idx, len(self.interesting))
@@ -123,10 +149,9 @@
try:
if not self.hold_graph:
graph = a_branch.repository.get_graph()
- t_start = time.clock()
+ timer.start()
heads = graph.heads(parent_ids)
- t_end = time.clock()
- t_heads = t_end - t_start
+ t_heads = timer.end()
if t_heads < 0:
import pdb; pdb.set_trace()
pb.note('negative heads time: %.3fs for %s',
@@ -138,31 +163,38 @@
# Check to see that the node really is in the ancestry of the
# others
non_heads = set(parent_ids) - heads
- head_ancestries = []
+ head_ancestries = {}
for head in heads:
ancestry = set(a_branch.repository.get_ancestry(head,
topo_sorted=False))
- for non_head in non_heads:
- if non_head not in ancestry:
- pb.note('heads() incorrect for: %s'
- '\n%s\nwas not in the ancestry',
- head, non_head)
- self.invalid_heads.add(revision_id)
+ head_ancestries[head] = ancestry
+ for non_head in non_heads:
+ for head in heads:
+ ancestry = head_ancestries[head]
+ if non_head in ancestry:
+ break
+ else:
+ pb.note('heads() incorrect for: %s'
+ '\n%s'
+ '\nwas not found in any ancestry of:'
+ '\n%s',
+ revision_id, non_head, heads)
+ import pdb; pdb.set_trace()
+ self.invalid_heads.add(revision_id)
a_branch.lock_read()
try:
if not self.hold_graph:
graph = a_branch.repository.get_graph()
- t_start = time.clock()
+ timer.start()
for parent_id in parent_ids:
heads = graph.heads((revision_id, parent_id))
assert heads == set([revision_id])
- t_end = time.clock()
- t_trivial_heads = t_end - t_start
+ t_trivial_heads = timer.end()
if t_trivial_heads < 0:
import pdb; pdb.set_trace()
pb.note('negative trivial heads time: %.3fs for %s',
- t_trivial_heads, revision_id)
+ t_trivial_heads, parent_ids)
finally:
a_branch.unlock()
self.trivial_head_times[revision_id] = t_trivial_heads
@@ -172,13 +204,13 @@
try:
if not self.hold_graph:
graph = a_branch.repository.get_graph()
- t_start = time.clock()
+ timer.start()
for parent_id in parent_ids:
left, right = graph.find_difference(revision_id, parent_id)
if right != set():
pb.note('found unmerged nodes for:\n %s\nand %s',
revision_id, parent_id)
- t_trivial_diff = time.clock() - t_start
+ t_trivial_diff = timer.end()
finally:
a_branch.unlock()
self.trivial_diff_times[revision_id] = t_trivial_diff
@@ -190,10 +222,10 @@
try:
if not self.hold_graph:
graph = a_branch.repository.get_graph()
- t_start = time.clock()
+ timer.start()
left, right = graph.find_difference(parent_ids[0],
parent_ids[1])
- t_diff = time.clock() - t_start
+ t_diff = timer.end()
finally:
a_branch.unlock()
self.find_difference_times[revision_id] = t_diff
More information about the bazaar-commits
mailing list