Rev 19: Switch to testing just find_differences in http://bzr.arbash-meinel.com/plugins/test_graph

John Arbash Meinel john at arbash-meinel.com
Thu Apr 24 00:21:46 BST 2008


At http://bzr.arbash-meinel.com/plugins/test_graph

------------------------------------------------------------
revno: 19
revision-id: john at arbash-meinel.com-20080423231554-pty1cpydllewccj6
parent: john at arbash-meinel.com-20071218204921-05jg95his26fj97y
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: test_graph
timestamp: Wed 2008-04-23 18:15:54 -0500
message:
  Switch to testing just find_differences
modified:
  __init__.py                    __init__.py-20071210194758-1pwa1q7e3wnjf418-1
  graph_testing.py               graph_testing.py-20071210194758-1pwa1q7e3wnjf418-2
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2007-12-18 17:17:00 +0000
+++ b/__init__.py	2008-04-23 23:15:54 +0000
@@ -30,12 +30,14 @@
 
     takes_options = [option.Option('pause',
                         help='Start pdb after processing is done.'),
+                     option.Option('count', type=int,
+                        help='Only process count nodes')
                     ]
     takes_args = ['location?']
 
-    def run(self, location='.', pause=False):
+    def run(self, location='.', pause=False, count=None):
         from graph_testing import test_all
-        test_all(location, pause=pause)
+        test_all(location, pause=pause, count=count)
 
 commands.register_command(cmd_test_graph)
 

=== modified file 'graph_testing.py'
--- a/graph_testing.py	2007-12-18 20:49:21 +0000
+++ b/graph_testing.py	2008-04-23 23:15:54 +0000
@@ -135,107 +135,114 @@
                 inner_hit, len(ancestries))
         self.ancestries = ancestries
 
-    def time_functions(self, a_branch):
+    def time_functions(self, a_branch, count=None):
         if self.hold_graph:
             graph = a_branch.repository.get_graph()
 
         timer = Timer()
 
+        interesting = self.interesting
+        if count:
+            interesting = interesting[:count]
         pb = ui.ui_factory.nested_progress_bar()
