bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
| 
4371.3.38
by John Arbash Meinel
 Add a failing test for handling nodes that are in the same linear chain.  | 
1  | 
#!/usr/bin/env python
 | 
2  | 
import random  | 
|
3  | 
import os  | 
|
4  | 
import time  | 
|
5  | 
import sys  | 
|
6  | 
import optparse  | 
|
7  | 
from bzrlib import (  | 
|
8  | 
branch,  | 
|
9  | 
commands,  | 
|
10  | 
graph,  | 
|
11  | 
ui,  | 
|
12  | 
trace,  | 
|
13  | 
_known_graph_py,  | 
|
14  | 
_known_graph_pyx,  | 
|
15  | 
    )
 | 
|
16  | 
from bzrlib.ui import text  | 
|
17  | 
||
18  | 
p = optparse.OptionParser()  | 
|
| 
4371.4.11
by Vincent Ladeuil
 Cleanup tools/time_graph.py and add a --quick option.  | 
19  | 
p.add_option('--quick', default=False, action='store_true')  | 
| 
4371.3.38
by John Arbash Meinel
 Add a failing test for handling nodes that are in the same linear chain.  | 
20  | 
p.add_option('--max-combinations', default=500, type=int)  | 
21  | 
p.add_option('--lsprof', default=None, type=str)  | 
|
22  | 
opts, args = p.parse_args(sys.argv[1:])  | 
|
| 
4371.4.11
by Vincent Ladeuil
 Cleanup tools/time_graph.py and add a --quick option.  | 
23  | 
|
| 
4371.3.38
by John Arbash Meinel
 Add a failing test for handling nodes that are in the same linear chain.  | 
24  | 
trace.enable_default_logging()  | 
25  | 
ui.ui_factory = text.TextUIFactory()  | 
|
26  | 
||
| 
4371.4.11
by Vincent Ladeuil
 Cleanup tools/time_graph.py and add a --quick option.  | 
27  | 
begin = time.clock()  | 
| 
4371.3.38
by John Arbash Meinel
 Add a failing test for handling nodes that are in the same linear chain.  | 
28  | 
if len(args) >= 1:  | 
29  | 
b = branch.Branch.open(args[0])  | 
|
30  | 
else:  | 
|
31  | 
b = branch.Branch.open('.')  | 
|
32  | 
b.lock_read()  | 
|
33  | 
try:  | 
|
34  | 
g = b.repository.get_graph()  | 
|
35  | 
parent_map = dict(p for p in g.iter_ancestry([b.last_revision()])  | 
|
36  | 
if p[1] is not None)  | 
|
37  | 
finally:  | 
|
38  | 
b.unlock()  | 
|
| 
4371.4.11
by Vincent Ladeuil
 Cleanup tools/time_graph.py and add a --quick option.  | 
39  | 
end = time.clock()  | 
| 
4371.3.38
by John Arbash Meinel
 Add a failing test for handling nodes that are in the same linear chain.  | 
40  | 
|
| 
4371.4.11
by Vincent Ladeuil
 Cleanup tools/time_graph.py and add a --quick option.  | 
41  | 
print 'Found %d nodes, loaded in %.3fs' % (len(parent_map), end - begin)  | 
| 
4371.3.38
by John Arbash Meinel
 Add a failing test for handling nodes that are in the same linear chain.  | 
42  | 
|
43  | 
def all_heads_comp(g, combinations):  | 
|
44  | 
h = []  | 
|
45  | 
pb = ui.ui_factory.nested_progress_bar()  | 
|
46  | 
try:  | 
|
47  | 
for idx, combo in enumerate(combinations):  | 
|
48  | 
if idx & 0x1f == 0:  | 
|
49  | 
pb.update('proc', idx, len(combinations))  | 
|
50  | 
h.append(g.heads(combo))  | 
|
51  | 
finally:  | 
|
52  | 
pb.finished()  | 
|
53  | 
return h  | 
|
| 
4371.4.11
by Vincent Ladeuil
 Cleanup tools/time_graph.py and add a --quick option.  | 
54  | 
|
| 
4371.3.38
by John Arbash Meinel
 Add a failing test for handling nodes that are in the same linear chain.  | 
55  | 
combinations = []  | 
56  | 
# parents = parent_map.keys()
 | 
|
57  | 
# for p1 in parents:
 | 
|
58  | 
#     for p2 in random.sample(parents, 10):
 | 
|
59  | 
#         combinations.append((p1, p2))
 | 
|
60  | 
# Times for random sampling of 10x1150 of bzrtools
 | 
