Show More
@@ -1,410 +1,411 | |||||
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 |
|
5 | from mercurial import repoview, branchmap, merge, copies | |
6 | import time, os, sys |
|
6 | import time, os, sys | |
7 |
|
7 | |||
8 | cmdtable = {} |
|
8 | cmdtable = {} | |
9 | command = cmdutil.command(cmdtable) |
|
9 | command = cmdutil.command(cmdtable) | |
10 |
|
10 | |||
11 | def timer(func, title=None): |
|
11 | def timer(func, title=None): | |
12 | results = [] |
|
12 | results = [] | |
13 | begin = time.time() |
|
13 | begin = time.time() | |
14 | count = 0 |
|
14 | count = 0 | |
15 | while True: |
|
15 | while True: | |
16 | ostart = os.times() |
|
16 | ostart = os.times() | |
17 | cstart = time.time() |
|
17 | cstart = time.time() | |
18 | r = func() |
|
18 | r = func() | |
19 | cstop = time.time() |
|
19 | cstop = time.time() | |
20 | ostop = os.times() |
|
20 | ostop = os.times() | |
21 | count += 1 |
|
21 | count += 1 | |
22 | a, b = ostart, ostop |
|
22 | a, b = ostart, ostop | |
23 | results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) |
|
23 | results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) | |
24 | if cstop - begin > 3 and count >= 100: |
|
24 | if cstop - begin > 3 and count >= 100: | |
25 | break |
|
25 | break | |
26 | if cstop - begin > 10 and count >= 3: |
|
26 | if cstop - begin > 10 and count >= 3: | |
27 | break |
|
27 | break | |
28 | if title: |
|
28 | if title: | |
29 | sys.stderr.write("! %s\n" % title) |
|
29 | sys.stderr.write("! %s\n" % title) | |
30 | if r: |
|
30 | if r: | |
31 | sys.stderr.write("! result: %s\n" % r) |
|
31 | sys.stderr.write("! result: %s\n" % r) | |
32 | m = min(results) |
|
32 | m = min(results) | |
33 | sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n" |
|
33 | sys.stderr.write("! wall %f comb %f user %f sys %f (best of %d)\n" | |
34 | % (m[0], m[1] + m[2], m[1], m[2], count)) |
|
34 | % (m[0], m[1] + m[2], m[1], m[2], count)) | |
35 |
|
35 | |||
36 | @command('perfwalk') |
|
36 | @command('perfwalk') | |
37 | def perfwalk(ui, repo, *pats): |
|
37 | def perfwalk(ui, repo, *pats): | |
38 | try: |
|
38 | try: | |
39 | m = scmutil.match(repo[None], pats, {}) |
|
39 | m = scmutil.match(repo[None], pats, {}) | |
40 | timer(lambda: len(list(repo.dirstate.walk(m, [], True, False)))) |
|
40 | timer(lambda: len(list(repo.dirstate.walk(m, [], True, False)))) | |
41 | except Exception: |
|
41 | except Exception: | |
42 | try: |
|
42 | try: | |
43 | m = scmutil.match(repo[None], pats, {}) |
|
43 | m = scmutil.match(repo[None], pats, {}) | |
44 | timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)])) |
|
44 | timer(lambda: len([b for a, b, c in repo.dirstate.statwalk([], m)])) | |
45 | except Exception: |
|
45 | except Exception: | |
46 | timer(lambda: len(list(cmdutil.walk(repo, pats, {})))) |
|
46 | timer(lambda: len(list(cmdutil.walk(repo, pats, {})))) | |
47 |
|
47 | |||
48 | @command('perfannotate') |
|
48 | @command('perfannotate') | |
49 | def perfannotate(ui, repo, f): |
|
49 | def perfannotate(ui, repo, f): | |
50 | fc = repo['.'][f] |
|
50 | fc = repo['.'][f] | |
51 | timer(lambda: len(fc.annotate(True))) |
|
51 | timer(lambda: len(fc.annotate(True))) | |
52 |
|
52 | |||
53 | @command('perfstatus', |
|
53 | @command('perfstatus', | |
54 | [('u', 'unknown', False, |
|
54 | [('u', 'unknown', False, | |
55 | 'ask status to look for unknown files')]) |
|
55 | 'ask status to look for unknown files')]) | |
56 | def perfstatus(ui, repo, **opts): |
|
56 | def perfstatus(ui, repo, **opts): | |
57 | #m = match.always(repo.root, repo.getcwd()) |
|
57 | #m = match.always(repo.root, repo.getcwd()) | |
58 | #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False, |
|
58 | #timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False, | |
59 | # False)))) |
|
59 | # False)))) | |
60 | timer(lambda: sum(map(len, repo.status(**opts)))) |
|
60 | timer(lambda: sum(map(len, repo.status(**opts)))) | |
61 |
|
61 | |||
62 | @command('perfaddremove') |
|
62 | @command('perfaddremove') | |
63 | def perfaddremove(ui, repo): |
|
63 | def perfaddremove(ui, repo): | |
64 | try: |
|
64 | try: | |
65 | oldquiet = repo.ui.quiet |
|
65 | oldquiet = repo.ui.quiet | |
66 | repo.ui.quiet = True |
|
66 | repo.ui.quiet = True | |
67 | timer(lambda: scmutil.addremove(repo, dry_run=True)) |
|
67 | timer(lambda: scmutil.addremove(repo, dry_run=True)) | |
68 | finally: |
|
68 | finally: | |
69 | repo.ui.quiet = oldquiet |
|
69 | repo.ui.quiet = oldquiet | |
70 |
|
70 | |||
71 | def clearcaches(cl): |
|
71 | def clearcaches(cl): | |
72 | # behave somewhat consistently across internal API changes |
|
72 | # behave somewhat consistently across internal API changes | |
73 | if util.safehasattr(cl, 'clearcaches'): |
|
73 | if util.safehasattr(cl, 'clearcaches'): | |
74 | cl.clearcaches() |
|
74 | cl.clearcaches() | |
75 | elif util.safehasattr(cl, '_nodecache'): |
|
75 | elif util.safehasattr(cl, '_nodecache'): | |
76 | from mercurial.node import nullid, nullrev |
|
76 | from mercurial.node import nullid, nullrev | |
77 | cl._nodecache = {nullid: nullrev} |
|
77 | cl._nodecache = {nullid: nullrev} | |
78 | cl._nodepos = None |
|
78 | cl._nodepos = None | |
79 |
|
79 | |||
80 | @command('perfheads') |
|
80 | @command('perfheads') | |
81 | def perfheads(ui, repo): |
|
81 | def perfheads(ui, repo): | |
82 | cl = repo.changelog |
|
82 | cl = repo.changelog | |
83 | def d(): |
|
83 | def d(): | |
84 | len(cl.headrevs()) |
|
84 | len(cl.headrevs()) | |
85 | clearcaches(cl) |
|
85 | clearcaches(cl) | |
86 | timer(d) |
|
86 | timer(d) | |
87 |
|
87 | |||
88 | @command('perftags') |
|
88 | @command('perftags') | |
89 | def perftags(ui, repo): |
|
89 | def perftags(ui, repo): | |
90 | import mercurial.changelog, mercurial.manifest |
|
90 | import mercurial.changelog, mercurial.manifest | |
91 | def t(): |
|
91 | def t(): | |
92 | repo.changelog = mercurial.changelog.changelog(repo.sopener) |
|
92 | repo.changelog = mercurial.changelog.changelog(repo.sopener) | |
93 | repo.manifest = mercurial.manifest.manifest(repo.sopener) |
|
93 | repo.manifest = mercurial.manifest.manifest(repo.sopener) | |
94 | repo._tags = None |
|
94 | repo._tags = None | |
95 | return len(repo.tags()) |
|
95 | return len(repo.tags()) | |
96 | timer(t) |
|
96 | timer(t) | |
97 |
|
97 | |||
98 | @command('perfancestors') |
|
98 | @command('perfancestors') | |
99 | def perfancestors(ui, repo): |
|
99 | def perfancestors(ui, repo): | |
100 | heads = repo.changelog.headrevs() |
|
100 | heads = repo.changelog.headrevs() | |
101 | def d(): |
|
101 | def d(): | |
102 | for a in repo.changelog.ancestors(heads): |
|
102 | for a in repo.changelog.ancestors(heads): | |
103 | pass |
|
103 | pass | |
104 | timer(d) |
|
104 | timer(d) | |
105 |
|
105 | |||
106 | @command('perfancestorset') |
|
106 | @command('perfancestorset') | |
107 | def perfancestorset(ui, repo, revset): |
|
107 | def perfancestorset(ui, repo, revset): | |
108 | revs = repo.revs(revset) |
|
108 | revs = repo.revs(revset) | |
109 | heads = repo.changelog.headrevs() |
|
109 | heads = repo.changelog.headrevs() | |
110 | def d(): |
|
110 | def d(): | |
111 | s = repo.changelog.ancestors(heads) |
|
111 | s = repo.changelog.ancestors(heads) | |
112 | for rev in revs: |
|
112 | for rev in revs: | |
113 | rev in s |
|
113 | rev in s | |
114 | timer(d) |
|
114 | timer(d) | |
115 |
|
115 | |||
116 | @command('perfdirs') |
|
116 | @command('perfdirs') | |
117 | def perfdirs(ui, repo): |
|
117 | def perfdirs(ui, repo): | |
118 | dirstate = repo.dirstate |
|
118 | dirstate = repo.dirstate | |
119 | 'a' in dirstate |
|
119 | 'a' in dirstate | |
120 | def d(): |
|
120 | def d(): | |
121 | dirstate.dirs() |
|
121 | dirstate.dirs() | |
122 | del dirstate._dirs |
|
122 | del dirstate._dirs | |
123 | timer(d) |
|
123 | timer(d) | |
124 |
|
124 | |||
125 | @command('perfdirstate') |
|
125 | @command('perfdirstate') | |
126 | def perfdirstate(ui, repo): |
|
126 | def perfdirstate(ui, repo): | |
127 | "a" in repo.dirstate |
|
127 | "a" in repo.dirstate | |
128 | def d(): |
|
128 | def d(): | |
129 | repo.dirstate.invalidate() |
|
129 | repo.dirstate.invalidate() | |
130 | "a" in repo.dirstate |
|
130 | "a" in repo.dirstate | |
131 | timer(d) |
|
131 | timer(d) | |
132 |
|
132 | |||
133 | @command('perfdirstatedirs') |
|
133 | @command('perfdirstatedirs') | |
134 | def perfdirstatedirs(ui, repo): |
|
134 | def perfdirstatedirs(ui, repo): | |
135 | "a" in repo.dirstate |
|
135 | "a" in repo.dirstate | |
136 | def d(): |
|
136 | def d(): | |
137 | "a" in repo.dirstate._dirs |
|
137 | "a" in repo.dirstate._dirs | |
138 | del repo.dirstate._dirs |
|
138 | del repo.dirstate._dirs | |
139 | timer(d) |
|
139 | timer(d) | |
140 |
|
140 | |||
141 | @command('perfdirstatewrite') |
|
141 | @command('perfdirstatewrite') | |
142 | def perfdirstatewrite(ui, repo): |
|
142 | def perfdirstatewrite(ui, repo): | |
143 | ds = repo.dirstate |
|
143 | ds = repo.dirstate | |
144 | "a" in ds |
|
144 | "a" in ds | |
145 | def d(): |
|
145 | def d(): | |
146 | ds._dirty = True |
|
146 | ds._dirty = True | |
147 | ds.write() |
|
147 | ds.write() | |
148 | timer(d) |
|
148 | timer(d) | |
149 |
|
149 | |||
150 | @command('perfmergecalculate', |
|
150 | @command('perfmergecalculate', | |
151 | [('r', 'rev', '.', 'rev to merge against')]) |
|
151 | [('r', 'rev', '.', 'rev to merge against')]) | |
152 | def perfmergecalculate(ui, repo, rev): |
|
152 | def perfmergecalculate(ui, repo, rev): | |
153 | wctx = repo[None] |
|
153 | wctx = repo[None] | |
154 | rctx = scmutil.revsingle(repo, rev, rev) |
|
154 | rctx = scmutil.revsingle(repo, rev, rev) | |
155 | ancestor = wctx.ancestor(rctx) |
|
155 | ancestor = wctx.ancestor(rctx) | |
156 | # we don't want working dir files to be stat'd in the benchmark, so prime |
|
156 | # we don't want working dir files to be stat'd in the benchmark, so prime | |
157 | # that cache |
|
157 | # that cache | |
158 | wctx.dirty() |
|
158 | wctx.dirty() | |
159 | def d(): |
|
159 | def d(): | |
160 | # acceptremote is True because we don't want prompts in the middle of |
|
160 | # acceptremote is True because we don't want prompts in the middle of | |
161 | # our benchmark |
|
161 | # our benchmark | |
162 | merge.calculateupdates(repo, wctx, rctx, ancestor, False, False, False, |
|
162 | merge.calculateupdates(repo, wctx, rctx, ancestor, False, False, False, | |
163 | acceptremote=True) |
|
163 | acceptremote=True) | |
164 | timer(d) |
|
164 | timer(d) | |
165 |
|
165 | |||
166 | @command('perfpathcopies', [], "REV REV") |
|
166 | @command('perfpathcopies', [], "REV REV") | |
167 | def perfpathcopies(ui, repo, rev1, rev2): |
|
167 | def perfpathcopies(ui, repo, rev1, rev2): | |
168 | ctx1 = scmutil.revsingle(repo, rev1, rev1) |
|
168 | ctx1 = scmutil.revsingle(repo, rev1, rev1) | |
169 | ctx2 = scmutil.revsingle(repo, rev2, rev2) |
|
169 | ctx2 = scmutil.revsingle(repo, rev2, rev2) | |
170 | def d(): |
|
170 | def d(): | |
171 | copies.pathcopies(ctx1, ctx2) |
|
171 | copies.pathcopies(ctx1, ctx2) | |
172 | timer(d) |
|
172 | timer(d) | |
173 |
|
173 | |||
174 | @command('perfmanifest') |
|
174 | @command('perfmanifest', [], 'REV') | |
175 | def perfmanifest(ui, repo): |
|
175 | def perfmanifest(ui, repo, rev): | |
|
176 | ctx = scmutil.revsingle(repo, rev, rev) | |||
|
177 | t = ctx.manifestnode() | |||
176 | def d(): |
|
178 | def d(): | |
177 | t = repo.manifest.tip() |
|
|||
178 | repo.manifest._mancache.clear() |
|
179 | repo.manifest._mancache.clear() | |
179 | repo.manifest._cache = None |
|
180 | repo.manifest._cache = None | |
180 | repo.manifest.read(t) |
|
181 | repo.manifest.read(t) | |
181 | timer(d) |
|
182 | timer(d) | |
182 |
|
183 | |||
183 | @command('perfchangeset') |
|
184 | @command('perfchangeset') | |
184 | def perfchangeset(ui, repo, rev): |
|
185 | def perfchangeset(ui, repo, rev): | |
185 | n = repo[rev].node() |
|
186 | n = repo[rev].node() | |
186 | def d(): |
|
187 | def d(): | |
187 | repo.changelog.read(n) |
|
188 | repo.changelog.read(n) | |
188 | #repo.changelog._cache = None |
|
189 | #repo.changelog._cache = None | |
189 | timer(d) |
|
190 | timer(d) | |
190 |
|
191 | |||
191 | @command('perfindex') |
|
192 | @command('perfindex') | |
192 | def perfindex(ui, repo): |
|
193 | def perfindex(ui, repo): | |
193 | import mercurial.revlog |
|
194 | import mercurial.revlog | |
194 | mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg |
|
195 | mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg | |
195 | n = repo["tip"].node() |
|
196 | n = repo["tip"].node() | |
196 | def d(): |
|
197 | def d(): | |
197 | cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i") |
|
198 | cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i") | |
198 | cl.rev(n) |
|
199 | cl.rev(n) | |
199 | timer(d) |
|
200 | timer(d) | |
200 |
|
201 | |||
201 | @command('perfstartup') |
|
202 | @command('perfstartup') | |
202 | def perfstartup(ui, repo): |
|
203 | def perfstartup(ui, repo): | |
203 | cmd = sys.argv[0] |
|
204 | cmd = sys.argv[0] | |
204 | def d(): |
|
205 | def d(): | |
205 | os.system("HGRCPATH= %s version -q > /dev/null" % cmd) |
|
206 | os.system("HGRCPATH= %s version -q > /dev/null" % cmd) | |
206 | timer(d) |
|
207 | timer(d) | |
207 |
|
208 | |||
208 | @command('perfparents') |
|
209 | @command('perfparents') | |
209 | def perfparents(ui, repo): |
|
210 | def perfparents(ui, repo): | |
210 | nl = [repo.changelog.node(i) for i in xrange(1000)] |
|
211 | nl = [repo.changelog.node(i) for i in xrange(1000)] | |
211 | def d(): |
|
212 | def d(): | |
212 | for n in nl: |
|
213 | for n in nl: | |
213 | repo.changelog.parents(n) |
|
214 | repo.changelog.parents(n) | |
214 | timer(d) |
|
215 | timer(d) | |
215 |
|
216 | |||
216 | @command('perflookup') |
|
217 | @command('perflookup') | |
217 | def perflookup(ui, repo, rev): |
|
218 | def perflookup(ui, repo, rev): | |
218 | timer(lambda: len(repo.lookup(rev))) |
|
219 | timer(lambda: len(repo.lookup(rev))) | |
219 |
|
220 | |||
220 | @command('perfrevrange') |
|
221 | @command('perfrevrange') | |
221 | def perfrevrange(ui, repo, *specs): |
|
222 | def perfrevrange(ui, repo, *specs): | |
222 | revrange = scmutil.revrange |
|
223 | revrange = scmutil.revrange | |
223 | timer(lambda: len(revrange(repo, specs))) |
|
224 | timer(lambda: len(revrange(repo, specs))) | |
224 |
|
225 | |||
225 | @command('perfnodelookup') |
|
226 | @command('perfnodelookup') | |
226 | def perfnodelookup(ui, repo, rev): |
|
227 | def perfnodelookup(ui, repo, rev): | |
227 | import mercurial.revlog |
|
228 | import mercurial.revlog | |
228 | mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg |
|
229 | mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg | |
229 | n = repo[rev].node() |
|
230 | n = repo[rev].node() | |
230 | cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i") |
|
231 | cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i") | |
231 | def d(): |
|
232 | def d(): | |
232 | cl.rev(n) |
|
233 | cl.rev(n) | |
233 | clearcaches(cl) |
|
234 | clearcaches(cl) | |
234 | timer(d) |
|
235 | timer(d) | |
235 |
|
236 | |||
236 | @command('perflog', |
|
237 | @command('perflog', | |
237 | [('', 'rename', False, 'ask log to follow renames')]) |
|
238 | [('', 'rename', False, 'ask log to follow renames')]) | |
238 | def perflog(ui, repo, **opts): |
|
239 | def perflog(ui, repo, **opts): | |
239 | ui.pushbuffer() |
|
240 | ui.pushbuffer() | |
240 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', |
|
241 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', | |
241 | copies=opts.get('rename'))) |
|
242 | copies=opts.get('rename'))) | |
242 | ui.popbuffer() |
|
243 | ui.popbuffer() | |
243 |
|
244 | |||
244 | @command('perftemplating') |
|
245 | @command('perftemplating') | |
245 | def perftemplating(ui, repo): |
|
246 | def perftemplating(ui, repo): | |
246 | ui.pushbuffer() |
|
247 | ui.pushbuffer() | |
247 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', |
|
248 | timer(lambda: commands.log(ui, repo, rev=[], date='', user='', | |
248 | template='{date|shortdate} [{rev}:{node|short}]' |
|
249 | template='{date|shortdate} [{rev}:{node|short}]' | |
249 | ' {author|person}: {desc|firstline}\n')) |
|
250 | ' {author|person}: {desc|firstline}\n')) | |
250 | ui.popbuffer() |
|
251 | ui.popbuffer() | |
251 |
|
252 | |||
252 | @command('perfcca') |
|
253 | @command('perfcca') | |
253 | def perfcca(ui, repo): |
|
254 | def perfcca(ui, repo): | |
254 | timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate)) |
|
255 | timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate)) | |
255 |
|
256 | |||
256 | @command('perffncacheload') |
|
257 | @command('perffncacheload') | |
257 | def perffncacheload(ui, repo): |
|
258 | def perffncacheload(ui, repo): | |
258 | s = repo.store |
|
259 | s = repo.store | |
259 | def d(): |
|
260 | def d(): | |
260 | s.fncache._load() |
|
261 | s.fncache._load() | |
261 | timer(d) |
|
262 | timer(d) | |
262 |
|
263 | |||
263 | @command('perffncachewrite') |
|
264 | @command('perffncachewrite') | |
264 | def perffncachewrite(ui, repo): |
|
265 | def perffncachewrite(ui, repo): | |
265 | s = repo.store |
|
266 | s = repo.store | |
266 | s.fncache._load() |
|
267 | s.fncache._load() | |
267 | def d(): |
|
268 | def d(): | |
268 | s.fncache._dirty = True |
|
269 | s.fncache._dirty = True | |
269 | s.fncache.write() |
|
270 | s.fncache.write() | |
270 | timer(d) |
|
271 | timer(d) | |
271 |
|
272 | |||
272 | @command('perffncacheencode') |
|
273 | @command('perffncacheencode') | |
273 | def perffncacheencode(ui, repo): |
|
274 | def perffncacheencode(ui, repo): | |
274 | s = repo.store |
|
275 | s = repo.store | |
275 | s.fncache._load() |
|
276 | s.fncache._load() | |
276 | def d(): |
|
277 | def d(): | |
277 | for p in s.fncache.entries: |
|
278 | for p in s.fncache.entries: | |
278 | s.encode(p) |
|
279 | s.encode(p) | |
279 | timer(d) |
|
280 | timer(d) | |
280 |
|
281 | |||
281 | @command('perfdiffwd') |
|
282 | @command('perfdiffwd') | |
282 | def perfdiffwd(ui, repo): |
|
283 | def perfdiffwd(ui, repo): | |
283 | """Profile diff of working directory changes""" |
|
284 | """Profile diff of working directory changes""" | |
284 | options = { |
|
285 | options = { | |
285 | 'w': 'ignore_all_space', |
|
286 | 'w': 'ignore_all_space', | |
286 | 'b': 'ignore_space_change', |
|
287 | 'b': 'ignore_space_change', | |
287 | 'B': 'ignore_blank_lines', |
|
288 | 'B': 'ignore_blank_lines', | |
288 | } |
|
289 | } | |
289 |
|
290 | |||
290 | for diffopt in ('', 'w', 'b', 'B', 'wB'): |
|
291 | for diffopt in ('', 'w', 'b', 'B', 'wB'): | |
291 | opts = dict((options[c], '1') for c in diffopt) |
|
292 | opts = dict((options[c], '1') for c in diffopt) | |
292 | def d(): |
|
293 | def d(): | |
293 | ui.pushbuffer() |
|
294 | ui.pushbuffer() | |
294 | commands.diff(ui, repo, **opts) |
|
295 | commands.diff(ui, repo, **opts) | |
295 | ui.popbuffer() |
|
296 | ui.popbuffer() | |
296 | title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none') |
|
297 | title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none') | |
297 | timer(d, title) |
|
298 | timer(d, title) | |
298 |
|
299 | |||
299 | @command('perfrevlog', |
|
300 | @command('perfrevlog', | |
300 | [('d', 'dist', 100, 'distance between the revisions')], |
|
301 | [('d', 'dist', 100, 'distance between the revisions')], | |
301 | "[INDEXFILE]") |
|
302 | "[INDEXFILE]") | |
302 | def perfrevlog(ui, repo, file_, **opts): |
|
303 | def perfrevlog(ui, repo, file_, **opts): | |
303 | from mercurial import revlog |
|
304 | from mercurial import revlog | |
304 | dist = opts['dist'] |
|
305 | dist = opts['dist'] | |
305 | def d(): |
|
306 | def d(): | |
306 | r = revlog.revlog(lambda fn: open(fn, 'rb'), file_) |
|
307 | r = revlog.revlog(lambda fn: open(fn, 'rb'), file_) | |
307 | for x in xrange(0, len(r), dist): |
|
308 | for x in xrange(0, len(r), dist): | |
308 | r.revision(r.node(x)) |
|
309 | r.revision(r.node(x)) | |
309 |
|
310 | |||
310 | timer(d) |
|
311 | timer(d) | |
311 |
|
312 | |||
312 | @command('perfrevset', |
|
313 | @command('perfrevset', | |
313 | [('C', 'clear', False, 'clear volatile cache between each call.')], |
|
314 | [('C', 'clear', False, 'clear volatile cache between each call.')], | |
314 | "REVSET") |
|
315 | "REVSET") | |
315 | def perfrevset(ui, repo, expr, clear=False): |
|
316 | def perfrevset(ui, repo, expr, clear=False): | |
316 | """benchmark the execution time of a revset |
|
317 | """benchmark the execution time of a revset | |
317 |
|
318 | |||
318 | Use the --clean option if need to evaluate the impact of build volatile |
|
319 | Use the --clean option if need to evaluate the impact of build volatile | |
319 | revisions set cache on the revset execution. Volatile cache hold filtered |
|
320 | revisions set cache on the revset execution. Volatile cache hold filtered | |
320 | and obsolete related cache.""" |
|
321 | and obsolete related cache.""" | |
321 | def d(): |
|
322 | def d(): | |
322 | if clear: |
|
323 | if clear: | |
323 | repo.invalidatevolatilesets() |
|
324 | repo.invalidatevolatilesets() | |
324 | repo.revs(expr) |
|
325 | repo.revs(expr) | |
325 | timer(d) |
|
326 | timer(d) | |
326 |
|
327 | |||
327 | @command('perfvolatilesets') |
|
328 | @command('perfvolatilesets') | |
328 | def perfvolatilesets(ui, repo, *names): |
|
329 | def perfvolatilesets(ui, repo, *names): | |
329 | """benchmark the computation of various volatile set |
|
330 | """benchmark the computation of various volatile set | |
330 |
|
331 | |||
331 | Volatile set computes element related to filtering and obsolescence.""" |
|
332 | Volatile set computes element related to filtering and obsolescence.""" | |
332 | repo = repo.unfiltered() |
|
333 | repo = repo.unfiltered() | |
333 |
|
334 | |||
334 | def getobs(name): |
|
335 | def getobs(name): | |
335 | def d(): |
|
336 | def d(): | |
336 | repo.invalidatevolatilesets() |
|
337 | repo.invalidatevolatilesets() | |
337 | obsolete.getrevs(repo, name) |
|
338 | obsolete.getrevs(repo, name) | |
338 | return d |
|
339 | return d | |
339 |
|
340 | |||
340 | allobs = sorted(obsolete.cachefuncs) |
|
341 | allobs = sorted(obsolete.cachefuncs) | |
341 | if names: |
|
342 | if names: | |
342 | allobs = [n for n in allobs if n in names] |
|
343 | allobs = [n for n in allobs if n in names] | |
343 |
|
344 | |||
344 | for name in allobs: |
|
345 | for name in allobs: | |
345 | timer(getobs(name), title=name) |
|
346 | timer(getobs(name), title=name) | |
346 |
|
347 | |||
347 | def getfiltered(name): |
|
348 | def getfiltered(name): | |
348 | def d(): |
|
349 | def d(): | |
349 | repo.invalidatevolatilesets() |
|
350 | repo.invalidatevolatilesets() | |
350 | repoview.filteredrevs(repo, name) |
|
351 | repoview.filteredrevs(repo, name) | |
351 | return d |
|
352 | return d | |
352 |
|
353 | |||
353 | allfilter = sorted(repoview.filtertable) |
|
354 | allfilter = sorted(repoview.filtertable) | |
354 | if names: |
|
355 | if names: | |
355 | allfilter = [n for n in allfilter if n in names] |
|
356 | allfilter = [n for n in allfilter if n in names] | |
356 |
|
357 | |||
357 | for name in allfilter: |
|
358 | for name in allfilter: | |
358 | timer(getfiltered(name), title=name) |
|
359 | timer(getfiltered(name), title=name) | |
359 |
|
360 | |||
360 | @command('perfbranchmap', |
|
361 | @command('perfbranchmap', | |
361 | [('f', 'full', False, |
|
362 | [('f', 'full', False, | |
362 | 'Includes build time of subset'), |
|
363 | 'Includes build time of subset'), | |
363 | ]) |
|
364 | ]) | |
364 | def perfbranchmap(ui, repo, full=False): |
|
365 | def perfbranchmap(ui, repo, full=False): | |
365 | """benchmark the update of a branchmap |
|
366 | """benchmark the update of a branchmap | |
366 |
|
367 | |||
367 | This benchmarks the full repo.branchmap() call with read and write disabled |
|
368 | This benchmarks the full repo.branchmap() call with read and write disabled | |
368 | """ |
|
369 | """ | |
369 | def getbranchmap(filtername): |
|
370 | def getbranchmap(filtername): | |
370 | """generate a benchmark function for the filtername""" |
|
371 | """generate a benchmark function for the filtername""" | |
371 | if filtername is None: |
|
372 | if filtername is None: | |
372 | view = repo |
|
373 | view = repo | |
373 | else: |
|
374 | else: | |
374 | view = repo.filtered(filtername) |
|
375 | view = repo.filtered(filtername) | |
375 | def d(): |
|
376 | def d(): | |
376 | if full: |
|
377 | if full: | |
377 | view._branchcaches.clear() |
|
378 | view._branchcaches.clear() | |
378 | else: |
|
379 | else: | |
379 | view._branchcaches.pop(filtername, None) |
|
380 | view._branchcaches.pop(filtername, None) | |
380 | view.branchmap() |
|
381 | view.branchmap() | |
381 | return d |
|
382 | return d | |
382 | # add filter in smaller subset to bigger subset |
|
383 | # add filter in smaller subset to bigger subset | |
383 | possiblefilters = set(repoview.filtertable) |
|
384 | possiblefilters = set(repoview.filtertable) | |
384 | allfilters = [] |
|
385 | allfilters = [] | |
385 | while possiblefilters: |
|
386 | while possiblefilters: | |
386 | for name in possiblefilters: |
|
387 | for name in possiblefilters: | |
387 | subset = repoview.subsettable.get(name) |
|
388 | subset = repoview.subsettable.get(name) | |
388 | if subset not in possiblefilters: |
|
389 | if subset not in possiblefilters: | |
389 | break |
|
390 | break | |
390 | else: |
|
391 | else: | |
391 | assert False, 'subset cycle %s!' % possiblefilters |
|
392 | assert False, 'subset cycle %s!' % possiblefilters | |
392 | allfilters.append(name) |
|
393 | allfilters.append(name) | |
393 | possiblefilters.remove(name) |
|
394 | possiblefilters.remove(name) | |
394 |
|
395 | |||
395 | # warm the cache |
|
396 | # warm the cache | |
396 | if not full: |
|
397 | if not full: | |
397 | for name in allfilters: |
|
398 | for name in allfilters: | |
398 | repo.filtered(name).branchmap() |
|
399 | repo.filtered(name).branchmap() | |
399 | # add unfiltered |
|
400 | # add unfiltered | |
400 | allfilters.append(None) |
|
401 | allfilters.append(None) | |
401 | oldread = branchmap.read |
|
402 | oldread = branchmap.read | |
402 | oldwrite = branchmap.branchcache.write |
|
403 | oldwrite = branchmap.branchcache.write | |
403 | try: |
|
404 | try: | |
404 | branchmap.read = lambda repo: None |
|
405 | branchmap.read = lambda repo: None | |
405 | branchmap.write = lambda repo: None |
|
406 | branchmap.write = lambda repo: None | |
406 | for name in allfilters: |
|
407 | for name in allfilters: | |
407 | timer(getbranchmap(name), title=str(name)) |
|
408 | timer(getbranchmap(name), title=str(name)) | |
408 | finally: |
|
409 | finally: | |
409 | branchmap.read = oldread |
|
410 | branchmap.read = oldread | |
410 | branchmap.branchcache.write = oldwrite |
|
411 | branchmap.branchcache.write = oldwrite |
General Comments 0
You need to be logged in to leave comments.
Login now