-        for idx, revision_id in enumerate(reversed(self.interesting)):
-            pb.update('processing', idx, len(self.interesting))
-            parent_ids = self.rev_graph[revision_id]
-            a_branch.lock_read()
-            try:
-                if not self.hold_graph:
-                    graph = a_branch.repository.get_graph()
-                timer.start()
-                heads = graph.heads(parent_ids)
-                t_heads = timer.end()
-                if t_heads < 0:
-                    import pdb; pdb.set_trace()
-                    pb.note('negative heads time: %.3fs for %s',
-                            t_heads, parent_ids)
-            finally:
-                a_branch.unlock()
-            self.head_times[revision_id] = t_heads
-            if heads != set(parent_ids):
-                # Check to see that the node really is in the ancestry of the
-                # others
-                non_heads = set(parent_ids) - heads
-                for non_head in non_heads:
-                    for head in heads:
-                        ancestry = self.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()
-                timer.start()
-                for parent_id in parent_ids:
-                    heads = graph.heads((revision_id, parent_id))
-                    assert heads == set([revision_id])
-                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, parent_ids)
-            finally:
-                a_branch.unlock()
-            self.trivial_head_times[revision_id] = t_trivial_heads
-
-            continue
-            a_branch.lock_read()
-            try:
-                if not self.hold_graph:
-                    graph = a_branch.repository.get_graph()
-                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 = timer.end()
-            finally:
-                a_branch.unlock()
-            self.trivial_diff_times[revision_id] = t_trivial_diff
-
-            if len(parent_ids) < 2:
-                continue
-
-            a_branch.lock_read()
-            try:
-                if not self.hold_graph:
-                    graph = a_branch.repository.get_graph()
-                timer.start()
-                left, right = graph.find_difference(parent_ids[0],
-                                                    parent_ids[1])
-                t_diff = timer.end()
-            finally:
-                a_branch.unlock()
-            self.find_difference_times[revision_id] = t_diff
-            left_ancestry = frozenset(self.ancestries[parent_ids[0]])
-            right_ancestry = frozenset(self.ancestries[parent_ids[1]])
-            left_correct = left == (left_ancestry - right_ancestry)
-            right_correct = right == (right_ancestry - left_ancestry)
-            if not left_correct and not right_correct:
-                pb.note('left and right incorrect for: %s', revision_id)
-            elif not left_correct:
-                pb.note('left incorrect for: %s', revision_id)
-            elif not right_correct:
-                pb.note('right incorrect for: %s', revision_id)
-            if not left_correct or not right_correct:
-                self.invalid_diffs.add(revision_id)
+        try:
+            for idx, revision_id in enumerate(reversed(interesting)):
+                pb.update('processing', idx, len(interesting))
+                parent_ids = self.rev_graph[revision_id]
+                # a_branch.lock_read()
+                # try:
+                #     if not self.hold_graph:
+                #         graph = a_branch.repository.get_graph()
+                #     timer.start()
+                #     heads = graph.heads(parent_ids)
+                #     t_heads = timer.end()
+                #     if t_heads < 0:
+                #         import pdb; pdb.set_trace()
+                #         pb.note('negative heads time: %.3fs for %s',
+                #                 t_heads, parent_ids)
+                # finally:
+                #     a_branch.unlock()
+                # self.head_times[revision_id] = t_heads
+                # if heads != set(parent_ids):
+                #     # Check to see that the node really is in the ancestry of the
+                #     # others
+                #     non_heads = set(parent_ids) - heads
+                #     for non_head in non_heads:
+                #         for head in heads:
+                #             ancestry = self.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()
+                #     timer.start()
+                #     for parent_id in parent_ids:
+                #         heads = graph.heads((revision_id, parent_id))
+                #         assert heads == set([revision_id])
+                #     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, parent_ids)
+                # finally:
+                #     a_branch.unlock()
+                # self.trivial_head_times[revision_id] = t_trivial_heads
+
+                # Skip the find_difference check
+                # continue
+                a_branch.lock_read()
+                try:
+                    if not self.hold_graph:
+                        graph = a_branch.repository.get_graph()
+                    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 = timer.end()
+                finally:
+                    a_branch.unlock()
+                self.trivial_diff_times[revision_id] = t_trivial_diff
+
+                if len(parent_ids) < 2:
+                    continue
+
+                a_branch.lock_read()
+                try:
+                    if not self.hold_graph:
+                        graph = a_branch.repository.get_graph()
+                    timer.start()
+                    left, right = graph.find_difference(parent_ids[0],
+                                                        parent_ids[1])
+                    t_diff = timer.end()
+                finally:
+                    a_branch.unlock()
+                self.find_difference_times[revision_id] = t_diff
+                left_ancestry = frozenset(self.ancestries[parent_ids[0]])
+                right_ancestry = frozenset(self.ancestries[parent_ids[1]])
+                left_correct = left == (left_ancestry - right_ancestry)
+                right_correct = right == (right_ancestry - left_ancestry)
+                if not left_correct and not right_correct:
+                    pb.note('left and right incorrect for: %s', revision_id)
+                elif not left_correct:
+                    pb.note('left incorrect for: %s', revision_id)
+                elif not right_correct:
+                    pb.note('right incorrect for: %s', revision_id)
+                if not left_correct or not right_correct:
+                    self.invalid_diffs.add(revision_id)
+        except KeyboardInterrupt:
+            pass # Just break out of the loop
         pb.finished()
 
     def get_statistics(self, times):
@@ -292,7 +299,7 @@
     return rev_graph
 
 
-def test_all(location, pause=False):
+def test_all(location, pause=False, count=None):
     the_branch = branch.Branch.open(location)
     the_branch.lock_read()
     the_branch.lock_read()
@@ -310,16 +317,16 @@
     tester.hold_graph = True
     tester.get_interesting_nodes(last_revision)
     tester.get_ancestry_for_interesting()
-    tester.time_functions(the_branch)
+    tester.time_functions(the_branch, count=count)
     import pprint
-    print 'trivial heads:'
-    pprint.pprint(tester.get_statistics(tester.trivial_head_times))
-    # print 'trivial diff:'
-    # pprint.pprint(tester.get_statistics(tester.trivial_diff_times))
-    print 'heads:'
-    pprint.pprint(tester.get_statistics(tester.head_times))
-    # print 'diffs:'
-    # pprint.pprint(tester.get_statistics(tester.find_difference_times))
+    # print 'trivial heads:'
+    # pprint.pprint(tester.get_statistics(tester.trivial_head_times))
+    print 'trivial diff:'
+    pprint.pprint(tester.get_statistics(tester.trivial_diff_times))
+    # print 'heads:'
+    # pprint.pprint(tester.get_statistics(tester.head_times))
+    print 'diffs:'
+    pprint.pprint(tester.get_statistics(tester.find_difference_times))
     if pause:
         import pdb; pdb.set_trace()
     the_branch.unlock()



More information about the bazaar-commits mailing list