/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: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python3
 
2
import random
 
3
import os
 
4
import time
 
5
import sys
 
6
import optparse
 
7
from breezy import (
 
8
    branch,
 
9
    commands,
 
10
    graph,
 
11
    osutils,
 
12
    ui,
 
13
    trace,
 
14
    _known_graph_py,
 
15
    _known_graph_pyx,
 
16
    )
 
17
from breezy.ui import text
 
18
 
 
19
p = optparse.OptionParser()
 
20
p.add_option('--quick', default=False, action='store_true')
 
21
p.add_option('--max-combinations', default=500, type=int)
 
22
p.add_option('--lsprof', default=None, type=str)
 
23
opts, args = p.parse_args(sys.argv[1:])
 
24
 
 
25
trace.enable_default_logging()
 
26
ui.ui_factory = text.TextUIFactory()
 
27
 
 
28
begin = osutils.perf_counter()
 
29
if len(args) >= 1:
 
30
    b = branch.Branch.open(args[0])
 
31
else:
 
32
    b = branch.Branch.open('.')
 
33
with b.lock_read():
 
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
end = osutils.perf_counter()
 
38
 
 
39
print('Found %d nodes, loaded in %.3fs' % (len(parent_map), end - begin))
 
40
 
 
41
def all_heads_comp(g, combinations):
 
42
    h = []
 
43
    with ui.ui_factory.nested_progress_bar() as pb:
 
44
        for idx, combo in enumerate(combinations):
 
45
            if idx & 0x1f == 0:
 
46
                pb.update('proc', idx, len(combinations))
 
47
            h.append(g.heads(combo))
 
48
    return h
 
49
 
 
50
combinations = []
 
51
# parents = parent_map.keys()
 
52
# for p1 in parents:
 
53
#     for p2 in random.sample(parents, 10):
 
54
#         combinations.append((p1, p2))
 
55
# Times for random sampling of 10x1150 of bzrtools
 
56
#   Graph        KnownGraph
 
57
#   96.1s   vs   25.7s  :)
 
58
# Times for 500 'merge parents' from bzr.dev
 
59
#   25.6s   vs   45.0s  :(
 
60
 
 
61
for revision_id, parent_ids in parent_map.iteritems():
 
62
    if parent_ids is not None and len(parent_ids) > 1:
 
63
        combinations.append(parent_ids)
 
64
# The largest portion of the graph that has to be walked for a heads() check
 
65
# combinations = [('john@arbash-meinel.com-20090312021943-tu6tcog48aiujx4s',
 
66
#                  'john@arbash-meinel.com-20090312130552-09xa2xsitf6rilzc')]
 
67
if opts.max_combinations > 0 and len(combinations) > opts.max_combinations:
 
68
    combinations = random.sample(combinations, opts.max_combinations)
 
69
 
 
70
print('      %d combinations' % (len(combinations),))
 
71
 
 
72
def combi_graph(graph_klass, comb):
 
73
    # DEBUG
 
74
    graph._counters[1] = 0
 
75
    graph._counters[2] = 0
 
76
 
 
77
    begin = osutils.perf_counter()
 
78
    g = graph_klass(parent_map)
 
79
    if opts.lsprof is not None:
 
80
        heads = commands.apply_lsprofiled(opts.lsprof, all_heads_comp, g, comb)
 
81
    else:
 
82
        heads = all_heads_comp(g, comb)
 
83
    end = osutils.perf_counter()
 
84
    return dict(elapsed=(end - begin), graph=g, heads=heads)
 
85
 
 
86
def report(name, g):
 
87
    print('%s: %.3fs' % (name, g['elapsed']))
 
88
    counters_used = False
 
89
    for c in graph._counters:
 
90
        if c:
 
91
            counters_used = True
 
92
    if counters_used:
 
93
        print('  %s' % (graph._counters,))
 
94
 
 
95
known_python = combi_graph(_known_graph_py.KnownGraph, combinations)
 
96
report('Known', known_python)
 
97
 
 
98
known_pyrex = combi_graph(_known_graph_pyx.KnownGraph, combinations)
 
99
report('Known (pyx)', known_pyrex)
 
100
 
 
101
def _simple_graph(parent_map):
 
102
    return graph.Graph(graph.DictParentsProvider(parent_map))
 
103
 
 
104
if opts.quick:
 
105
    if known_python['heads'] != known_pyrex['heads']:
 
106
        import pdb; pdb.set_trace()
 
107
    print('ratio: %.1f:1 faster' % (
 
108
        known_python['elapsed'] / known_pyrex['elapsed'],))
 
109
else:
 
110
    orig = combi_graph(_simple_graph, combinations)
 
111
    report('Orig', orig)
 
112
 
 
113
    if orig['heads'] != known_pyrex['heads']:
 
114
        import pdb; pdb.set_trace()
 
115
 
 
116
    print('ratio: %.1f:1 faster' % (
 
117
        orig['elapsed'] / known_pyrex['elapsed'],))