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