|
61  | 
#   Graph        KnownGraph
 | 
|
62  | 
#   96.1s   vs   25.7s  :)
 | 
|
63  | 
# Times for 500 'merge parents' from bzr.dev
 | 
|
64  | 
#   25.6s   vs   45.0s  :(
 | 
|
65  | 
||
66  | 
for revision_id, parent_ids in parent_map.iteritems():  | 
|
67  | 
if parent_ids is not None and len(parent_ids) > 1:  | 
|
68  | 
combinations.append(parent_ids)  | 
|
| 
4371.4.24
by John Arbash Meinel
 Make a note of the 'worst case' for heads.  | 
69  | 
# The largest portion of the graph that has to be walked for a heads() check
 | 
70  | 
# combinations = [('john@arbash-meinel.com-20090312021943-tu6tcog48aiujx4s',
 | 
|
71  | 
#                  'john@arbash-meinel.com-20090312130552-09xa2xsitf6rilzc')]
 | 
|
| 
4371.3.38
by John Arbash Meinel
 Add a failing test for handling nodes that are in the same linear chain.  | 
72  | 
if opts.max_combinations > 0 and len(combinations) > opts.max_combinations:  | 
73  | 
combinations = random.sample(combinations, opts.max_combinations)  | 
|
74  | 
||
75  | 
print ' %d combinations' % (len(combinations),)  | 
|
| 
4371.4.11
by Vincent Ladeuil
 Cleanup tools/time_graph.py and add a --quick option.  | 
76  | 
|
77  | 
def combi_graph(graph_klass, comb):  | 
|
78  | 
    # DEBUG
 | 
|
79  | 
graph._counters[1] = 0  | 
|
80  | 
graph._counters[2] = 0  | 
|
81  | 
||
82  | 
begin = time.clock()  | 
|
83  | 
g = graph_klass(parent_map)  | 
|
84  | 
if opts.lsprof is not None:  | 
|
85  | 
heads = commands.apply_lsprofiled(opts.lsprof, all_heads_comp, g, comb)  | 
|
86  | 
else:  | 
|
87  | 
heads = all_heads_comp(g, comb)  | 
|
88  | 
end = time.clock()  | 
|
89  | 
return dict(elapsed=(end - begin), graph=g, heads=heads)  | 
|
90  | 
||
91  | 
def report(name, g):  | 
|
92  | 
print '%s: %.3fs' % (name, g['elapsed'])  | 
|
93  | 
counters_used = False  | 
|
94  | 
for c in graph._counters:  | 
|
95  | 
if c:  | 
|
96  | 
counters_used = True  | 
|
97  | 
if counters_used:  | 
|
98  | 
print ' %s' % (graph._counters,)  | 
|
99  | 
||
100  | 
known_python = combi_graph(_known_graph_py.KnownGraph, combinations)  | 
|
101  | 
report('Known', known_python)  | 
|
102  | 
||
103  | 
known_pyrex = combi_graph(_known_graph_pyx.KnownGraph, combinations)  | 
|
104  | 
report('Known (pyx)', known_pyrex)  | 
|
105  | 
||
106  | 
def _simple_graph(parent_map):  | 
|
107  | 
return graph.Graph(graph.DictParentsProvider(parent_map))  | 
|
108  | 
||
109  | 
if opts.quick:  | 
|
110  | 
if known_python['heads'] != known_pyrex['heads']:  | 
|
111  | 
import pdb; pdb.set_trace()  | 
|
| 
4371.4.20
by John Arbash Meinel
 Update time_graph to use X:1 ratios rather than 0.xxx ratios.  | 
112  | 
print 'ratio: %.1f:1 faster' % (  | 
113  | 
known_python['elapsed'] / known_pyrex['elapsed'],)  | 
|
| 
4371.4.11
by Vincent Ladeuil
 Cleanup tools/time_graph.py and add a --quick option.  | 
114  | 
else:  | 
115  | 
orig = combi_graph(_simple_graph, combinations)  | 
|
116  | 
report('Orig', orig)  | 
|
117  | 
||
118  | 
if orig['heads'] != known_pyrex['heads']:  | 
|
119  | 
import pdb; pdb.set_trace()  | 
|
120  | 
||
| 
4371.4.20
by John Arbash Meinel
 Update time_graph to use X:1 ratios rather than 0.xxx ratios.  | 
121  | 
print 'ratio: %.1f:1 faster' % (  | 
122  | 
orig['elapsed'] / known_pyrex['elapsed'],)  |