~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to tools/time_graph.py

  • Committer: Vincent Ladeuil
  • Date: 2009-06-18 20:00:24 UTC
  • mto: This revision was merged to the branch mainline in revision 4466.
  • Revision ID: v.ladeuil+lp@free.fr-20090618200024-fdrav7hxlz3soot2
Cleanup tools/time_graph.py and add a --quick option.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
from bzrlib.ui import text
17
17
 
18
18
p = optparse.OptionParser()
 
19
p.add_option('--quick', default=False, action='store_true')
19
20
p.add_option('--max-combinations', default=500, type=int)
20
21
p.add_option('--lsprof', default=None, type=str)
21
22
opts, args = p.parse_args(sys.argv[1:])
 
23
 
22
24
trace.enable_default_logging()
23
25
ui.ui_factory = text.TextUIFactory()
24
26
 
25
 
t1 = time.clock()
 
27
begin = time.clock()
26
28
if len(args) >= 1:
27
29
    b = branch.Branch.open(args[0])
28
30
else:
34
36
                         if p[1] is not None)
35
37
finally:
36
38
    b.unlock()
37
 
t2 = time.clock()
 
39
end = time.clock()
38
40
 
39
 
print 'Found %d nodes, loaded in %.3fs' % (len(parent_map), t2-t1)
 
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 = []
49
51
    finally:
50
52
        pb.finished()
51
53
    return h
 
54
 
52
55
combinations = []
53
56
# parents = parent_map.keys()
54
57
# for p1 in parents:
67
70
    combinations = random.sample(combinations, opts.max_combinations)
68
71
 
69
72
print '      %d combinations' % (len(combinations),)
70
 
t1 = time.clock()
71
 
known_g = _known_graph_py.KnownGraph(parent_map)
72
 
if opts.lsprof is not None:
73
 
    h_known = commands.apply_lsprofiled(opts.lsprof,
74
 
        all_heads_comp, known_g, combinations)
75
 
else:
76
 
    h_known = all_heads_comp(known_g, combinations)
77
 
t2 = time.clock()
78
 
print "Known: %.3fs" % (t2-t1,)
79
 
print "  %s" % (graph._counters,)
80
 
t1 = time.clock()
81
 
known_g = _known_graph_pyx.KnownGraph(parent_map)
82
 
if opts.lsprof is not None:
83
 
    h_known = commands.apply_lsprofiled(opts.lsprof,
84
 
        all_heads_comp, known_g, combinations)
85
 
else:
86
 
    h_known = all_heads_comp(known_g, combinations)
87
 
t2 = time.clock()
88
 
print "Known (pyx): %.3fs" % (t2-t1,)
89
 
print "  %s" % (graph._counters,)
90
 
simple_g = graph.Graph(graph.DictParentsProvider(parent_map))
91
 
graph._counters[1] = 0
92
 
graph._counters[2] = 0
93
 
h_simple = all_heads_comp(simple_g, combinations)
94
 
t3 = time.clock()
95
 
print "Orig: %.3fs" % (t3-t2,)
96
 
print "  %s" % (graph._counters,)
97
 
if h_simple != h_known:
98
 
    import pdb; pdb.set_trace()
99
 
print 'ratio: %.3fs' % ((t2-t1) / (t3-t2))
 
73
 
 
74
def combi_graph(graph_klass, comb):
 
75
    # DEBUG
 
76
    graph._counters[1] = 0
 
77
    graph._counters[2] = 0
 
78
 
 
79
    begin = time.clock()
 
80
    g = graph_klass(parent_map)
 
81
    if opts.lsprof is not None:
 
82
        heads = commands.apply_lsprofiled(opts.lsprof, all_heads_comp, g, comb)
 
83
    else:
 
84
        heads = all_heads_comp(g, comb)
 
85
    end = time.clock()
 
86
    return dict(elapsed=(end - begin), graph=g, heads=heads)
 
87
 
 
88
def report(name, g):
 
89
    print '%s: %.3fs' % (name, g['elapsed'])
 
90
    counters_used = False
 
91
    for c in graph._counters:
 
92
        if c:
 
93
            counters_used = True
 
94
    if counters_used:
 
95
        print '  %s' % (graph._counters,)
 
96
 
 
97
known_python = combi_graph(_known_graph_py.KnownGraph, combinations)
 
98
report('Known', known_python)
 
99
 
 
100
known_pyrex = combi_graph(_known_graph_pyx.KnownGraph, combinations)
 
101
report('Known (pyx)', known_pyrex)
 
102
 
 
103
def _simple_graph(parent_map):
 
104
    return graph.Graph(graph.DictParentsProvider(parent_map))
 
105
 
 
106
if opts.quick:
 
107
    if known_python['heads'] != known_pyrex['heads']:
 
108
        import pdb; pdb.set_trace()
 
109
    print 'ratio: %.3fs' % (known_pyrex['elapsed'] / known_python['elapsed'])
 
110
else:
 
111
    orig = combi_graph(_simple_graph, combinations)
 
112
    report('Orig', orig)
 
113
 
 
114
    if orig['heads'] != known_pyrex['heads']:
 
115
        import pdb; pdb.set_trace()
 
116
 
 
117
    print 'ratio: %.3fs' % (known_pyrex['elapsed'] / orig['elapsed'])