/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to tools/time_graph.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python3
 
1
#!/usr/bin/env python
2
2
import random
3
3
import os
4
4
import time
5
5
import sys
6
6
import optparse
7
 
from breezy import (
 
7
from bzrlib import (
8
8
    branch,
9
9
    commands,
10
10
    graph,
11
 
    osutils,
12
11
    ui,
13
12
    trace,
14
13
    _known_graph_py,
15
14
    _known_graph_pyx,
16
15
    )
17
 
from breezy.ui import text
 
16
from bzrlib.ui import text
18
17
 
19
18
p = optparse.OptionParser()
20
19
p.add_option('--quick', default=False, action='store_true')
25
24
trace.enable_default_logging()
26
25
ui.ui_factory = text.TextUIFactory()
27
26
 
28
 
begin = osutils.perf_counter()
 
27
begin = time.clock()
29
28
if len(args) >= 1:
30
29
    b = branch.Branch.open(args[0])
31
30
else:
32
31
    b = branch.Branch.open('.')
33
 
with b.lock_read():
 
32
b.lock_read()
 
33
try:
34
34
    g = b.repository.get_graph()
35
35
    parent_map = dict(p for p in g.iter_ancestry([b.last_revision()])
36
 
                      if p[1] is not None)
37
 
end = osutils.perf_counter()
 
36
                         if p[1] is not None)
 
37
finally:
 
38
    b.unlock()
 
39
end = time.clock()
38
40
 
39
 
print('Found %d nodes, loaded in %.3fs' % (len(parent_map), end - begin))
 
41
print 'Found %d nodes, loaded in %.3fs' % (len(parent_map), end - begin)
40
42
 
41
43
def all_heads_comp(g, combinations):
42
44
    h = []
43
 
    with ui.ui_factory.nested_progress_bar() as pb:
 
45
    pb = ui.ui_factory.nested_progress_bar()
 
46
    try:
44
47
        for idx, combo in enumerate(combinations):
45
48
            if idx & 0x1f == 0:
46
49
                pb.update('proc', idx, len(combinations))
47
50
            h.append(g.heads(combo))
 
51
    finally:
 
52
        pb.finished()
48
53
    return h
49
54
 
50
55
combinations = []
67
72
if opts.max_combinations > 0 and len(combinations) > opts.max_combinations:
68
73
    combinations = random.sample(combinations, opts.max_combinations)
69
74
 
70
 
print('      %d combinations' % (len(combinations),))
 
75
print '      %d combinations' % (len(combinations),)
71
76
 
72
77
def combi_graph(graph_klass, comb):
73
78
    # DEBUG
74
79
    graph._counters[1] = 0
75
80
    graph._counters[2] = 0
76
81
 
77
 
    begin = osutils.perf_counter()
 
82
    begin = time.clock()
78
83
    g = graph_klass(parent_map)
79
84
    if opts.lsprof is not None:
80
85
        heads = commands.apply_lsprofiled(opts.lsprof, all_heads_comp, g, comb)
81
86
    else:
82
87
        heads = all_heads_comp(g, comb)
83
 
    end = osutils.perf_counter()
 
88
    end = time.clock()
84
89
    return dict(elapsed=(end - begin), graph=g, heads=heads)
85
90
 
86
91
def report(name, g):
87
 
    print('%s: %.3fs' % (name, g['elapsed']))
 
92
    print '%s: %.3fs' % (name, g['elapsed'])
88
93
    counters_used = False
89
94
    for c in graph._counters:
90
95
        if c:
91
96
            counters_used = True
92
97
    if counters_used:
93
 
        print('  %s' % (graph._counters,))
 
98
        print '  %s' % (graph._counters,)
94
99
 
95
100
known_python = combi_graph(_known_graph_py.KnownGraph, combinations)
96
101
report('Known', known_python)
104
109
if opts.quick:
105
110
    if known_python['heads'] != known_pyrex['heads']:
106
111
        import pdb; pdb.set_trace()
107
 
    print('ratio: %.1f:1 faster' % (
108
 
        known_python['elapsed'] / known_pyrex['elapsed'],))
 
112
    print 'ratio: %.1f:1 faster' % (
 
113
        known_python['elapsed'] / known_pyrex['elapsed'],)
109
114
else:
110
115
    orig = combi_graph(_simple_graph, combinations)
111
116
    report('Orig', orig)
113
118
    if orig['heads'] != known_pyrex['heads']:
114
119
        import pdb; pdb.set_trace()
115
120
 
116
 
    print('ratio: %.1f:1 faster' % (
117
 
        orig['elapsed'] / known_pyrex['elapsed'],))
 
121
    print 'ratio: %.1f:1 faster' % (
 
122
        orig['elapsed'] / known_pyrex['elapsed'],)