/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: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

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