Show More
@@ -1,684 +1,776 | |||||
1 | # perf.py - performance test routines |
|
1 | # perf.py - performance test routines | |
2 | '''helper extension to measure performance''' |
|
2 | '''helper extension to measure performance''' | |
3 |
|
3 | |||
4 | from mercurial import cmdutil, scmutil, util, commands, obsolete |
|
4 | from mercurial import cmdutil, scmutil, util, commands, obsolete | |
5 | from mercurial import repoview, branchmap, merge, copies, error |
|
5 | from mercurial import repoview, branchmap, merge, copies, error, revlog | |
|
6 | from mercurial import mdiff | |||
6 | import time, os, sys |
|
7 | import time, os, sys | |
7 | import random |
|
8 | import random | |
8 | import functools |
|
9 | import functools | |
9 |
|
10 | |||
10 | formatteropts = commands.formatteropts |
|
11 | formatteropts = commands.formatteropts | |
|
12 | revlogopts = commands.debugrevlogopts | |||
11 |
|
13 | |||
12 | cmdtable = {} |
|
14 | cmdtable = {} | |
13 | command = cmdutil.command(cmdtable) |
|
15 | command = cmdutil.command(cmdtable) | |
14 |
|
16 | |||
15 | def getlen(ui): |
|
17 | def getlen(ui): | |
16 | if ui.configbool("perf", "stub"): |
|
18 | if ui.configbool("perf", "stub"): | |
17 | return lambda x: 1 |
|
19 | return lambda x: 1 | |
18 | return len |
|
20 | return len | |
19 |
|
21 | |||
20 | def gettimer(ui, opts=None): |
|
22 | def gettimer(ui, opts=None): | |
21 | """return a timer function and formatter: (timer, formatter) |
|
23 | """return a timer function and formatter: (timer, formatter) | |
22 |
|
24 | |||
23 | This function exists to gather the creation of formatter in a single |
|
25 | This function exists to gather the creation of formatter in a single | |
24 | place instead of duplicating it in all performance commands.""" |
|
26 | place instead of duplicating it in all performance commands.""" | |
25 |
|
27 | |||
26 | # enforce an idle period before execution to counteract power management |
|
28 | # enforce an idle period before execution to counteract power management | |
27 | # experimental config: perf.presleep |
|
29 | # experimental config: perf.presleep | |
28 | time.sleep(ui.configint("perf", "presleep", 1)) |
|
30 | time.sleep(ui.configint("perf", "presleep", 1)) | |
29 |
|
31 | |||
30 | if opts is None: |
|
32 | if opts is None: | |
31 | opts = {} |
|
33 | opts = {} | |
32 | # redirect all to stderr |
|
34 | # redirect all to stderr | |
33 | ui = ui.copy() |
|
35 | ui = ui.copy() | |
34 | ui.fout = ui.ferr |
|
36 | ui.fout = ui.ferr | |
35 | # get a formatter |
|
37 | # get a formatter | |
36 | fm = ui.formatter('perf', opts) |
|
38 | fm = ui.formatter('perf', opts) | |
37 | # stub function, runs code only once instead of in a loop |
|
39 | # stub function, runs code only once instead of in a loop | |
38 | # experimental config: perf.stub |
|
40 | # experimental config: perf.stub | |
39 | if ui.configbool("perf", "stub"): |
|
41 | if ui.configbool("perf", "stub"): | |
40 | return functools.partial(stub_timer, fm), fm |
|
42 | return functools.partial(stub_timer, fm), fm | |
41 | return functools.partial(_timer, fm), fm |
|
43 | return functools.partial(_timer, fm), fm | |
42 |
|
44 | |||
43 | def stub_timer(fm, func, title=None): |
|
45 | def stub_timer(fm, func, title=None): | |
44 | func() |
|
46 | func() | |
45 |
|
47 | |||
46 | def _timer(fm, func, title=None): |
|
48 | def _timer(fm, func, title=None): | |
47 | results = [] |
|
49 | results = [] | |
48 | begin = time.time() |
|
50 | begin = time.time() | |
49 | count = 0 |
|
51 | count = 0 | |
50 | while True: |
|
52 | while True: | |
51 | ostart = os.times() |
|
53 | ostart = os.times() | |
52 | cstart = time.time() |
|
54 | cstart = time.time() | |
53 | r = func() |
|
55 | r = func() | |
54 | cstop = time.time() |
|
56 | cstop = time.time() | |
55 | ostop = os.times() |
|
57 | ostop = os.times() | |
56 | count += 1 |
|
58 | count += 1 | |
57 | a, b = ostart, ostop |
|
59 | a, b = ostart, ostop | |
58 | results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) |
|
60 | results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) | |
59 | if cstop - begin > 3 and count >= 100: |
|
61 | if cstop - begin > 3 and count >= 100: | |
60 | break |
|
62 | break | |
61 | if cstop - begin > 10 and count >= 3: |
|
63 | if cstop - begin > 10 and count >= 3: | |
62 | break |
|
64 | break | |
63 |
|
65 | |||
64 | fm.startitem() |
|
66 | fm.startitem() | |
65 |
|
67 | |||
66 | if title: |
|
68 | if title: | |
67 | fm.write('title', '! %s\n', title) |
|
69 | fm.write('title', '! %s\n', title) | |
68 | if r: |
|
70 | if r: | |
69 | fm.write('result', '! result: %s\n', r) |
|
71 | fm.write('result', '! result: %s\n', r) | |
70 | m = min(results) |
|
72 | m = min(results) | |
71 | fm.plain('!') |
|
73 | fm.plain('!') | |
72 | fm.write('wall', ' wall %f', m[0]) |
|
74 | fm.write('wall', ' wall %f', m[0]) | |
73 | fm.write('comb', ' comb %f', m[1] + m[2]) |
|
75 | fm.write('comb', ' comb %f', m[1] + m[2]) | |
74 | fm.write('user', ' user %f', m[1]) |
|
76 | fm.write('user', ' user %f', m[1]) | |
75 | fm.write('sys', ' sys %f', m[2]) |
|
77 | fm.write('sys', ' sys %f', m[2]) | |
76 | fm.write('count', ' (best of %d)', count) |
|
78 | fm.write('count', ' (best of %d)', count) | |
77 | fm.plain('\n') |
|
79 | fm.plain('\n') | |
78 |
|
80 | |||
79 | @command('perfwalk', formatteropts) |
|
81 | @command('perfwalk', formatteropts) | |
80 | def perfwalk(ui, repo, *pats, **opts): |
|
82 | def perfwalk(ui, repo, *pats, **opts): | |
81 | timer, fm = gettimer(ui, opts) |
|
83 | timer, fm = gettimer(ui, opts) | |
82 | try: |
|
84 | try: | |
83 | m = scmutil.match(repo[None], pats, {}) |
|
85 | m = scmutil.match(repo[None], pats, {}) | |
84 | timer(lambda: len(list(repo.dirstate.walk(m, [], True, False)))) |
|
86 | timer(lambda: len(list(repo.dirstate.walk(m, [], True, False)))) | |
85 | except Exception: |
|
87 | except Exception: | |
86 | try: |
|
88 | try: | |
87 | m = scmutil.match(repo[None], pats, {}) |
|
89 | m = scmutil.match(repo[None], pats, {}) | |
88 | timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)])) |
|
90 | timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)])) | |
89 | except Exception: |
|
91 | except Exception: | |
90 | timer(lambda: len(list(cmdutil.walk(repo, pats, {})))) |
|
92 | timer(lambda: len(list(cmdutil.walk(repo, pats, {})))) | |
91 | fm.end() |
|
93 | fm.end() | |
92 |
|
94 | |||
93 | @command('perfannotate', formatteropts) |
|
95 | @command('perfannotate', formatteropts) | |
94 | def perfannotate(ui, repo, f, **opts): |
|
96 | def perfannotate(ui, repo, f, **opts): | |
95 | timer, fm = gettimer(ui, opts) |
|
97 | timer, fm = gettimer(ui, opts) | |
96 | fc = repo['.'][f] |
|
98 | fc = repo['.'][f] | |
97 | timer(lambda: len(fc.annotate(True))) |
|
99 | timer(lambda: len(fc.annotate(True))) | |
98 | fm.end() |
|
100 | fm.end() | |
99 |
|
101 | |||
100 | @command('perfstatus', |
|
102 | @command('perfstatus', | |
101 | [('u', 'unknown', False, |
|
103 | [('u', 'unknown', False, | |
102 | 'ask status to look for unknown files')] + formatteropts) |
|
104 | 'ask status to look for unknown files')] + formatteropts) | |
103 | def perfstatus(ui, repo, **opts): |
|
105 | def perfstatus(ui, repo, **opts): | |
104 | #m = match.always(repo.root, repo.getcwd()) |
|
106 | #m = match.always(repo.root, repo.getcwd()) | |
105 | #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False, |
|
107 | #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False, | |
106 | # False)))) |
|
108 | # False)))) | |
107 | timer, fm = gettimer(ui, opts) |
|
109 | timer, fm = gettimer(ui, opts) | |
108 | timer(lambda: sum(map(len, repo.status(unknown=opts['unknown'])))) |
|
110 | timer(lambda: sum(map(len, repo.status(unknown=opts['unknown'])))) | |
109 | fm.end() |
|
111 | fm.end() | |
110 |
|
112 | |||
111 | @command('perfaddremove', formatteropts) |
|
113 | @command('perfaddremove', formatteropts) | |
112 | def perfaddremove(ui, repo, **opts): |
|
114 | def perfaddremove(ui, repo, **opts): | |
113 | timer, fm = gettimer(ui, opts) |
|
115 | timer, fm = gettimer(ui, opts) | |
114 | try: |
|
116 | try: | |
115 | oldquiet = repo.ui.quiet |
|
117 | oldquiet = repo.ui.quiet | |
116 | repo.ui.quiet = True |
|
118 | repo.ui.quiet = True | |
117 | matcher = scmutil.match(repo[None]) |
|
119 | matcher = scmutil.match(repo[None]) | |
118 | timer(lambda: scmutil.addremove(repo, matcher, "", dry_run=True)) |
|
120 | timer(lambda: scmutil.addremove(repo, matcher, "", dry_run=True)) | |
119 | finally: |
|
121 | finally: | |
120 | repo.ui.quiet = oldquiet |
|
122 | repo.ui.quiet = oldquiet | |
121 | fm.end() |
|
123 | fm.end() | |
122 |
|
124 | |||
123 | def clearcaches(cl): |
|
125 | def clearcaches(cl): | |
124 | # behave somewhat consistently across internal API changes |
|
126 | # behave somewhat consistently across internal API changes | |
125 | if util.safehasattr(cl, 'clearcaches'): |
|
127 | if util.safehasattr(cl, 'clearcaches'): | |
126 | cl.clearcaches() |
|
128 | cl.clearcaches() | |
127 | elif util.safehasattr(cl, '_nodecache'): |
|
129 | elif util.safehasattr(cl, '_nodecache'): | |
128 | from mercurial.node import nullid, nullrev |
|
130 | from mercurial.node import nullid, nullrev | |
129 | cl._nodecache = {nullid: nullrev} |
|
131 | cl._nodecache = {nullid: nullrev} | |
130 | cl._nodepos = None |
|
132 | cl._nodepos = None | |
131 |
|
133 | |||
132 | @command('perfheads', formatteropts) |
|
134 | @command('perfheads', formatteropts) | |
133 | def perfheads(ui, repo, **opts): |
|
135 | def perfheads(ui, repo, **opts): | |
134 | timer, fm = gettimer(ui, opts) |
|
136 | timer, fm = gettimer(ui, opts) | |
135 | cl = repo.changelog |
|
137 | cl = repo.changelog | |
136 | def d(): |
|
138 | def d(): | |
137 | len(cl.headrevs()) |
|
139 | len(cl.headrevs()) | |
138 | clearcaches(cl) |
|
140 | clearcaches(cl) | |
139 | timer(d) |
|
141 | timer(d) | |
140 | fm.end() |
|
142 | fm.end() | |
141 |
|
143 | |||
142 | @command('perftags', formatteropts) |
|
144 | @command('perftags', formatteropts) | |
143 | def perftags(ui, repo, **opts): |
|
145 | def perftags(ui, repo, **opts): | |
144 | import mercurial.changelog |
|
146 | import mercurial.changelog | |
145 | import mercurial.manifest |
|
147 | import mercurial.manifest | |
146 | timer, fm = gettimer(ui, opts) |
|
148 | timer, fm = gettimer(ui, opts) | |
147 | def t(): |
|
149 | def t(): | |
148 | repo.changelog = mercurial.changelog.changelog(repo.svfs) |
|
150 | repo.changelog = mercurial.changelog.changelog(repo.svfs) | |
149 | repo.manifest = mercurial.manifest.manifest(repo.svfs) |
|
151 | repo.manifest = mercurial.manifest.manifest(repo.svfs) | |
150 | repo._tags = None |
|
152 | repo._tags = None | |
151 | return len(repo.tags()) |
|
153 | return len(repo.tags()) | |
152 | timer(t) |
|
154 | timer(t) | |
153 | fm.end() |
|
155 | fm.end() | |
154 |
|
156 | |||
155 | @command('perfancestors', formatteropts) |
|
157 | @command('perfancestors', formatteropts) | |
156 | def perfancestors(ui, repo, **opts): |
|
158 | def perfancestors(ui, repo, **opts): | |
157 | timer, fm = gettimer(ui, opts) |
|
159 | timer, fm = gettimer(ui, opts) | |
158 | heads = repo.changelog.headrevs() |
|
160 | heads = repo.changelog.headrevs() | |
159 | def d(): |
|
161 | def d(): | |
160 | for a in repo.changelog.ancestors(heads): |
|
162 | for a in repo.changelog.ancestors(heads): | |
161 | pass |
|
163 | pass | |
162 | timer(d) |
|
164 | timer(d) | |
163 | fm.end() |
|
165 | fm.end() | |
164 |
|
166 | |||
165 | @command('perfancestorset', formatteropts) |
|
167 | @command('perfancestorset', formatteropts) | |
166 | def perfancestorset(ui, repo, revset, **opts): |
|
168 | def perfancestorset(ui, repo, revset, **opts): | |
167 | timer, fm = gettimer(ui, opts) |
|
169 | timer, fm = gettimer(ui, opts) | |
168 | revs = repo.revs(revset) |
|
170 | revs = repo.revs(revset) | |
169 | heads = repo.changelog.headrevs() |
|
171 | heads = repo.changelog.headrevs() | |
170 | def d(): |
|
172 | def d(): | |
171 | s = repo.changelog.ancestors(heads) |
|
173 | s = repo.changelog.ancestors(heads) | |
172 | for rev in revs: |
|
174 | for rev in revs: | |
173 | rev in s |
|
175 | rev in s | |
174 | timer(d) |
|
176 | timer(d) | |
175 | fm.end() |
|
177 | fm.end() | |
176 |
|
178 | |||
177 | @command('perfdirs', formatteropts) |
|
179 | @command('perfdirs', formatteropts) | |
178 | def perfdirs(ui, repo, **opts): |
|
180 | def perfdirs(ui, repo, **opts): | |
179 | timer, fm = gettimer(ui, opts) |
|
181 | timer, fm = gettimer(ui, opts) | |
180 | dirstate = repo.dirstate |
|
182 | dirstate = repo.dirstate | |
181 | 'a' in dirstate |
|
183 | 'a' in dirstate | |
182 | def d(): |
|
184 | def d(): | |
183 | dirstate.dirs() |
|
185 | dirstate.dirs() | |
184 | del dirstate._dirs |
|
186 | del dirstate._dirs | |
185 | timer(d) |
|
187 | timer(d) | |
186 | fm.end() |
|
188 | fm.end() | |
187 |
|
189 | |||
188 | @command('perfdirstate', formatteropts) |
|
190 | @command('perfdirstate', formatteropts) | |
189 | def perfdirstate(ui, repo, **opts): |
|
191 | def perfdirstate(ui, repo, **opts): | |
190 | timer, fm = gettimer(ui, opts) |
|
192 | timer, fm = gettimer(ui, opts) | |
191 | "a" in repo.dirstate |
|
193 | "a" in repo.dirstate | |
192 | def d(): |
|
194 | def d(): | |
193 | repo.dirstate.invalidate() |
|
195 | repo.dirstate.invalidate() | |
194 | "a" in repo.dirstate |
|
196 | "a" in repo.dirstate | |
195 | timer(d) |
|
197 | timer(d) | |
196 | fm.end() |
|
198 | fm.end() | |
197 |
|
199 | |||
198 | @command('perfdirstatedirs', formatteropts) |
|
200 | @command('perfdirstatedirs', formatteropts) | |
199 | def perfdirstatedirs(ui, repo, **opts): |
|
201 | def perfdirstatedirs(ui, repo, **opts): | |
200 | timer, fm = gettimer(ui, opts) |
|
202 | timer, fm = gettimer(ui, opts) | |
201 | "a" in repo.dirstate |
|
203 | "a" in repo.dirstate | |
202 | def d(): |
|
204 | def d(): | |
203 | "a" in repo.dirstate._dirs |
|
205 | "a" in repo.dirstate._dirs | |
204 | del repo.dirstate._dirs |
|
206 | del repo.dirstate._dirs | |
205 | timer(d) |
|
207 | timer(d) | |
206 | fm.end() |
|
208 | fm.end() | |
207 |
|
209 | |||
208 | @command('perfdirstatefoldmap', formatteropts) |
|
210 | @command('perfdirstatefoldmap', formatteropts) | |
209 | def perfdirstatefoldmap(ui, repo, **opts): |
|
211 | def perfdirstatefoldmap(ui, repo, **opts): | |
210 | timer, fm = gettimer(ui, opts) |
|
212 | timer, fm = gettimer(ui, opts) | |
211 | dirstate = repo.dirstate |
|
213 | dirstate = repo.dirstate | |
212 | 'a' in dirstate |
|
214 | 'a' in dirstate | |
213 | def d(): |
|
215 | def d(): | |
214 | dirstate._filefoldmap.get('a') |
|
216 | dirstate._filefoldmap.get('a') | |
215 | del dirstate._filefoldmap |
|
217 | del dirstate._filefoldmap | |
216 | timer(d) |
|
218 | timer(d) | |
217 | fm.end() |
|
219 | fm.end() | |
218 |
|
220 | |||
219 | @command('perfdirfoldmap', formatteropts) |
|
221 | @command('perfdirfoldmap', formatteropts) | |
220 | def perfdirfoldmap(ui, repo, **opts): |
|
222 | def perfdirfoldmap(ui, repo, **opts): | |
221 | timer, fm = gettimer(ui, opts) |
|
223 | timer, fm = gettimer(ui, opts) | |
222 | dirstate = repo.dirstate |
|
224 | dirstate = repo.dirstate | |
223 | 'a' in dirstate |
|
225 | 'a' in dirstate | |
224 | def d(): |
|
226 | def d(): | |
225 | dirstate._dirfoldmap.get('a') |
|
227 | dirstate._dirfoldmap.get('a') | |
226 | del dirstate._dirfoldmap |
|
228 | del dirstate._dirfoldmap | |
227 | del dirstate._dirs |
|
229 | del dirstate._dirs | |
228 | timer(d) |
|
230 | timer(d) | |
229 | fm.end() |
|
231 | fm.end() | |
230 |
|
232 | |||
231 | @command('perfdirstatewrite', formatteropts) |
|
233 | @command('perfdirstatewrite', formatteropts) | |
232 | def perfdirstatewrite(ui, repo, **opts): |
|
234 | def perfdirstatewrite(ui, repo, **opts): | |
233 | timer, fm = gettimer(ui, opts) |
|
235 | timer, fm = gettimer(ui, opts) | |
234 | ds = repo.dirstate |
|
236 | ds = repo.dirstate | |
235 | "a" in ds |
|
237 | "a" in ds | |
236 | def d(): |
|
238 | def d(): | |
237 | ds._dirty = True |
|
239 | ds._dirty = True | |
238 | ds.write(repo.currenttransaction()) |
|
240 | ds.write(repo.currenttransaction()) | |
239 | timer(d) |
|
241 | timer(d) | |
240 | fm.end() |
|
242 | fm.end() | |
241 |
|
243 | |||
242 | @command('perfmergecalculate', |
|
244 | @command('perfmergecalculate', | |
243 | [('r', 'rev', '.', 'rev to merge against')] + formatteropts) |
|
245 | [('r', 'rev', '.', 'rev to merge against')] + formatteropts) | |
244 | def perfmergecalculate(ui, repo, rev, **opts): |
|
246 | def perfmergecalculate(ui, repo, rev, **opts): | |
245 | timer, fm = gettimer(ui, opts) |
|
247 | timer, fm = gettimer(ui, opts) | |
246 | wctx = repo[None] |
|
248 | wctx = repo[None] | |
247 | rctx = scmutil.revsingle(repo, rev, rev) |
|
249 | rctx = scmutil.revsingle(repo, rev, rev) | |
248 | ancestor = wctx.ancestor(rctx) |
|
250 | ancestor = wctx.ancestor(rctx) | |
249 | # we don't want working dir files to be stat'd in the benchmark, so prime |
|
251 | # we don't want working dir files to be stat'd in the benchmark, so prime | |
250 | # that cache |
|
252 | # that cache | |
251 | wctx.dirty() |
|
253 | wctx.dirty() | |
252 | def d(): |
|
254 | def d(): | |
253 | # acceptremote is True because we don't want prompts in the middle of |
|
255 | # acceptremote is True because we don't want prompts in the middle of | |
254 | # our benchmark |
|
256 | # our benchmark | |
255 | merge.calculateupdates(repo, wctx, rctx, [ancestor], False, False, |
|
257 | merge.calculateupdates(repo, wctx, rctx, [ancestor], False, False, | |
256 | acceptremote=True, followcopies=True) |
|
258 | acceptremote=True, followcopies=True) | |
257 | timer(d) |
|
259 | timer(d) | |
258 | fm.end() |
|
260 | fm.end() | |
259 |
|
261 | |||
260 | @command('perfpathcopies', [], "REV REV") |
|
262 | @command('perfpathcopies', [], "REV REV") | |
261 | def perfpathcopies(ui, repo, rev1, rev2, **opts): |
|
263 | def perfpathcopies(ui, repo, rev1, rev2, **opts): | |
262 | timer, fm = gettimer(ui, opts) |
|
264 | timer, fm = gettimer(ui, opts) | |
263 | ctx1 = scmutil.revsingle(repo, rev1, rev1) |
|
265 | ctx1 = scmutil.revsingle(repo, rev1, rev1) | |
264 | ctx2 = scmutil.revsingle(repo, rev2, rev2) |
|
266 | ctx2 = scmutil.revsingle(repo, rev2, rev2) | |
265 | def d(): |
|
267 | def d(): | |
266 | copies.pathcopies(ctx1, ctx2) |
|
268 | copies.pathcopies(ctx1, ctx2) | |
267 | timer(d) |
|
269 | timer(d) | |
268 | fm.end() |
|
270 | fm.end() | |
269 |
|
271 | |||
270 | @command('perfmanifest', [], 'REV') |
|
272 | @command('perfmanifest', [], 'REV') | |
271 | def perfmanifest(ui, repo, rev, **opts): |
|
273 | def perfmanifest(ui, repo, rev, **opts): | |
272 | timer, fm = gettimer(ui, opts) |
|
274 | timer, fm = gettimer(ui, opts) | |
273 | ctx = scmutil.revsingle(repo, rev, rev) |
|
275 | ctx = scmutil.revsingle(repo, rev, rev) | |
274 | t = ctx.manifestnode() |
|
276 | t = ctx.manifestnode() | |
275 | def d(): |
|
277 | def d(): | |
276 | repo.manifest.clearcaches() |
|
278 | repo.manifest.clearcaches() | |
277 | repo.manifest.read(t) |
|
279 | repo.manifest.read(t) | |
278 | timer(d) |
|
280 | timer(d) | |
279 | fm.end() |
|
281 | fm.end() | |
280 |
|
282 | |||
281 | @command('perfchangeset', formatteropts) |
|
283 | @command('perfchangeset', formatteropts) | |
282 | def perfchangeset(ui, repo, rev, **opts): |
|
284 | def perfchangeset(ui, repo, rev, **opts): | |
283 | timer, fm = gettimer(ui, opts) |
|
285 | timer, fm = gettimer(ui, opts) | |
284 | n = repo[rev].node() |
|
286 | n = repo[rev].node() | |
285 | def d(): |
|
287 | def d(): | |
286 | repo.changelog.read(n) |
|
288 | repo.changelog.read(n) | |
287 | #repo.changelog._cache = None |
|
289 | #repo.changelog._cache = None | |
288 | timer(d) |
|
290 | timer(d) | |
289 | fm.end() |
|
291 | fm.end() | |
290 |
|
292 | |||
291 | @command('perfindex', formatteropts) |
|
293 | @command('perfindex', formatteropts) | |
292 | def perfindex(ui, repo, **opts): |
|
294 | def perfindex(ui, repo, **opts): | |
293 | import mercurial.revlog |
|
295 | import mercurial.revlog | |
294 | timer, fm = gettimer(ui, opts) |
|
296 | timer, fm = gettimer(ui, opts) | |
295 | mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg |
|
297 | mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg | |
296 | n = repo["tip"].node() |
|
298 | n = repo["tip"].node() | |
297 | def d(): |
|
299 | def d(): | |
298 | cl = mercurial.revlog.revlog(repo.svfs, "00changelog.i") |
|
300 | cl = mercurial.revlog.revlog(repo.svfs, "00changelog.i") | |
299 | cl.rev(n) |
|
301 | cl.rev(n) | |
300 | timer(d) |
|
302 | timer(d) | |
301 | fm.end() |
|
303 | fm.end() | |
302 |
|
304 | |||
303 | @command('perfstartup', formatteropts) |
|
305 | @command('perfstartup', formatteropts) | |
304 | def perfstartup(ui, repo, **opts): |
|
306 | def perfstartup(ui, repo, **opts): | |
305 | timer, fm = gettimer(ui, opts) |
|
307 | timer, fm = gettimer(ui, opts) | |
306 | cmd = sys.argv[0] |
|
308 | cmd = sys.argv[0] | |
307 | def d(): |
|
309 | def d(): | |
308 | if os.name != 'nt': |
|
310 | if os.name != 'nt': | |
309 | os.system("HGRCPATH= %s version -q > /dev/null" % cmd) |
|
311 | os.system("HGRCPATH= %s version -q > /dev/null" % cmd) | |
310 | else: |
|
312 | else: | |
311 | os.environ['HGRCPATH'] = '' |
|
313 | os.environ['HGRCPATH'] = '' | |
312 | os.system("%s version -q > NUL" % cmd) |
|
314 | os.system("%s version -q > NUL" % cmd) | |
313 | timer(d) |
|
315 | timer(d) | |
314 | fm.end() |
|
316 | fm.end() | |
315 |
|
317 | |||
316 | @command('perfparents', formatteropts) |
|
318 | @command('perfparents', formatteropts) | |
317 | def perfparents(ui, repo, **opts): |
|
319 | def perfparents(ui, repo, **opts): | |
318 | timer, fm = gettimer(ui, opts) |
|
320 | timer, fm = gettimer(ui, opts) | |
319 | # control the number of commits perfparents iterates over |
|
321 | # control the number of commits perfparents iterates over | |
320 | # experimental config: perf.parentscount |
|
322 | # experimental config: perf.parentscount | |
321 | count = ui.configint("perf", "parentscount", 1000) |
|
323 | count = ui.configint("perf", "parentscount", 1000) | |
322 | if len(repo.changelog) < count: |
|
324 | if len(repo.changelog) < count: | |
323 | raise error.Abort("repo needs %d commits for this test" % count) |
|
325 | raise error.Abort("repo needs %d commits for this test" % count) | |
324 | repo = repo.unfiltered() |
|
326 | repo = repo.unfiltered() | |
325 | nl = [repo.changelog.node(i) for i in xrange(count)] |
|
327 | nl = [repo.changelog.node(i) for i in xrange(count)] | |
326 | def d(): |
|
328 | def d(): | |
327 | for n in nl: |
|
329 | for n in nl: | |
328 | repo.changelog.parents(n) |
|
330 | repo.changelog.parents(n) | |
329 | timer(d) |
|
331 | timer(d) | |
330 | fm.end() |
|
332 | fm.end() | |
331 |
|
333 | |||
332 | @command('perfctxfiles', formatteropts) |
|
334 | @command('perfctxfiles', formatteropts) | |
333 | def perfctxfiles(ui, repo, x, **opts): |
|
335 | def perfctxfiles(ui, repo, x, **opts): | |
334 | x = int(x) |
|
336 | x = int(x) | |
335 | timer, fm = gettimer(ui, opts) |
|
337 | timer, fm = gettimer(ui, opts) | |
336 | def d(): |
|
338 | def d(): | |
337 | len(repo[x].files()) |
|
339 | len(repo[x].files()) | |
338 | timer(d) |
|
340 | timer(d) | |
339 | fm.end() |
|
341 | fm.end() | |
340 |
|
342 | |||
341 | @command('perfrawfiles', formatteropts) |
|
343 | @command('perfrawfiles', formatteropts) | |
342 | def perfrawfiles(ui, repo, x, **opts): |
|
344 | def perfrawfiles(ui, repo, x, **opts): | |
343 | x = int(x) |
|
345 | x = int(x) | |
344 | timer, fm = gettimer(ui, opts) |
|
346 | timer, fm = gettimer(ui, opts) | |
345 | cl = repo.changelog |
|
347 | cl = repo.changelog | |
346 | def d(): |
|
348 | def d(): | |
347 | len(cl.read(x)[3]) |
|
349 | len(cl.read(x)[3]) | |
348 | timer(d) |
|
350 | timer(d) | |
349 | fm.end() |
|
351 | fm.end() | |
350 |
|
352 | |||
351 | @command('perflookup', formatteropts) |
|
353 | @command('perflookup', formatteropts) | |
352 | def perflookup(ui, repo, rev, **opts): |
|
354 | def perflookup(ui, repo, rev, **opts): | |
353 | timer, fm = gettimer(ui, opts) |
|
355 | timer, fm = gettimer(ui, opts) | |
354 | timer(lambda: len(repo.lookup(rev))) |
|
356 | timer(lambda: len(repo.lookup(rev))) | |
355 | fm.end() |
|
357 | fm.end() | |
356 |
|
358 | |||
357 | @command('perfrevrange', formatteropts) |
|
359 | @command('perfrevrange', formatteropts) | |
358 | def perfrevrange(ui, repo, *specs, **opts): |
|
360 | def perfrevrange(ui, repo, *specs, **opts): | |
359 | timer, fm = gettimer(ui, opts) |
|
361 | timer, fm = gettimer(ui, opts) | |
360 | revrange = scmutil.revrange |
|
362 | revrange = scmutil.revrange | |
361 | timer(lambda: len(revrange(repo, specs))) |
|
363 | timer(lambda: len(revrange(repo, specs))) | |
362 | fm.end() |
|
364 | fm.end() | |
363 |
|
365 | |||
364 | @command('perfnodelookup', formatteropts) |
|
366 | @command('perfnodelookup', formatteropts) | |
365 | def perfnodelookup(ui, repo, rev, **opts): |
|
367 | def perfnodelookup(ui, repo, rev, **opts): | |
366 | timer, fm = gettimer(ui, opts) |
|
368 | timer, fm = gettimer(ui, opts) | |
367 | import mercurial.revlog |
|
369 | import mercurial.revlog | |
368 | mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg |
|
370 | mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg | |
369 | n = repo[rev].node() |
|
371 | n = repo[rev].node() | |
370 | cl = mercurial.revlog.revlog(repo.svfs, "00changelog.i") |
|
372 | cl = mercurial.revlog.revlog(repo.svfs, "00changelog.i") | |
371 | def d(): |
|
373 | def d(): | |
372 | cl.rev(n) |
|
374 | cl.rev(n) | |
373 | clearcaches(cl) |
|
375 | clearcaches(cl) | |
374 | timer(d) |
|
376 | timer(d) | |
375 | fm.end() |
|
377 | fm.end() | |
376 |
|
378 | |||
377 | @command('perflog', |
|
379 | @command('perflog', | |
378 | [('', 'rename', False, 'ask log to follow renames')] + formatteropts) |
|
380 | [('', 'rename', False, 'ask log to follow renames')] + formatteropts) | |
379 | def perflog(ui, repo, rev=None, **opts): |
|
381 | def perflog(ui, repo, rev=None, **opts): | |
380 | if rev is None: |
|
382 | if rev is None: | |
381 | rev=[] |
|
383 | rev=[] | |
382 | timer, fm = gettimer(ui, opts) |
|
384 | timer, fm = gettimer(ui, opts) | |
383 | ui.pushbuffer() |
|
385 | ui.pushbuffer() | |
384 | timer(lambda: commands.log(ui, repo, rev=rev, date='', user='', |
|
386 | timer(lambda: commands.log(ui, repo, rev=rev, date='', user='', | |
385 | copies=opts.get('rename'))) |
|
387 | copies=opts.get('rename'))) | |
386 | ui.popbuffer() |
|
388 | ui.popbuffer() | |
387 | fm.end() |
|
389 | fm.end() | |
388 |
|
390 | |||
389 | @command('perfmoonwalk', formatteropts) |
|
391 | @command('perfmoonwalk', formatteropts) | |
390 | def perfmoonwalk(ui, repo, **opts): |
|
392 | def perfmoonwalk(ui, repo, **opts): | |
391 | """benchmark walking the changelog backwards |
|
393 | """benchmark walking the changelog backwards | |
392 |
|
394 | |||
393 | This also loads the changelog data for each revision in the changelog. |
|
395 | This also loads the changelog data for each revision in the changelog. | |
394 | """ |
|
396 | """ | |
395 | timer, fm = gettimer(ui, opts) |
|
397 | timer, fm = gettimer(ui, opts) | |
396 | def moonwalk(): |
|
398 | def moonwalk(): | |
397 | for i in xrange(len(repo), -1, -1): |
|
399 | for i in xrange(len(repo), -1, -1): | |
398 | ctx = repo[i] |
|
400 | ctx = repo[i] | |
399 | ctx.branch() # read changelog data (in addition to the index) |
|
401 | ctx.branch() # read changelog data (in addition to the index) | |
400 | timer(moonwalk) |
|
402 | timer(moonwalk) | |
401 | fm.end() |
|
403 | fm.end() | |
402 |
|
404 | |||
403 | @command('perftemplating', formatteropts) |
|
405 | @command('perftemplating', formatteropts) | |
404 | def perftemplating(ui, repo, rev=None, **opts): |
|
406 | def perftemplating(ui, repo, rev=None, **opts): | |
405 | if rev is None: |
|
407 | if rev is None: | |
406 | rev=[] |
|
408 | rev=[] | |
407 | timer, fm = gettimer(ui, opts) |
|
409 | timer, fm = gettimer(ui, opts) | |
408 | ui.pushbuffer() |
|
410 | ui.pushbuffer() | |
409 | timer(lambda: commands.log(ui, repo, rev=rev, date='', user='', |
|
411 | timer(lambda: commands.log(ui, repo, rev=rev, date='', user='', | |
410 | template='{date|shortdate} [{rev}:{node|short}]' |
|
412 | template='{date|shortdate} [{rev}:{node|short}]' | |
411 | ' {author|person}: {desc|firstline}\n')) |
|
413 | ' {author|person}: {desc|firstline}\n')) | |
412 | ui.popbuffer() |
|
414 | ui.popbuffer() | |
413 | fm.end() |
|
415 | fm.end() | |
414 |
|
416 | |||
415 | @command('perfcca', formatteropts) |
|
417 | @command('perfcca', formatteropts) | |
416 | def perfcca(ui, repo, **opts): |
|
418 | def perfcca(ui, repo, **opts): | |
417 | timer, fm = gettimer(ui, opts) |
|
419 | timer, fm = gettimer(ui, opts) | |
418 | timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate)) |
|
420 | timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate)) | |
419 | fm.end() |
|
421 | fm.end() | |
420 |
|
422 | |||
421 | @command('perffncacheload', formatteropts) |
|
423 | @command('perffncacheload', formatteropts) | |
422 | def perffncacheload(ui, repo, **opts): |
|
424 | def perffncacheload(ui, repo, **opts): | |
423 | timer, fm = gettimer(ui, opts) |
|
425 | timer, fm = gettimer(ui, opts) | |
424 | s = repo.store |
|
426 | s = repo.store | |
425 | def d(): |
|
427 | def d(): | |
426 | s.fncache._load() |
|
428 | s.fncache._load() | |
427 | timer(d) |
|
429 | timer(d) | |
428 | fm.end() |
|
430 | fm.end() | |
429 |
|
431 | |||
430 | @command('perffncachewrite', formatteropts) |
|
432 | @command('perffncachewrite', formatteropts) | |
431 | def perffncachewrite(ui, repo, **opts): |
|
433 | def perffncachewrite(ui, repo, **opts): | |
432 | timer, fm = gettimer(ui, opts) |
|
434 | timer, fm = gettimer(ui, opts) | |
433 | s = repo.store |
|
435 | s = repo.store | |
434 | s.fncache._load() |
|
436 | s.fncache._load() | |
435 | lock = repo.lock() |
|
437 | lock = repo.lock() | |
436 | tr = repo.transaction('perffncachewrite') |
|
438 | tr = repo.transaction('perffncachewrite') | |
437 | def d(): |
|
439 | def d(): | |
438 | s.fncache._dirty = True |
|
440 | s.fncache._dirty = True | |
439 | s.fncache.write(tr) |
|
441 | s.fncache.write(tr) | |
440 | timer(d) |
|
442 | timer(d) | |
441 | lock.release() |
|
443 | lock.release() | |
442 | fm.end() |
|
444 | fm.end() | |
443 |
|
445 | |||
444 | @command('perffncacheencode', formatteropts) |
|
446 | @command('perffncacheencode', formatteropts) | |
445 | def perffncacheencode(ui, repo, **opts): |
|
447 | def perffncacheencode(ui, repo, **opts): | |
446 | timer, fm = gettimer(ui, opts) |
|
448 | timer, fm = gettimer(ui, opts) | |
447 | s = repo.store |
|
449 | s = repo.store | |
448 | s.fncache._load() |
|
450 | s.fncache._load() | |
449 | def d(): |
|
451 | def d(): | |
450 | for p in s.fncache.entries: |
|
452 | for p in s.fncache.entries: | |
451 | s.encode(p) |
|
453 | s.encode(p) | |
452 | timer(d) |
|
454 | timer(d) | |
453 | fm.end() |
|
455 | fm.end() | |
454 |
|
456 | |||
455 | @command('perfdiffwd', formatteropts) |
|
457 | @command('perfdiffwd', formatteropts) | |
456 | def perfdiffwd(ui, repo, **opts): |
|
458 | def perfdiffwd(ui, repo, **opts): | |
457 | """Profile diff of working directory changes""" |
|
459 | """Profile diff of working directory changes""" | |
458 | timer, fm = gettimer(ui, opts) |
|
460 | timer, fm = gettimer(ui, opts) | |
459 | options = { |
|
461 | options = { | |
460 | 'w': 'ignore_all_space', |
|
462 | 'w': 'ignore_all_space', | |
461 | 'b': 'ignore_space_change', |
|
463 | 'b': 'ignore_space_change', | |
462 | 'B': 'ignore_blank_lines', |
|
464 | 'B': 'ignore_blank_lines', | |
463 | } |
|
465 | } | |
464 |
|
466 | |||
465 | for diffopt in ('', 'w', 'b', 'B', 'wB'): |
|
467 | for diffopt in ('', 'w', 'b', 'B', 'wB'): | |
466 | opts = dict((options[c], '1') for c in diffopt) |
|
468 | opts = dict((options[c], '1') for c in diffopt) | |
467 | def d(): |
|
469 | def d(): | |
468 | ui.pushbuffer() |
|
470 | ui.pushbuffer() | |
469 | commands.diff(ui, repo, **opts) |
|
471 | commands.diff(ui, repo, **opts) | |
470 | ui.popbuffer() |
|
472 | ui.popbuffer() | |
471 | title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none') |
|
473 | title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none') | |
472 | timer(d, title) |
|
474 | timer(d, title) | |
473 | fm.end() |
|
475 | fm.end() | |
474 |
|
476 | |||
475 | @command('perfrevlog', |
|
477 | @command('perfrevlog', | |
476 | [('d', 'dist', 100, 'distance between the revisions')] + formatteropts, |
|
478 | [('d', 'dist', 100, 'distance between the revisions')] + formatteropts, | |
477 | "[INDEXFILE]") |
|
479 | "[INDEXFILE]") | |
478 | def perfrevlog(ui, repo, file_, **opts): |
|
480 | def perfrevlog(ui, repo, file_, **opts): | |
479 | timer, fm = gettimer(ui, opts) |
|
481 | timer, fm = gettimer(ui, opts) | |
480 | from mercurial import revlog |
|
482 | from mercurial import revlog | |
481 | dist = opts['dist'] |
|
483 | dist = opts['dist'] | |
482 | _len = getlen(ui) |
|
484 | _len = getlen(ui) | |
483 | def d(): |
|
485 | def d(): | |
484 | r = revlog.revlog(lambda fn: open(fn, 'rb'), file_) |
|
486 | r = revlog.revlog(lambda fn: open(fn, 'rb'), file_) | |
485 | for x in xrange(0, _len(r), dist): |
|
487 | for x in xrange(0, _len(r), dist): | |
486 | r.revision(r.node(x)) |
|
488 | r.revision(r.node(x)) | |
487 |
|
489 | |||
488 | timer(d) |
|
490 | timer(d) | |
489 | fm.end() |
|
491 | fm.end() | |
490 |
|
492 | |||
|
493 | @command('perfrevlogrevision', revlogopts + formatteropts + | |||
|
494 | [('', 'cache', False, 'use caches instead of clearing')], | |||
|
495 | '-c|-m|FILE REV') | |||
|
496 | def perfrevlogrevision(ui, repo, file_, rev=None, cache=None, **opts): | |||
|
497 | """Benchmark obtaining a revlog revision. | |||
|
498 | ||||
|
499 | Obtaining a revlog revision consists of roughly the following steps: | |||
|
500 | ||||
|
501 | 1. Compute the delta chain | |||
|
502 | 2. Obtain the raw chunks for that delta chain | |||
|
503 | 3. Decompress each raw chunk | |||
|
504 | 4. Apply binary patches to obtain fulltext | |||
|
505 | 5. Verify hash of fulltext | |||
|
506 | ||||
|
507 | This command measures the time spent in each of these phases. | |||
|
508 | """ | |||
|
509 | if opts.get('changelog') or opts.get('manifest'): | |||
|
510 | file_, rev = None, file_ | |||
|
511 | elif rev is None: | |||
|
512 | raise error.CommandError('perfrevlogrevision', 'invalid arguments') | |||
|
513 | ||||
|
514 | r = cmdutil.openrevlog(repo, 'perfrevlogrevision', file_, opts) | |||
|
515 | node = r.lookup(rev) | |||
|
516 | rev = r.rev(node) | |||
|
517 | ||||
|
518 | def dodeltachain(rev): | |||
|
519 | if not cache: | |||
|
520 | r.clearcaches() | |||
|
521 | r._deltachain(rev) | |||
|
522 | ||||
|
523 | def doread(chain): | |||
|
524 | if not cache: | |||
|
525 | r.clearcaches() | |||
|
526 | r._chunkraw(chain[0], chain[-1]) | |||
|
527 | ||||
|
528 | def dodecompress(data, chain): | |||
|
529 | if not cache: | |||
|
530 | r.clearcaches() | |||
|
531 | ||||
|
532 | start = r.start | |||
|
533 | length = r.length | |||
|
534 | inline = r._inline | |||
|
535 | iosize = r._io.size | |||
|
536 | buffer = util.buffer | |||
|
537 | offset = start(chain[0]) | |||
|
538 | ||||
|
539 | for rev in chain: | |||
|
540 | chunkstart = start(rev) | |||
|
541 | if inline: | |||
|
542 | chunkstart += (rev + 1) * iosize | |||
|
543 | chunklength = length(rev) | |||
|
544 | b = buffer(data, chunkstart - offset, chunklength) | |||
|
545 | revlog.decompress(b) | |||
|
546 | ||||
|
547 | def dopatch(text, bins): | |||
|
548 | if not cache: | |||
|
549 | r.clearcaches() | |||
|
550 | mdiff.patches(text, bins) | |||
|
551 | ||||
|
552 | def dohash(text): | |||
|
553 | if not cache: | |||
|
554 | r.clearcaches() | |||
|
555 | r._checkhash(text, node, rev) | |||
|
556 | ||||
|
557 | def dorevision(): | |||
|
558 | if not cache: | |||
|
559 | r.clearcaches() | |||
|
560 | r.revision(node) | |||
|
561 | ||||
|
562 | chain = r._deltachain(rev)[0] | |||
|
563 | data = r._chunkraw(chain[0], chain[-1]) | |||
|
564 | bins = r._chunks(chain) | |||
|
565 | text = str(bins[0]) | |||
|
566 | bins = bins[1:] | |||
|
567 | text = mdiff.patches(text, bins) | |||
|
568 | ||||
|
569 | benches = [ | |||
|
570 | (lambda: dorevision(), 'full'), | |||
|
571 | (lambda: dodeltachain(rev), 'deltachain'), | |||
|
572 | (lambda: doread(chain), 'read'), | |||
|
573 | (lambda: dodecompress(data, chain), 'decompress'), | |||
|
574 | (lambda: dopatch(text, bins), 'patch'), | |||
|
575 | (lambda: dohash(text), 'hash'), | |||
|
576 | ] | |||
|
577 | ||||
|
578 | for fn, title in benches: | |||
|
579 | timer, fm = gettimer(ui, opts) | |||
|
580 | timer(fn, title=title) | |||
|
581 | fm.end() | |||
|
582 | ||||
491 | @command('perfrevset', |
|
583 | @command('perfrevset', | |
492 | [('C', 'clear', False, 'clear volatile cache between each call.'), |
|
584 | [('C', 'clear', False, 'clear volatile cache between each call.'), | |
493 | ('', 'contexts', False, 'obtain changectx for each revision')] |
|
585 | ('', 'contexts', False, 'obtain changectx for each revision')] | |
494 | + formatteropts, "REVSET") |
|
586 | + formatteropts, "REVSET") | |
495 | def perfrevset(ui, repo, expr, clear=False, contexts=False, **opts): |
|
587 | def perfrevset(ui, repo, expr, clear=False, contexts=False, **opts): | |
496 | """benchmark the execution time of a revset |
|
588 | """benchmark the execution time of a revset | |
497 |
|
589 | |||
498 | Use the --clean option if need to evaluate the impact of build volatile |
|
590 | Use the --clean option if need to evaluate the impact of build volatile | |
499 | revisions set cache on the revset execution. Volatile cache hold filtered |
|
591 | revisions set cache on the revset execution. Volatile cache hold filtered | |
500 | and obsolete related cache.""" |
|
592 | and obsolete related cache.""" | |
501 | timer, fm = gettimer(ui, opts) |
|
593 | timer, fm = gettimer(ui, opts) | |
502 | def d(): |
|
594 | def d(): | |
503 | if clear: |
|
595 | if clear: | |
504 | repo.invalidatevolatilesets() |
|
596 | repo.invalidatevolatilesets() | |
505 | if contexts: |
|
597 | if contexts: | |
506 | for ctx in repo.set(expr): pass |
|
598 | for ctx in repo.set(expr): pass | |
507 | else: |
|
599 | else: | |
508 | for r in repo.revs(expr): pass |
|
600 | for r in repo.revs(expr): pass | |
509 | timer(d) |
|
601 | timer(d) | |
510 | fm.end() |
|
602 | fm.end() | |
511 |
|
603 | |||
512 | @command('perfvolatilesets', formatteropts) |
|
604 | @command('perfvolatilesets', formatteropts) | |
513 | def perfvolatilesets(ui, repo, *names, **opts): |
|
605 | def perfvolatilesets(ui, repo, *names, **opts): | |
514 | """benchmark the computation of various volatile set |
|
606 | """benchmark the computation of various volatile set | |
515 |
|
607 | |||
516 | Volatile set computes element related to filtering and obsolescence.""" |
|
608 | Volatile set computes element related to filtering and obsolescence.""" | |
517 | timer, fm = gettimer(ui, opts) |
|
609 | timer, fm = gettimer(ui, opts) | |
518 | repo = repo.unfiltered() |
|
610 | repo = repo.unfiltered() | |
519 |
|
611 | |||
520 | def getobs(name): |
|
612 | def getobs(name): | |
521 | def d(): |
|
613 | def d(): | |
522 | repo.invalidatevolatilesets() |
|
614 | repo.invalidatevolatilesets() | |
523 | obsolete.getrevs(repo, name) |
|
615 | obsolete.getrevs(repo, name) | |
524 | return d |
|
616 | return d | |
525 |
|
617 | |||
526 | allobs = sorted(obsolete.cachefuncs) |
|
618 | allobs = sorted(obsolete.cachefuncs) | |
527 | if names: |
|
619 | if names: | |
528 | allobs = [n for n in allobs if n in names] |
|
620 | allobs = [n for n in allobs if n in names] | |
529 |
|
621 | |||
530 | for name in allobs: |
|
622 | for name in allobs: | |
531 | timer(getobs(name), title=name) |
|
623 | timer(getobs(name), title=name) | |
532 |
|
624 | |||
533 | def getfiltered(name): |
|
625 | def getfiltered(name): | |
534 | def d(): |
|
626 | def d(): | |
535 | repo.invalidatevolatilesets() |
|
627 | repo.invalidatevolatilesets() | |
536 | repoview.filterrevs(repo, name) |
|
628 | repoview.filterrevs(repo, name) | |
537 | return d |
|
629 | return d | |
538 |
|
630 | |||
539 | allfilter = sorted(repoview.filtertable) |
|
631 | allfilter = sorted(repoview.filtertable) | |
540 | if names: |
|
632 | if names: | |
541 | allfilter = [n for n in allfilter if n in names] |
|
633 | allfilter = [n for n in allfilter if n in names] | |
542 |
|
634 | |||
543 | for name in allfilter: |
|
635 | for name in allfilter: | |
544 | timer(getfiltered(name), title=name) |
|
636 | timer(getfiltered(name), title=name) | |
545 | fm.end() |
|
637 | fm.end() | |
546 |
|
638 | |||
547 | @command('perfbranchmap', |
|
639 | @command('perfbranchmap', | |
548 | [('f', 'full', False, |
|
640 | [('f', 'full', False, | |
549 | 'Includes build time of subset'), |
|
641 | 'Includes build time of subset'), | |
550 | ] + formatteropts) |
|
642 | ] + formatteropts) | |
551 | def perfbranchmap(ui, repo, full=False, **opts): |
|
643 | def perfbranchmap(ui, repo, full=False, **opts): | |
552 | """benchmark the update of a branchmap |
|
644 | """benchmark the update of a branchmap | |
553 |
|
645 | |||
554 | This benchmarks the full repo.branchmap() call with read and write disabled |
|
646 | This benchmarks the full repo.branchmap() call with read and write disabled | |
555 | """ |
|
647 | """ | |
556 | timer, fm = gettimer(ui, opts) |
|
648 | timer, fm = gettimer(ui, opts) | |
557 | def getbranchmap(filtername): |
|
649 | def getbranchmap(filtername): | |
558 | """generate a benchmark function for the filtername""" |
|
650 | """generate a benchmark function for the filtername""" | |
559 | if filtername is None: |
|
651 | if filtername is None: | |
560 | view = repo |
|
652 | view = repo | |
561 | else: |
|
653 | else: | |
562 | view = repo.filtered(filtername) |
|
654 | view = repo.filtered(filtername) | |
563 | def d(): |
|
655 | def d(): | |
564 | if full: |
|
656 | if full: | |
565 | view._branchcaches.clear() |
|
657 | view._branchcaches.clear() | |
566 | else: |
|
658 | else: | |
567 | view._branchcaches.pop(filtername, None) |
|
659 | view._branchcaches.pop(filtername, None) | |
568 | view.branchmap() |
|
660 | view.branchmap() | |
569 | return d |
|
661 | return d | |
570 | # add filter in smaller subset to bigger subset |
|
662 | # add filter in smaller subset to bigger subset | |
571 | possiblefilters = set(repoview.filtertable) |
|
663 | possiblefilters = set(repoview.filtertable) | |
572 | allfilters = [] |
|
664 | allfilters = [] | |
573 | while possiblefilters: |
|
665 | while possiblefilters: | |
574 | for name in possiblefilters: |
|
666 | for name in possiblefilters: | |
575 | subset = branchmap.subsettable.get(name) |
|
667 | subset = branchmap.subsettable.get(name) | |
576 | if subset not in possiblefilters: |
|
668 | if subset not in possiblefilters: | |
577 | break |
|
669 | break | |
578 | else: |
|
670 | else: | |
579 | assert False, 'subset cycle %s!' % possiblefilters |
|
671 | assert False, 'subset cycle %s!' % possiblefilters | |
580 | allfilters.append(name) |
|
672 | allfilters.append(name) | |
581 | possiblefilters.remove(name) |
|
673 | possiblefilters.remove(name) | |
582 |
|
674 | |||
583 | # warm the cache |
|
675 | # warm the cache | |
584 | if not full: |
|
676 | if not full: | |
585 | for name in allfilters: |
|
677 | for name in allfilters: | |
586 | repo.filtered(name).branchmap() |
|
678 | repo.filtered(name).branchmap() | |
587 | # add unfiltered |
|
679 | # add unfiltered | |
588 | allfilters.append(None) |
|
680 | allfilters.append(None) | |
589 | oldread = branchmap.read |
|
681 | oldread = branchmap.read | |
590 | oldwrite = branchmap.branchcache.write |
|
682 | oldwrite = branchmap.branchcache.write | |
591 | try: |
|
683 | try: | |
592 | branchmap.read = lambda repo: None |
|
684 | branchmap.read = lambda repo: None | |
593 | branchmap.write = lambda repo: None |
|
685 | branchmap.write = lambda repo: None | |
594 | for name in allfilters: |
|
686 | for name in allfilters: | |
595 | timer(getbranchmap(name), title=str(name)) |
|
687 | timer(getbranchmap(name), title=str(name)) | |
596 | finally: |
|
688 | finally: | |
597 | branchmap.read = oldread |
|
689 | branchmap.read = oldread | |
598 | branchmap.branchcache.write = oldwrite |
|
690 | branchmap.branchcache.write = oldwrite | |
599 | fm.end() |
|
691 | fm.end() | |
600 |
|
692 | |||
601 | @command('perfloadmarkers') |
|
693 | @command('perfloadmarkers') | |
602 | def perfloadmarkers(ui, repo): |
|
694 | def perfloadmarkers(ui, repo): | |
603 | """benchmark the time to parse the on-disk markers for a repo |
|
695 | """benchmark the time to parse the on-disk markers for a repo | |
604 |
|
696 | |||
605 | Result is the number of markers in the repo.""" |
|
697 | Result is the number of markers in the repo.""" | |
606 | timer, fm = gettimer(ui) |
|
698 | timer, fm = gettimer(ui) | |
607 | timer(lambda: len(obsolete.obsstore(repo.svfs))) |
|
699 | timer(lambda: len(obsolete.obsstore(repo.svfs))) | |
608 | fm.end() |
|
700 | fm.end() | |
609 |
|
701 | |||
610 | @command('perflrucachedict', formatteropts + |
|
702 | @command('perflrucachedict', formatteropts + | |
611 | [('', 'size', 4, 'size of cache'), |
|
703 | [('', 'size', 4, 'size of cache'), | |
612 | ('', 'gets', 10000, 'number of key lookups'), |
|
704 | ('', 'gets', 10000, 'number of key lookups'), | |
613 | ('', 'sets', 10000, 'number of key sets'), |
|
705 | ('', 'sets', 10000, 'number of key sets'), | |
614 | ('', 'mixed', 10000, 'number of mixed mode operations'), |
|
706 | ('', 'mixed', 10000, 'number of mixed mode operations'), | |
615 | ('', 'mixedgetfreq', 50, 'frequency of get vs set ops in mixed mode')], |
|
707 | ('', 'mixedgetfreq', 50, 'frequency of get vs set ops in mixed mode')], | |
616 | norepo=True) |
|
708 | norepo=True) | |
617 | def perflrucache(ui, size=4, gets=10000, sets=10000, mixed=10000, |
|
709 | def perflrucache(ui, size=4, gets=10000, sets=10000, mixed=10000, | |
618 | mixedgetfreq=50, **opts): |
|
710 | mixedgetfreq=50, **opts): | |
619 | def doinit(): |
|
711 | def doinit(): | |
620 | for i in xrange(10000): |
|
712 | for i in xrange(10000): | |
621 | util.lrucachedict(size) |
|
713 | util.lrucachedict(size) | |
622 |
|
714 | |||
623 | values = [] |
|
715 | values = [] | |
624 | for i in xrange(size): |
|
716 | for i in xrange(size): | |
625 | values.append(random.randint(0, sys.maxint)) |
|
717 | values.append(random.randint(0, sys.maxint)) | |
626 |
|
718 | |||
627 | # Get mode fills the cache and tests raw lookup performance with no |
|
719 | # Get mode fills the cache and tests raw lookup performance with no | |
628 | # eviction. |
|
720 | # eviction. | |
629 | getseq = [] |
|
721 | getseq = [] | |
630 | for i in xrange(gets): |
|
722 | for i in xrange(gets): | |
631 | getseq.append(random.choice(values)) |
|
723 | getseq.append(random.choice(values)) | |
632 |
|
724 | |||
633 | def dogets(): |
|
725 | def dogets(): | |
634 | d = util.lrucachedict(size) |
|
726 | d = util.lrucachedict(size) | |
635 | for v in values: |
|
727 | for v in values: | |
636 | d[v] = v |
|
728 | d[v] = v | |
637 | for key in getseq: |
|
729 | for key in getseq: | |
638 | value = d[key] |
|
730 | value = d[key] | |
639 | value # silence pyflakes warning |
|
731 | value # silence pyflakes warning | |
640 |
|
732 | |||
641 | # Set mode tests insertion speed with cache eviction. |
|
733 | # Set mode tests insertion speed with cache eviction. | |
642 | setseq = [] |
|
734 | setseq = [] | |
643 | for i in xrange(sets): |
|
735 | for i in xrange(sets): | |
644 | setseq.append(random.randint(0, sys.maxint)) |
|
736 | setseq.append(random.randint(0, sys.maxint)) | |
645 |
|
737 | |||
646 | def dosets(): |
|
738 | def dosets(): | |
647 | d = util.lrucachedict(size) |
|
739 | d = util.lrucachedict(size) | |
648 | for v in setseq: |
|
740 | for v in setseq: | |
649 | d[v] = v |
|
741 | d[v] = v | |
650 |
|
742 | |||
651 | # Mixed mode randomly performs gets and sets with eviction. |
|
743 | # Mixed mode randomly performs gets and sets with eviction. | |
652 | mixedops = [] |
|
744 | mixedops = [] | |
653 | for i in xrange(mixed): |
|
745 | for i in xrange(mixed): | |
654 | r = random.randint(0, 100) |
|
746 | r = random.randint(0, 100) | |
655 | if r < mixedgetfreq: |
|
747 | if r < mixedgetfreq: | |
656 | op = 0 |
|
748 | op = 0 | |
657 | else: |
|
749 | else: | |
658 | op = 1 |
|
750 | op = 1 | |
659 |
|
751 | |||
660 | mixedops.append((op, random.randint(0, size * 2))) |
|
752 | mixedops.append((op, random.randint(0, size * 2))) | |
661 |
|
753 | |||
662 | def domixed(): |
|
754 | def domixed(): | |
663 | d = util.lrucachedict(size) |
|
755 | d = util.lrucachedict(size) | |
664 |
|
756 | |||
665 | for op, v in mixedops: |
|
757 | for op, v in mixedops: | |
666 | if op == 0: |
|
758 | if op == 0: | |
667 | try: |
|
759 | try: | |
668 | d[v] |
|
760 | d[v] | |
669 | except KeyError: |
|
761 | except KeyError: | |
670 | pass |
|
762 | pass | |
671 | else: |
|
763 | else: | |
672 | d[v] = v |
|
764 | d[v] = v | |
673 |
|
765 | |||
674 | benches = [ |
|
766 | benches = [ | |
675 | (doinit, 'init'), |
|
767 | (doinit, 'init'), | |
676 | (dogets, 'gets'), |
|
768 | (dogets, 'gets'), | |
677 | (dosets, 'sets'), |
|
769 | (dosets, 'sets'), | |
678 | (domixed, 'mixed') |
|
770 | (domixed, 'mixed') | |
679 | ] |
|
771 | ] | |
680 |
|
772 | |||
681 | for fn, title in benches: |
|
773 | for fn, title in benches: | |
682 | timer, fm = gettimer(ui, opts) |
|
774 | timer, fm = gettimer(ui, opts) | |
683 | timer(fn, title=title) |
|
775 | timer(fn, title=title) | |
684 | fm.end() |
|
776 | fm.end() |
@@ -1,148 +1,151 | |||||
1 | #require test-repo |
|
1 | #require test-repo | |
2 |
|
2 | |||
3 | Set vars: |
|
3 | Set vars: | |
4 |
|
4 | |||
5 | $ CONTRIBDIR="$TESTDIR/../contrib" |
|
5 | $ CONTRIBDIR="$TESTDIR/../contrib" | |
6 |
|
6 | |||
7 | Prepare repo: |
|
7 | Prepare repo: | |
8 |
|
8 | |||
9 | $ hg init |
|
9 | $ hg init | |
10 |
|
10 | |||
11 | $ echo this is file a > a |
|
11 | $ echo this is file a > a | |
12 | $ hg add a |
|
12 | $ hg add a | |
13 | $ hg commit -m first |
|
13 | $ hg commit -m first | |
14 |
|
14 | |||
15 | $ echo adding to file a >> a |
|
15 | $ echo adding to file a >> a | |
16 | $ hg commit -m second |
|
16 | $ hg commit -m second | |
17 |
|
17 | |||
18 | $ echo adding more to file a >> a |
|
18 | $ echo adding more to file a >> a | |
19 | $ hg commit -m third |
|
19 | $ hg commit -m third | |
20 |
|
20 | |||
21 | $ hg up -r 0 |
|
21 | $ hg up -r 0 | |
22 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
22 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
23 | $ echo merge-this >> a |
|
23 | $ echo merge-this >> a | |
24 | $ hg commit -m merge-able |
|
24 | $ hg commit -m merge-able | |
25 | created new head |
|
25 | created new head | |
26 |
|
26 | |||
27 | $ hg up -r 2 |
|
27 | $ hg up -r 2 | |
28 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved |
|
28 | 1 files updated, 0 files merged, 0 files removed, 0 files unresolved | |
29 |
|
29 | |||
30 | perfstatus |
|
30 | perfstatus | |
31 |
|
31 | |||
32 | $ cat >> $HGRCPATH << EOF |
|
32 | $ cat >> $HGRCPATH << EOF | |
33 | > [extensions] |
|
33 | > [extensions] | |
34 | > perfstatusext=$CONTRIBDIR/perf.py |
|
34 | > perfstatusext=$CONTRIBDIR/perf.py | |
35 | > [perf] |
|
35 | > [perf] | |
36 | > presleep=0 |
|
36 | > presleep=0 | |
37 | > stub=on |
|
37 | > stub=on | |
38 | > parentscount=1 |
|
38 | > parentscount=1 | |
39 | > EOF |
|
39 | > EOF | |
40 | $ hg help perfstatusext |
|
40 | $ hg help perfstatusext | |
41 | perfstatusext extension - helper extension to measure performance |
|
41 | perfstatusext extension - helper extension to measure performance | |
42 |
|
42 | |||
43 | list of commands: |
|
43 | list of commands: | |
44 |
|
44 | |||
45 | perfaddremove |
|
45 | perfaddremove | |
46 | (no help text available) |
|
46 | (no help text available) | |
47 | perfancestors |
|
47 | perfancestors | |
48 | (no help text available) |
|
48 | (no help text available) | |
49 | perfancestorset |
|
49 | perfancestorset | |
50 | (no help text available) |
|
50 | (no help text available) | |
51 | perfannotate (no help text available) |
|
51 | perfannotate (no help text available) | |
52 | perfbranchmap |
|
52 | perfbranchmap | |
53 | benchmark the update of a branchmap |
|
53 | benchmark the update of a branchmap | |
54 | perfcca (no help text available) |
|
54 | perfcca (no help text available) | |
55 | perfchangeset |
|
55 | perfchangeset | |
56 | (no help text available) |
|
56 | (no help text available) | |
57 | perfctxfiles (no help text available) |
|
57 | perfctxfiles (no help text available) | |
58 | perfdiffwd Profile diff of working directory changes |
|
58 | perfdiffwd Profile diff of working directory changes | |
59 | perfdirfoldmap |
|
59 | perfdirfoldmap | |
60 | (no help text available) |
|
60 | (no help text available) | |
61 | perfdirs (no help text available) |
|
61 | perfdirs (no help text available) | |
62 | perfdirstate (no help text available) |
|
62 | perfdirstate (no help text available) | |
63 | perfdirstatedirs |
|
63 | perfdirstatedirs | |
64 | (no help text available) |
|
64 | (no help text available) | |
65 | perfdirstatefoldmap |
|
65 | perfdirstatefoldmap | |
66 | (no help text available) |
|
66 | (no help text available) | |
67 | perfdirstatewrite |
|
67 | perfdirstatewrite | |
68 | (no help text available) |
|
68 | (no help text available) | |
69 | perffncacheencode |
|
69 | perffncacheencode | |
70 | (no help text available) |
|
70 | (no help text available) | |
71 | perffncacheload |
|
71 | perffncacheload | |
72 | (no help text available) |
|
72 | (no help text available) | |
73 | perffncachewrite |
|
73 | perffncachewrite | |
74 | (no help text available) |
|
74 | (no help text available) | |
75 | perfheads (no help text available) |
|
75 | perfheads (no help text available) | |
76 | perfindex (no help text available) |
|
76 | perfindex (no help text available) | |
77 | perfloadmarkers |
|
77 | perfloadmarkers | |
78 | benchmark the time to parse the on-disk markers for a repo |
|
78 | benchmark the time to parse the on-disk markers for a repo | |
79 | perflog (no help text available) |
|
79 | perflog (no help text available) | |
80 | perflookup (no help text available) |
|
80 | perflookup (no help text available) | |
81 | perflrucachedict |
|
81 | perflrucachedict | |
82 | (no help text available) |
|
82 | (no help text available) | |
83 | perfmanifest (no help text available) |
|
83 | perfmanifest (no help text available) | |
84 | perfmergecalculate |
|
84 | perfmergecalculate | |
85 | (no help text available) |
|
85 | (no help text available) | |
86 | perfmoonwalk benchmark walking the changelog backwards |
|
86 | perfmoonwalk benchmark walking the changelog backwards | |
87 | perfnodelookup |
|
87 | perfnodelookup | |
88 | (no help text available) |
|
88 | (no help text available) | |
89 | perfparents (no help text available) |
|
89 | perfparents (no help text available) | |
90 | perfpathcopies |
|
90 | perfpathcopies | |
91 | (no help text available) |
|
91 | (no help text available) | |
92 | perfrawfiles (no help text available) |
|
92 | perfrawfiles (no help text available) | |
93 | perfrevlog (no help text available) |
|
93 | perfrevlog (no help text available) | |
|
94 | perfrevlogrevision | |||
|
95 | Benchmark obtaining a revlog revision. | |||
94 | perfrevrange (no help text available) |
|
96 | perfrevrange (no help text available) | |
95 | perfrevset benchmark the execution time of a revset |
|
97 | perfrevset benchmark the execution time of a revset | |
96 | perfstartup (no help text available) |
|
98 | perfstartup (no help text available) | |
97 | perfstatus (no help text available) |
|
99 | perfstatus (no help text available) | |
98 | perftags (no help text available) |
|
100 | perftags (no help text available) | |
99 | perftemplating |
|
101 | perftemplating | |
100 | (no help text available) |
|
102 | (no help text available) | |
101 | perfvolatilesets |
|
103 | perfvolatilesets | |
102 | benchmark the computation of various volatile set |
|
104 | benchmark the computation of various volatile set | |
103 | perfwalk (no help text available) |
|
105 | perfwalk (no help text available) | |
104 |
|
106 | |||
105 | (use "hg help -v perfstatusext" to show built-in aliases and global options) |
|
107 | (use "hg help -v perfstatusext" to show built-in aliases and global options) | |
106 | $ hg perfaddremove |
|
108 | $ hg perfaddremove | |
107 | $ hg perfancestors |
|
109 | $ hg perfancestors | |
108 | $ hg perfancestorset 2 |
|
110 | $ hg perfancestorset 2 | |
109 | $ hg perfannotate a |
|
111 | $ hg perfannotate a | |
110 | $ hg perfbranchmap |
|
112 | $ hg perfbranchmap | |
111 | $ hg perfcca |
|
113 | $ hg perfcca | |
112 | $ hg perfchangeset 2 |
|
114 | $ hg perfchangeset 2 | |
113 | $ hg perfctxfiles 2 |
|
115 | $ hg perfctxfiles 2 | |
114 | $ hg perfdiffwd |
|
116 | $ hg perfdiffwd | |
115 | $ hg perfdirfoldmap |
|
117 | $ hg perfdirfoldmap | |
116 | $ hg perfdirs |
|
118 | $ hg perfdirs | |
117 | $ hg perfdirstate |
|
119 | $ hg perfdirstate | |
118 | $ hg perfdirstatedirs |
|
120 | $ hg perfdirstatedirs | |
119 | $ hg perfdirstatefoldmap |
|
121 | $ hg perfdirstatefoldmap | |
120 | $ hg perfdirstatewrite |
|
122 | $ hg perfdirstatewrite | |
121 | $ hg perffncacheencode |
|
123 | $ hg perffncacheencode | |
122 | $ hg perffncacheload |
|
124 | $ hg perffncacheload | |
123 | $ hg perffncachewrite |
|
125 | $ hg perffncachewrite | |
124 | transaction abort! |
|
126 | transaction abort! | |
125 | rollback completed |
|
127 | rollback completed | |
126 | $ hg perfheads |
|
128 | $ hg perfheads | |
127 | $ hg perfindex |
|
129 | $ hg perfindex | |
128 | $ hg perfloadmarkers |
|
130 | $ hg perfloadmarkers | |
129 | $ hg perflog |
|
131 | $ hg perflog | |
130 | $ hg perflookup 2 |
|
132 | $ hg perflookup 2 | |
131 | $ hg perflrucache |
|
133 | $ hg perflrucache | |
132 | $ hg perfmanifest 2 |
|
134 | $ hg perfmanifest 2 | |
133 | $ hg perfmergecalculate -r 3 |
|
135 | $ hg perfmergecalculate -r 3 | |
134 | $ hg perfmoonwalk |
|
136 | $ hg perfmoonwalk | |
135 | $ hg perfnodelookup 2 |
|
137 | $ hg perfnodelookup 2 | |
136 | $ hg perfpathcopies 1 2 |
|
138 | $ hg perfpathcopies 1 2 | |
137 | $ hg perfrawfiles 2 |
|
139 | $ hg perfrawfiles 2 | |
138 | $ hg perfrevlog .hg/store/data/a.i |
|
140 | $ hg perfrevlog .hg/store/data/a.i | |
|
141 | $ hg perfrevlogrevision -m 0 | |||
139 | $ hg perfrevrange |
|
142 | $ hg perfrevrange | |
140 | $ hg perfrevset 'all()' |
|
143 | $ hg perfrevset 'all()' | |
141 | $ hg perfstartup |
|
144 | $ hg perfstartup | |
142 | $ hg perfstatus |
|
145 | $ hg perfstatus | |
143 | $ hg perftags |
|
146 | $ hg perftags | |
144 | $ hg perftemplating |
|
147 | $ hg perftemplating | |
145 | $ hg perfvolatilesets |
|
148 | $ hg perfvolatilesets | |
146 | $ hg perfwalk |
|
149 | $ hg perfwalk | |
147 | $ hg perfparents |
|
150 | $ hg perfparents | |
148 |
|
151 |
General Comments 0
You need to be logged in to leave comments.
Login now