##// END OF EJS Templates
perf: add perfmoonwalk command to walk the changelog backwards...
Brodie Rao -
r20178:74aea4be default
parent child Browse files
Show More
@@ -1,412 +1,424 b''
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
90 import mercurial.changelog
91 import mercurial.manifest
91 import mercurial.manifest
92 def t():
92 def t():
93 repo.changelog = mercurial.changelog.changelog(repo.sopener)
93 repo.changelog = mercurial.changelog.changelog(repo.sopener)
94 repo.manifest = mercurial.manifest.manifest(repo.sopener)
94 repo.manifest = mercurial.manifest.manifest(repo.sopener)
95 repo._tags = None
95 repo._tags = None
96 return len(repo.tags())
96 return len(repo.tags())
97 timer(t)
97 timer(t)
98
98
99 @command('perfancestors')
99 @command('perfancestors')
100 def perfancestors(ui, repo):
100 def perfancestors(ui, repo):
101 heads = repo.changelog.headrevs()
101 heads = repo.changelog.headrevs()
102 def d():
102 def d():
103 for a in repo.changelog.ancestors(heads):
103 for a in repo.changelog.ancestors(heads):
104 pass
104 pass
105 timer(d)
105 timer(d)
106
106
107 @command('perfancestorset')
107 @command('perfancestorset')
108 def perfancestorset(ui, repo, revset):
108 def perfancestorset(ui, repo, revset):
109 revs = repo.revs(revset)
109 revs = repo.revs(revset)
110 heads = repo.changelog.headrevs()
110 heads = repo.changelog.headrevs()
111 def d():
111 def d():
112 s = repo.changelog.ancestors(heads)
112 s = repo.changelog.ancestors(heads)
113 for rev in revs:
113 for rev in revs:
114 rev in s
114 rev in s
115 timer(d)
115 timer(d)
116
116
117 @command('perfdirs')
117 @command('perfdirs')
118 def perfdirs(ui, repo):
118 def perfdirs(ui, repo):
119 dirstate = repo.dirstate
119 dirstate = repo.dirstate
120 'a' in dirstate
120 'a' in dirstate
121 def d():
121 def d():
122 dirstate.dirs()
122 dirstate.dirs()
123 del dirstate._dirs
123 del dirstate._dirs
124 timer(d)
124 timer(d)
125
125
126 @command('perfdirstate')
126 @command('perfdirstate')
127 def perfdirstate(ui, repo):
127 def perfdirstate(ui, repo):
128 "a" in repo.dirstate
128 "a" in repo.dirstate
129 def d():
129 def d():
130 repo.dirstate.invalidate()
130 repo.dirstate.invalidate()
131 "a" in repo.dirstate
131 "a" in repo.dirstate
132 timer(d)
132 timer(d)
133
133
134 @command('perfdirstatedirs')
134 @command('perfdirstatedirs')
135 def perfdirstatedirs(ui, repo):
135 def perfdirstatedirs(ui, repo):
136 "a" in repo.dirstate
136 "a" in repo.dirstate
137 def d():
137 def d():
138 "a" in repo.dirstate._dirs
138 "a" in repo.dirstate._dirs
139 del repo.dirstate._dirs
139 del repo.dirstate._dirs
140 timer(d)
140 timer(d)
141
141
142 @command('perfdirstatewrite')
142 @command('perfdirstatewrite')
143 def perfdirstatewrite(ui, repo):
143 def perfdirstatewrite(ui, repo):
144 ds = repo.dirstate
144 ds = repo.dirstate
145 "a" in ds
145 "a" in ds
146 def d():
146 def d():
147 ds._dirty = True
147 ds._dirty = True
148 ds.write()
148 ds.write()
149 timer(d)
149 timer(d)
150
150
151 @command('perfmergecalculate',
151 @command('perfmergecalculate',
152 [('r', 'rev', '.', 'rev to merge against')])
152 [('r', 'rev', '.', 'rev to merge against')])
153 def perfmergecalculate(ui, repo, rev):
153 def perfmergecalculate(ui, repo, rev):
154 wctx = repo[None]
154 wctx = repo[None]
155 rctx = scmutil.revsingle(repo, rev, rev)
155 rctx = scmutil.revsingle(repo, rev, rev)
156 ancestor = wctx.ancestor(rctx)
156 ancestor = wctx.ancestor(rctx)
157 # we don't want working dir files to be stat'd in the benchmark, so prime
157 # we don't want working dir files to be stat'd in the benchmark, so prime
158 # that cache
158 # that cache
159 wctx.dirty()
159 wctx.dirty()
160 def d():
160 def d():
161 # acceptremote is True because we don't want prompts in the middle of
161 # acceptremote is True because we don't want prompts in the middle of
162 # our benchmark
162 # our benchmark
163 merge.calculateupdates(repo, wctx, rctx, ancestor, False, False, False,
163 merge.calculateupdates(repo, wctx, rctx, ancestor, False, False, False,
164 acceptremote=True)
164 acceptremote=True)
165 timer(d)
165 timer(d)
166
166
167 @command('perfpathcopies', [], "REV REV")
167 @command('perfpathcopies', [], "REV REV")
168 def perfpathcopies(ui, repo, rev1, rev2):
168 def perfpathcopies(ui, repo, rev1, rev2):
169 ctx1 = scmutil.revsingle(repo, rev1, rev1)
169 ctx1 = scmutil.revsingle(repo, rev1, rev1)
170 ctx2 = scmutil.revsingle(repo, rev2, rev2)
170 ctx2 = scmutil.revsingle(repo, rev2, rev2)
171 def d():
171 def d():
172 copies.pathcopies(ctx1, ctx2)
172 copies.pathcopies(ctx1, ctx2)
173 timer(d)
173 timer(d)
174
174
175 @command('perfmanifest', [], 'REV')
175 @command('perfmanifest', [], 'REV')
176 def perfmanifest(ui, repo, rev):
176 def perfmanifest(ui, repo, rev):
177 ctx = scmutil.revsingle(repo, rev, rev)
177 ctx = scmutil.revsingle(repo, rev, rev)
178 t = ctx.manifestnode()
178 t = ctx.manifestnode()
179 def d():
179 def d():
180 repo.manifest._mancache.clear()
180 repo.manifest._mancache.clear()
181 repo.manifest._cache = None
181 repo.manifest._cache = None
182 repo.manifest.read(t)
182 repo.manifest.read(t)
183 timer(d)
183 timer(d)
184
184
185 @command('perfchangeset')
185 @command('perfchangeset')
186 def perfchangeset(ui, repo, rev):
186 def perfchangeset(ui, repo, rev):
187 n = repo[rev].node()
187 n = repo[rev].node()
188 def d():
188 def d():
189 repo.changelog.read(n)
189 repo.changelog.read(n)
190 #repo.changelog._cache = None
190 #repo.changelog._cache = None
191 timer(d)
191 timer(d)
192
192
193 @command('perfindex')
193 @command('perfindex')
194 def perfindex(ui, repo):
194 def perfindex(ui, repo):
195 import mercurial.revlog
195 import mercurial.revlog
196 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
196 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
197 n = repo["tip"].node()
197 n = repo["tip"].node()
198 def d():
198 def d():
199 cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i")
199 cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i")
200 cl.rev(n)
200 cl.rev(n)
201 timer(d)
201 timer(d)
202
202
203 @command('perfstartup')
203 @command('perfstartup')
204 def perfstartup(ui, repo):
204 def perfstartup(ui, repo):
205 cmd = sys.argv[0]
205 cmd = sys.argv[0]
206 def d():
206 def d():
207 os.system("HGRCPATH= %s version -q > /dev/null" % cmd)
207 os.system("HGRCPATH= %s version -q > /dev/null" % cmd)
208 timer(d)
208 timer(d)
209
209
210 @command('perfparents')
210 @command('perfparents')
211 def perfparents(ui, repo):
211 def perfparents(ui, repo):
212 nl = [repo.changelog.node(i) for i in xrange(1000)]
212 nl = [repo.changelog.node(i) for i in xrange(1000)]
213 def d():
213 def d():
214 for n in nl:
214 for n in nl:
215 repo.changelog.parents(n)
215 repo.changelog.parents(n)
216 timer(d)
216 timer(d)
217
217
218 @command('perflookup')
218 @command('perflookup')
219 def perflookup(ui, repo, rev):
219 def perflookup(ui, repo, rev):
220 timer(lambda: len(repo.lookup(rev)))
220 timer(lambda: len(repo.lookup(rev)))
221
221
222 @command('perfrevrange')
222 @command('perfrevrange')
223 def perfrevrange(ui, repo, *specs):
223 def perfrevrange(ui, repo, *specs):
224 revrange = scmutil.revrange
224 revrange = scmutil.revrange
225 timer(lambda: len(revrange(repo, specs)))
225 timer(lambda: len(revrange(repo, specs)))
226
226
227 @command('perfnodelookup')
227 @command('perfnodelookup')
228 def perfnodelookup(ui, repo, rev):
228 def perfnodelookup(ui, repo, rev):
229 import mercurial.revlog
229 import mercurial.revlog
230 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
230 mercurial.revlog._prereadsize = 2**24 # disable lazy parser in old hg
231 n = repo[rev].node()
231 n = repo[rev].node()
232 cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i")
232 cl = mercurial.revlog.revlog(repo.sopener, "00changelog.i")
233 def d():
233 def d():
234 cl.rev(n)
234 cl.rev(n)
235 clearcaches(cl)
235 clearcaches(cl)
236 timer(d)
236 timer(d)
237
237
238 @command('perflog',
238 @command('perflog',
239 [('', 'rename', False, 'ask log to follow renames')])
239 [('', 'rename', False, 'ask log to follow renames')])
240 def perflog(ui, repo, **opts):
240 def perflog(ui, repo, **opts):
241 ui.pushbuffer()
241 ui.pushbuffer()
242 timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
242 timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
243 copies=opts.get('rename')))
243 copies=opts.get('rename')))
244 ui.popbuffer()
244 ui.popbuffer()
245
245
246 @command('perfmoonwalk')
247 def perfmoonwalk(ui, repo):
248 """benchmark walking the changelog backwards
249
250 This also loads the changelog data for each revision in the changelog.
251 """
252 def moonwalk():
253 for i in xrange(len(repo), -1, -1):
254 ctx = repo[i]
255 ctx.branch() # read changelog data (in addition to the index)
256 timer(moonwalk)
257
246 @command('perftemplating')
258 @command('perftemplating')
247 def perftemplating(ui, repo):
259 def perftemplating(ui, repo):
248 ui.pushbuffer()
260 ui.pushbuffer()
249 timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
261 timer(lambda: commands.log(ui, repo, rev=[], date='', user='',
250 template='{date|shortdate} [{rev}:{node|short}]'
262 template='{date|shortdate} [{rev}:{node|short}]'
251 ' {author|person}: {desc|firstline}\n'))
263 ' {author|person}: {desc|firstline}\n'))
252 ui.popbuffer()
264 ui.popbuffer()
253
265
254 @command('perfcca')
266 @command('perfcca')
255 def perfcca(ui, repo):
267 def perfcca(ui, repo):
256 timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate))
268 timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate))
257
269
258 @command('perffncacheload')
270 @command('perffncacheload')
259 def perffncacheload(ui, repo):
271 def perffncacheload(ui, repo):
260 s = repo.store
272 s = repo.store
261 def d():
273 def d():
262 s.fncache._load()
274 s.fncache._load()
263 timer(d)
275 timer(d)
264
276
265 @command('perffncachewrite')
277 @command('perffncachewrite')
266 def perffncachewrite(ui, repo):
278 def perffncachewrite(ui, repo):
267 s = repo.store
279 s = repo.store
268 s.fncache._load()
280 s.fncache._load()
269 def d():
281 def d():
270 s.fncache._dirty = True
282 s.fncache._dirty = True
271 s.fncache.write()
283 s.fncache.write()
272 timer(d)
284 timer(d)
273
285
274 @command('perffncacheencode')
286 @command('perffncacheencode')
275 def perffncacheencode(ui, repo):
287 def perffncacheencode(ui, repo):
276 s = repo.store
288 s = repo.store
277 s.fncache._load()
289 s.fncache._load()
278 def d():
290 def d():
279 for p in s.fncache.entries:
291 for p in s.fncache.entries:
280 s.encode(p)
292 s.encode(p)
281 timer(d)
293 timer(d)
282
294
283 @command('perfdiffwd')
295 @command('perfdiffwd')
284 def perfdiffwd(ui, repo):
296 def perfdiffwd(ui, repo):
285 """Profile diff of working directory changes"""
297 """Profile diff of working directory changes"""
286 options = {
298 options = {
287 'w': 'ignore_all_space',
299 'w': 'ignore_all_space',
288 'b': 'ignore_space_change',
300 'b': 'ignore_space_change',
289 'B': 'ignore_blank_lines',
301 'B': 'ignore_blank_lines',
290 }
302 }
291
303
292 for diffopt in ('', 'w', 'b', 'B', 'wB'):
304 for diffopt in ('', 'w', 'b', 'B', 'wB'):
293 opts = dict((options[c], '1') for c in diffopt)
305 opts = dict((options[c], '1') for c in diffopt)
294 def d():
306 def d():
295 ui.pushbuffer()
307 ui.pushbuffer()
296 commands.diff(ui, repo, **opts)
308 commands.diff(ui, repo, **opts)
297 ui.popbuffer()
309 ui.popbuffer()
298 title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
310 title = 'diffopts: %s' % (diffopt and ('-' + diffopt) or 'none')
299 timer(d, title)
311 timer(d, title)
300
312
301 @command('perfrevlog',
313 @command('perfrevlog',
302 [('d', 'dist', 100, 'distance between the revisions')],
314 [('d', 'dist', 100, 'distance between the revisions')],
303 "[INDEXFILE]")
315 "[INDEXFILE]")
304 def perfrevlog(ui, repo, file_, **opts):
316 def perfrevlog(ui, repo, file_, **opts):
305 from mercurial import revlog
317 from mercurial import revlog
306 dist = opts['dist']
318 dist = opts['dist']
307 def d():
319 def d():
308 r = revlog.revlog(lambda fn: open(fn, 'rb'), file_)
320 r = revlog.revlog(lambda fn: open(fn, 'rb'), file_)
309 for x in xrange(0, len(r), dist):
321 for x in xrange(0, len(r), dist):
310 r.revision(r.node(x))
322 r.revision(r.node(x))
311
323
312 timer(d)
324 timer(d)
313
325
314 @command('perfrevset',
326 @command('perfrevset',
315 [('C', 'clear', False, 'clear volatile cache between each call.')],
327 [('C', 'clear', False, 'clear volatile cache between each call.')],
316 "REVSET")
328 "REVSET")
317 def perfrevset(ui, repo, expr, clear=False):
329 def perfrevset(ui, repo, expr, clear=False):
318 """benchmark the execution time of a revset
330 """benchmark the execution time of a revset
319
331
320 Use the --clean option if need to evaluate the impact of build volatile
332 Use the --clean option if need to evaluate the impact of build volatile
321 revisions set cache on the revset execution. Volatile cache hold filtered
333 revisions set cache on the revset execution. Volatile cache hold filtered
322 and obsolete related cache."""
334 and obsolete related cache."""
323 def d():
335 def d():
324 if clear:
336 if clear:
325 repo.invalidatevolatilesets()
337 repo.invalidatevolatilesets()
326 repo.revs(expr)
338 repo.revs(expr)
327 timer(d)
339 timer(d)
328
340
329 @command('perfvolatilesets')
341 @command('perfvolatilesets')
330 def perfvolatilesets(ui, repo, *names):
342 def perfvolatilesets(ui, repo, *names):
331 """benchmark the computation of various volatile set
343 """benchmark the computation of various volatile set
332
344
333 Volatile set computes element related to filtering and obsolescence."""
345 Volatile set computes element related to filtering and obsolescence."""
334 repo = repo.unfiltered()
346 repo = repo.unfiltered()
335
347
336 def getobs(name):
348 def getobs(name):
337 def d():
349 def d():
338 repo.invalidatevolatilesets()
350 repo.invalidatevolatilesets()
339 obsolete.getrevs(repo, name)
351 obsolete.getrevs(repo, name)
340 return d
352 return d
341
353
342 allobs = sorted(obsolete.cachefuncs)
354 allobs = sorted(obsolete.cachefuncs)
343 if names:
355 if names:
344 allobs = [n for n in allobs if n in names]
356 allobs = [n for n in allobs if n in names]
345
357
346 for name in allobs:
358 for name in allobs:
347 timer(getobs(name), title=name)
359 timer(getobs(name), title=name)
348
360
349 def getfiltered(name):
361 def getfiltered(name):
350 def d():
362 def d():
351 repo.invalidatevolatilesets()
363 repo.invalidatevolatilesets()
352 repoview.filteredrevs(repo, name)
364 repoview.filteredrevs(repo, name)
353 return d
365 return d
354
366
355 allfilter = sorted(repoview.filtertable)
367 allfilter = sorted(repoview.filtertable)
356 if names:
368 if names:
357 allfilter = [n for n in allfilter if n in names]
369 allfilter = [n for n in allfilter if n in names]
358
370
359 for name in allfilter:
371 for name in allfilter:
360 timer(getfiltered(name), title=name)
372 timer(getfiltered(name), title=name)
361
373
362 @command('perfbranchmap',
374 @command('perfbranchmap',
363 [('f', 'full', False,
375 [('f', 'full', False,
364 'Includes build time of subset'),
376 'Includes build time of subset'),
365 ])
377 ])
366 def perfbranchmap(ui, repo, full=False):
378 def perfbranchmap(ui, repo, full=False):
367 """benchmark the update of a branchmap
379 """benchmark the update of a branchmap
368
380
369 This benchmarks the full repo.branchmap() call with read and write disabled
381 This benchmarks the full repo.branchmap() call with read and write disabled
370 """
382 """
371 def getbranchmap(filtername):
383 def getbranchmap(filtername):
372 """generate a benchmark function for the filtername"""
384 """generate a benchmark function for the filtername"""
373 if filtername is None:
385 if filtername is None:
374 view = repo
386 view = repo
375 else:
387 else:
376 view = repo.filtered(filtername)
388 view = repo.filtered(filtername)
377 def d():
389 def d():
378 if full:
390 if full:
379 view._branchcaches.clear()
391 view._branchcaches.clear()
380 else:
392 else:
381 view._branchcaches.pop(filtername, None)
393 view._branchcaches.pop(filtername, None)
382 view.branchmap()
394 view.branchmap()
383 return d
395 return d
384 # add filter in smaller subset to bigger subset
396 # add filter in smaller subset to bigger subset
385 possiblefilters = set(repoview.filtertable)
397 possiblefilters = set(repoview.filtertable)
386 allfilters = []
398 allfilters = []
387 while possiblefilters:
399 while possiblefilters:
388 for name in possiblefilters:
400 for name in possiblefilters:
389 subset = branchmap.subsettable.get(name)
401 subset = branchmap.subsettable.get(name)
390 if subset not in possiblefilters:
402 if subset not in possiblefilters:
391 break
403 break
392 else:
404 else:
393 assert False, 'subset cycle %s!' % possiblefilters
405 assert False, 'subset cycle %s!' % possiblefilters
394 allfilters.append(name)
406 allfilters.append(name)
395 possiblefilters.remove(name)
407 possiblefilters.remove(name)
396
408
397 # warm the cache
409 # warm the cache
398 if not full:
410 if not full:
399 for name in allfilters:
411 for name in allfilters:
400 repo.filtered(name).branchmap()
412 repo.filtered(name).branchmap()
401 # add unfiltered
413 # add unfiltered
402 allfilters.append(None)
414 allfilters.append(None)
403 oldread = branchmap.read
415 oldread = branchmap.read
404 oldwrite = branchmap.branchcache.write
416 oldwrite = branchmap.branchcache.write
405 try:
417 try:
406 branchmap.read = lambda repo: None
418 branchmap.read = lambda repo: None
407 branchmap.write = lambda repo: None
419 branchmap.write = lambda repo: None
408 for name in allfilters:
420 for name in allfilters:
409 timer(getbranchmap(name), title=str(name))
421 timer(getbranchmap(name), title=str(name))
410 finally:
422 finally:
411 branchmap.read = oldread
423 branchmap.read = oldread
412 branchmap.branchcache.write = oldwrite
424 branchmap.branchcache.write = oldwrite
General Comments 0
You need to be logged in to leave comments. Login now