##// END OF EJS Templates
perf: use `setup` function in `perfdirstatedirs`...
marmoute -
r43394:100e7e0c default
parent child Browse files
Show More
@@ -1,3760 +1,3762 b''
1 1 # perf.py - performance test routines
2 2 '''helper extension to measure performance
3 3
4 4 Configurations
5 5 ==============
6 6
7 7 ``perf``
8 8 --------
9 9
10 10 ``all-timing``
11 11 When set, additional statistics will be reported for each benchmark: best,
12 12 worst, median average. If not set only the best timing is reported
13 13 (default: off).
14 14
15 15 ``presleep``
16 16 number of second to wait before any group of runs (default: 1)
17 17
18 18 ``pre-run``
19 19 number of run to perform before starting measurement.
20 20
21 21 ``profile-benchmark``
22 22 Enable profiling for the benchmarked section.
23 23 (The first iteration is benchmarked)
24 24
25 25 ``run-limits``
26 26 Control the number of runs each benchmark will perform. The option value
27 27 should be a list of `<time>-<numberofrun>` pairs. After each run the
28 28 conditions are considered in order with the following logic:
29 29
30 30 If benchmark has been running for <time> seconds, and we have performed
31 31 <numberofrun> iterations, stop the benchmark,
32 32
33 33 The default value is: `3.0-100, 10.0-3`
34 34
35 35 ``stub``
36 36 When set, benchmarks will only be run once, useful for testing
37 37 (default: off)
38 38 '''
39 39
40 40 # "historical portability" policy of perf.py:
41 41 #
42 42 # We have to do:
43 43 # - make perf.py "loadable" with as wide Mercurial version as possible
44 44 # This doesn't mean that perf commands work correctly with that Mercurial.
45 45 # BTW, perf.py itself has been available since 1.1 (or eb240755386d).
46 46 # - make historical perf command work correctly with as wide Mercurial
47 47 # version as possible
48 48 #
49 49 # We have to do, if possible with reasonable cost:
50 50 # - make recent perf command for historical feature work correctly
51 51 # with early Mercurial
52 52 #
53 53 # We don't have to do:
54 54 # - make perf command for recent feature work correctly with early
55 55 # Mercurial
56 56
57 57 from __future__ import absolute_import
58 58 import contextlib
59 59 import functools
60 60 import gc
61 61 import os
62 62 import random
63 63 import shutil
64 64 import struct
65 65 import sys
66 66 import tempfile
67 67 import threading
68 68 import time
69 69 from mercurial import (
70 70 changegroup,
71 71 cmdutil,
72 72 commands,
73 73 copies,
74 74 error,
75 75 extensions,
76 76 hg,
77 77 mdiff,
78 78 merge,
79 79 revlog,
80 80 util,
81 81 )
82 82
83 83 # for "historical portability":
84 84 # try to import modules separately (in dict order), and ignore
85 85 # failure, because these aren't available with early Mercurial
86 86 try:
87 87 from mercurial import branchmap # since 2.5 (or bcee63733aad)
88 88 except ImportError:
89 89 pass
90 90 try:
91 91 from mercurial import obsolete # since 2.3 (or ad0d6c2b3279)
92 92 except ImportError:
93 93 pass
94 94 try:
95 95 from mercurial import registrar # since 3.7 (or 37d50250b696)
96 96
97 97 dir(registrar) # forcibly load it
98 98 except ImportError:
99 99 registrar = None
100 100 try:
101 101 from mercurial import repoview # since 2.5 (or 3a6ddacb7198)
102 102 except ImportError:
103 103 pass
104 104 try:
105 105 from mercurial.utils import repoviewutil # since 5.0
106 106 except ImportError:
107 107 repoviewutil = None
108 108 try:
109 109 from mercurial import scmutil # since 1.9 (or 8b252e826c68)
110 110 except ImportError:
111 111 pass
112 112 try:
113 113 from mercurial import setdiscovery # since 1.9 (or cb98fed52495)
114 114 except ImportError:
115 115 pass
116 116
117 117 try:
118 118 from mercurial import profiling
119 119 except ImportError:
120 120 profiling = None
121 121
122 122
123 123 def identity(a):
124 124 return a
125 125
126 126
127 127 try:
128 128 from mercurial import pycompat
129 129
130 130 getargspec = pycompat.getargspec # added to module after 4.5
131 131 _byteskwargs = pycompat.byteskwargs # since 4.1 (or fbc3f73dc802)
132 132 _sysstr = pycompat.sysstr # since 4.0 (or 2219f4f82ede)
133 133 _bytestr = pycompat.bytestr # since 4.2 (or b70407bd84d5)
134 134 _xrange = pycompat.xrange # since 4.8 (or 7eba8f83129b)
135 135 fsencode = pycompat.fsencode # since 3.9 (or f4a5e0e86a7e)
136 136 if pycompat.ispy3:
137 137 _maxint = sys.maxsize # per py3 docs for replacing maxint
138 138 else:
139 139 _maxint = sys.maxint
140 140 except (NameError, ImportError, AttributeError):
141 141 import inspect
142 142
143 143 getargspec = inspect.getargspec
144 144 _byteskwargs = identity
145 145 _bytestr = str
146 146 fsencode = identity # no py3 support
147 147 _maxint = sys.maxint # no py3 support
148 148 _sysstr = lambda x: x # no py3 support
149 149 _xrange = xrange
150 150
151 151 try:
152 152 # 4.7+
153 153 queue = pycompat.queue.Queue
154 154 except (NameError, AttributeError, ImportError):
155 155 # <4.7.
156 156 try:
157 157 queue = pycompat.queue
158 158 except (NameError, AttributeError, ImportError):
159 159 import Queue as queue
160 160
161 161 try:
162 162 from mercurial import logcmdutil
163 163
164 164 makelogtemplater = logcmdutil.maketemplater
165 165 except (AttributeError, ImportError):
166 166 try:
167 167 makelogtemplater = cmdutil.makelogtemplater
168 168 except (AttributeError, ImportError):
169 169 makelogtemplater = None
170 170
171 171 # for "historical portability":
172 172 # define util.safehasattr forcibly, because util.safehasattr has been
173 173 # available since 1.9.3 (or 94b200a11cf7)
174 174 _undefined = object()
175 175
176 176
177 177 def safehasattr(thing, attr):
178 178 return getattr(thing, _sysstr(attr), _undefined) is not _undefined
179 179
180 180
181 181 setattr(util, 'safehasattr', safehasattr)
182 182
183 183 # for "historical portability":
184 184 # define util.timer forcibly, because util.timer has been available
185 185 # since ae5d60bb70c9
186 186 if safehasattr(time, 'perf_counter'):
187 187 util.timer = time.perf_counter
188 188 elif os.name == b'nt':
189 189 util.timer = time.clock
190 190 else:
191 191 util.timer = time.time
192 192
193 193 # for "historical portability":
194 194 # use locally defined empty option list, if formatteropts isn't
195 195 # available, because commands.formatteropts has been available since
196 196 # 3.2 (or 7a7eed5176a4), even though formatting itself has been
197 197 # available since 2.2 (or ae5f92e154d3)
198 198 formatteropts = getattr(
199 199 cmdutil, "formatteropts", getattr(commands, "formatteropts", [])
200 200 )
201 201
202 202 # for "historical portability":
203 203 # use locally defined option list, if debugrevlogopts isn't available,
204 204 # because commands.debugrevlogopts has been available since 3.7 (or
205 205 # 5606f7d0d063), even though cmdutil.openrevlog() has been available
206 206 # since 1.9 (or a79fea6b3e77).
207 207 revlogopts = getattr(
208 208 cmdutil,
209 209 "debugrevlogopts",
210 210 getattr(
211 211 commands,
212 212 "debugrevlogopts",
213 213 [
214 214 (b'c', b'changelog', False, b'open changelog'),
215 215 (b'm', b'manifest', False, b'open manifest'),
216 216 (b'', b'dir', False, b'open directory manifest'),
217 217 ],
218 218 ),
219 219 )
220 220
221 221 cmdtable = {}
222 222
223 223 # for "historical portability":
224 224 # define parsealiases locally, because cmdutil.parsealiases has been
225 225 # available since 1.5 (or 6252852b4332)
226 226 def parsealiases(cmd):
227 227 return cmd.split(b"|")
228 228
229 229
230 230 if safehasattr(registrar, 'command'):
231 231 command = registrar.command(cmdtable)
232 232 elif safehasattr(cmdutil, 'command'):
233 233 command = cmdutil.command(cmdtable)
234 234 if b'norepo' not in getargspec(command).args:
235 235 # for "historical portability":
236 236 # wrap original cmdutil.command, because "norepo" option has
237 237 # been available since 3.1 (or 75a96326cecb)
238 238 _command = command
239 239
240 240 def command(name, options=(), synopsis=None, norepo=False):
241 241 if norepo:
242 242 commands.norepo += b' %s' % b' '.join(parsealiases(name))
243 243 return _command(name, list(options), synopsis)
244 244
245 245
246 246 else:
247 247 # for "historical portability":
248 248 # define "@command" annotation locally, because cmdutil.command
249 249 # has been available since 1.9 (or 2daa5179e73f)
250 250 def command(name, options=(), synopsis=None, norepo=False):
251 251 def decorator(func):
252 252 if synopsis:
253 253 cmdtable[name] = func, list(options), synopsis
254 254 else:
255 255 cmdtable[name] = func, list(options)
256 256 if norepo:
257 257 commands.norepo += b' %s' % b' '.join(parsealiases(name))
258 258 return func
259 259
260 260 return decorator
261 261
262 262
263 263 try:
264 264 import mercurial.registrar
265 265 import mercurial.configitems
266 266
267 267 configtable = {}
268 268 configitem = mercurial.registrar.configitem(configtable)
269 269 configitem(
270 270 b'perf',
271 271 b'presleep',
272 272 default=mercurial.configitems.dynamicdefault,
273 273 experimental=True,
274 274 )
275 275 configitem(
276 276 b'perf',
277 277 b'stub',
278 278 default=mercurial.configitems.dynamicdefault,
279 279 experimental=True,
280 280 )
281 281 configitem(
282 282 b'perf',
283 283 b'parentscount',
284 284 default=mercurial.configitems.dynamicdefault,
285 285 experimental=True,
286 286 )
287 287 configitem(
288 288 b'perf',
289 289 b'all-timing',
290 290 default=mercurial.configitems.dynamicdefault,
291 291 experimental=True,
292 292 )
293 293 configitem(
294 294 b'perf', b'pre-run', default=mercurial.configitems.dynamicdefault,
295 295 )
296 296 configitem(
297 297 b'perf',
298 298 b'profile-benchmark',
299 299 default=mercurial.configitems.dynamicdefault,
300 300 )
301 301 configitem(
302 302 b'perf',
303 303 b'run-limits',
304 304 default=mercurial.configitems.dynamicdefault,
305 305 experimental=True,
306 306 )
307 307 except (ImportError, AttributeError):
308 308 pass
309 309 except TypeError:
310 310 # compatibility fix for a11fd395e83f
311 311 # hg version: 5.2
312 312 configitem(
313 313 b'perf', b'presleep', default=mercurial.configitems.dynamicdefault,
314 314 )
315 315 configitem(
316 316 b'perf', b'stub', default=mercurial.configitems.dynamicdefault,
317 317 )
318 318 configitem(
319 319 b'perf', b'parentscount', default=mercurial.configitems.dynamicdefault,
320 320 )
321 321 configitem(
322 322 b'perf', b'all-timing', default=mercurial.configitems.dynamicdefault,
323 323 )
324 324 configitem(
325 325 b'perf', b'pre-run', default=mercurial.configitems.dynamicdefault,
326 326 )
327 327 configitem(
328 328 b'perf',
329 329 b'profile-benchmark',
330 330 default=mercurial.configitems.dynamicdefault,
331 331 )
332 332 configitem(
333 333 b'perf', b'run-limits', default=mercurial.configitems.dynamicdefault,
334 334 )
335 335
336 336
337 337 def getlen(ui):
338 338 if ui.configbool(b"perf", b"stub", False):
339 339 return lambda x: 1
340 340 return len
341 341
342 342
343 343 class noop(object):
344 344 """dummy context manager"""
345 345
346 346 def __enter__(self):
347 347 pass
348 348
349 349 def __exit__(self, *args):
350 350 pass
351 351
352 352
353 353 NOOPCTX = noop()
354 354
355 355
356 356 def gettimer(ui, opts=None):
357 357 """return a timer function and formatter: (timer, formatter)
358 358
359 359 This function exists to gather the creation of formatter in a single
360 360 place instead of duplicating it in all performance commands."""
361 361
362 362 # enforce an idle period before execution to counteract power management
363 363 # experimental config: perf.presleep
364 364 time.sleep(getint(ui, b"perf", b"presleep", 1))
365 365
366 366 if opts is None:
367 367 opts = {}
368 368 # redirect all to stderr unless buffer api is in use
369 369 if not ui._buffers:
370 370 ui = ui.copy()
371 371 uifout = safeattrsetter(ui, b'fout', ignoremissing=True)
372 372 if uifout:
373 373 # for "historical portability":
374 374 # ui.fout/ferr have been available since 1.9 (or 4e1ccd4c2b6d)
375 375 uifout.set(ui.ferr)
376 376
377 377 # get a formatter
378 378 uiformatter = getattr(ui, 'formatter', None)
379 379 if uiformatter:
380 380 fm = uiformatter(b'perf', opts)
381 381 else:
382 382 # for "historical portability":
383 383 # define formatter locally, because ui.formatter has been
384 384 # available since 2.2 (or ae5f92e154d3)
385 385 from mercurial import node
386 386
387 387 class defaultformatter(object):
388 388 """Minimized composition of baseformatter and plainformatter
389 389 """
390 390
391 391 def __init__(self, ui, topic, opts):
392 392 self._ui = ui
393 393 if ui.debugflag:
394 394 self.hexfunc = node.hex
395 395 else:
396 396 self.hexfunc = node.short
397 397
398 398 def __nonzero__(self):
399 399 return False
400 400
401 401 __bool__ = __nonzero__
402 402
403 403 def startitem(self):
404 404 pass
405 405
406 406 def data(self, **data):
407 407 pass
408 408
409 409 def write(self, fields, deftext, *fielddata, **opts):
410 410 self._ui.write(deftext % fielddata, **opts)
411 411
412 412 def condwrite(self, cond, fields, deftext, *fielddata, **opts):
413 413 if cond:
414 414 self._ui.write(deftext % fielddata, **opts)
415 415
416 416 def plain(self, text, **opts):
417 417 self._ui.write(text, **opts)
418 418
419 419 def end(self):
420 420 pass
421 421
422 422 fm = defaultformatter(ui, b'perf', opts)
423 423
424 424 # stub function, runs code only once instead of in a loop
425 425 # experimental config: perf.stub
426 426 if ui.configbool(b"perf", b"stub", False):
427 427 return functools.partial(stub_timer, fm), fm
428 428
429 429 # experimental config: perf.all-timing
430 430 displayall = ui.configbool(b"perf", b"all-timing", False)
431 431
432 432 # experimental config: perf.run-limits
433 433 limitspec = ui.configlist(b"perf", b"run-limits", [])
434 434 limits = []
435 435 for item in limitspec:
436 436 parts = item.split(b'-', 1)
437 437 if len(parts) < 2:
438 438 ui.warn((b'malformatted run limit entry, missing "-": %s\n' % item))
439 439 continue
440 440 try:
441 441 time_limit = float(_sysstr(parts[0]))
442 442 except ValueError as e:
443 443 ui.warn(
444 444 (
445 445 b'malformatted run limit entry, %s: %s\n'
446 446 % (_bytestr(e), item)
447 447 )
448 448 )
449 449 continue
450 450 try:
451 451 run_limit = int(_sysstr(parts[1]))
452 452 except ValueError as e:
453 453 ui.warn(
454 454 (
455 455 b'malformatted run limit entry, %s: %s\n'
456 456 % (_bytestr(e), item)
457 457 )
458 458 )
459 459 continue
460 460 limits.append((time_limit, run_limit))
461 461 if not limits:
462 462 limits = DEFAULTLIMITS
463 463
464 464 profiler = None
465 465 if profiling is not None:
466 466 if ui.configbool(b"perf", b"profile-benchmark", False):
467 467 profiler = profiling.profile(ui)
468 468
469 469 prerun = getint(ui, b"perf", b"pre-run", 0)
470 470 t = functools.partial(
471 471 _timer,
472 472 fm,
473 473 displayall=displayall,
474 474 limits=limits,
475 475 prerun=prerun,
476 476 profiler=profiler,
477 477 )
478 478 return t, fm
479 479
480 480
481 481 def stub_timer(fm, func, setup=None, title=None):
482 482 if setup is not None:
483 483 setup()
484 484 func()
485 485
486 486
487 487 @contextlib.contextmanager
488 488 def timeone():
489 489 r = []
490 490 ostart = os.times()
491 491 cstart = util.timer()
492 492 yield r
493 493 cstop = util.timer()
494 494 ostop = os.times()
495 495 a, b = ostart, ostop
496 496 r.append((cstop - cstart, b[0] - a[0], b[1] - a[1]))
497 497
498 498
499 499 # list of stop condition (elapsed time, minimal run count)
500 500 DEFAULTLIMITS = (
501 501 (3.0, 100),
502 502 (10.0, 3),
503 503 )
504 504
505 505
506 506 def _timer(
507 507 fm,
508 508 func,
509 509 setup=None,
510 510 title=None,
511 511 displayall=False,
512 512 limits=DEFAULTLIMITS,
513 513 prerun=0,
514 514 profiler=None,
515 515 ):
516 516 gc.collect()
517 517 results = []
518 518 begin = util.timer()
519 519 count = 0
520 520 if profiler is None:
521 521 profiler = NOOPCTX
522 522 for i in range(prerun):
523 523 if setup is not None:
524 524 setup()
525 525 func()
526 526 keepgoing = True
527 527 while keepgoing:
528 528 if setup is not None:
529 529 setup()
530 530 with profiler:
531 531 with timeone() as item:
532 532 r = func()
533 533 profiler = NOOPCTX
534 534 count += 1
535 535 results.append(item[0])
536 536 cstop = util.timer()
537 537 # Look for a stop condition.
538 538 elapsed = cstop - begin
539 539 for t, mincount in limits:
540 540 if elapsed >= t and count >= mincount:
541 541 keepgoing = False
542 542 break
543 543
544 544 formatone(fm, results, title=title, result=r, displayall=displayall)
545 545
546 546
547 547 def formatone(fm, timings, title=None, result=None, displayall=False):
548 548
549 549 count = len(timings)
550 550
551 551 fm.startitem()
552 552
553 553 if title:
554 554 fm.write(b'title', b'! %s\n', title)
555 555 if result:
556 556 fm.write(b'result', b'! result: %s\n', result)
557 557
558 558 def display(role, entry):
559 559 prefix = b''
560 560 if role != b'best':
561 561 prefix = b'%s.' % role
562 562 fm.plain(b'!')
563 563 fm.write(prefix + b'wall', b' wall %f', entry[0])
564 564 fm.write(prefix + b'comb', b' comb %f', entry[1] + entry[2])
565 565 fm.write(prefix + b'user', b' user %f', entry[1])
566 566 fm.write(prefix + b'sys', b' sys %f', entry[2])
567 567 fm.write(prefix + b'count', b' (%s of %%d)' % role, count)
568 568 fm.plain(b'\n')
569 569
570 570 timings.sort()
571 571 min_val = timings[0]
572 572 display(b'best', min_val)
573 573 if displayall:
574 574 max_val = timings[-1]
575 575 display(b'max', max_val)
576 576 avg = tuple([sum(x) / count for x in zip(*timings)])
577 577 display(b'avg', avg)
578 578 median = timings[len(timings) // 2]
579 579 display(b'median', median)
580 580
581 581
582 582 # utilities for historical portability
583 583
584 584
585 585 def getint(ui, section, name, default):
586 586 # for "historical portability":
587 587 # ui.configint has been available since 1.9 (or fa2b596db182)
588 588 v = ui.config(section, name, None)
589 589 if v is None:
590 590 return default
591 591 try:
592 592 return int(v)
593 593 except ValueError:
594 594 raise error.ConfigError(
595 595 b"%s.%s is not an integer ('%s')" % (section, name, v)
596 596 )
597 597
598 598
599 599 def safeattrsetter(obj, name, ignoremissing=False):
600 600 """Ensure that 'obj' has 'name' attribute before subsequent setattr
601 601
602 602 This function is aborted, if 'obj' doesn't have 'name' attribute
603 603 at runtime. This avoids overlooking removal of an attribute, which
604 604 breaks assumption of performance measurement, in the future.
605 605
606 606 This function returns the object to (1) assign a new value, and
607 607 (2) restore an original value to the attribute.
608 608
609 609 If 'ignoremissing' is true, missing 'name' attribute doesn't cause
610 610 abortion, and this function returns None. This is useful to
611 611 examine an attribute, which isn't ensured in all Mercurial
612 612 versions.
613 613 """
614 614 if not util.safehasattr(obj, name):
615 615 if ignoremissing:
616 616 return None
617 617 raise error.Abort(
618 618 (
619 619 b"missing attribute %s of %s might break assumption"
620 620 b" of performance measurement"
621 621 )
622 622 % (name, obj)
623 623 )
624 624
625 625 origvalue = getattr(obj, _sysstr(name))
626 626
627 627 class attrutil(object):
628 628 def set(self, newvalue):
629 629 setattr(obj, _sysstr(name), newvalue)
630 630
631 631 def restore(self):
632 632 setattr(obj, _sysstr(name), origvalue)
633 633
634 634 return attrutil()
635 635
636 636
637 637 # utilities to examine each internal API changes
638 638
639 639
640 640 def getbranchmapsubsettable():
641 641 # for "historical portability":
642 642 # subsettable is defined in:
643 643 # - branchmap since 2.9 (or 175c6fd8cacc)
644 644 # - repoview since 2.5 (or 59a9f18d4587)
645 645 # - repoviewutil since 5.0
646 646 for mod in (branchmap, repoview, repoviewutil):
647 647 subsettable = getattr(mod, 'subsettable', None)
648 648 if subsettable:
649 649 return subsettable
650 650
651 651 # bisecting in bcee63733aad::59a9f18d4587 can reach here (both
652 652 # branchmap and repoview modules exist, but subsettable attribute
653 653 # doesn't)
654 654 raise error.Abort(
655 655 b"perfbranchmap not available with this Mercurial",
656 656 hint=b"use 2.5 or later",
657 657 )
658 658
659 659
660 660 def getsvfs(repo):
661 661 """Return appropriate object to access files under .hg/store
662 662 """
663 663 # for "historical portability":
664 664 # repo.svfs has been available since 2.3 (or 7034365089bf)
665 665 svfs = getattr(repo, 'svfs', None)
666 666 if svfs:
667 667 return svfs
668 668 else:
669 669 return getattr(repo, 'sopener')
670 670
671 671
672 672 def getvfs(repo):
673 673 """Return appropriate object to access files under .hg
674 674 """
675 675 # for "historical portability":
676 676 # repo.vfs has been available since 2.3 (or 7034365089bf)
677 677 vfs = getattr(repo, 'vfs', None)
678 678 if vfs:
679 679 return vfs
680 680 else:
681 681 return getattr(repo, 'opener')
682 682
683 683
684 684 def repocleartagscachefunc(repo):
685 685 """Return the function to clear tags cache according to repo internal API
686 686 """
687 687 if util.safehasattr(repo, b'_tagscache'): # since 2.0 (or 9dca7653b525)
688 688 # in this case, setattr(repo, '_tagscache', None) or so isn't
689 689 # correct way to clear tags cache, because existing code paths
690 690 # expect _tagscache to be a structured object.
691 691 def clearcache():
692 692 # _tagscache has been filteredpropertycache since 2.5 (or
693 693 # 98c867ac1330), and delattr() can't work in such case
694 694 if b'_tagscache' in vars(repo):
695 695 del repo.__dict__[b'_tagscache']
696 696
697 697 return clearcache
698 698
699 699 repotags = safeattrsetter(repo, b'_tags', ignoremissing=True)
700 700 if repotags: # since 1.4 (or 5614a628d173)
701 701 return lambda: repotags.set(None)
702 702
703 703 repotagscache = safeattrsetter(repo, b'tagscache', ignoremissing=True)
704 704 if repotagscache: # since 0.6 (or d7df759d0e97)
705 705 return lambda: repotagscache.set(None)
706 706
707 707 # Mercurial earlier than 0.6 (or d7df759d0e97) logically reaches
708 708 # this point, but it isn't so problematic, because:
709 709 # - repo.tags of such Mercurial isn't "callable", and repo.tags()
710 710 # in perftags() causes failure soon
711 711 # - perf.py itself has been available since 1.1 (or eb240755386d)
712 712 raise error.Abort(b"tags API of this hg command is unknown")
713 713
714 714
715 715 # utilities to clear cache
716 716
717 717
718 718 def clearfilecache(obj, attrname):
719 719 unfiltered = getattr(obj, 'unfiltered', None)
720 720 if unfiltered is not None:
721 721 obj = obj.unfiltered()
722 722 if attrname in vars(obj):
723 723 delattr(obj, attrname)
724 724 obj._filecache.pop(attrname, None)
725 725
726 726
727 727 def clearchangelog(repo):
728 728 if repo is not repo.unfiltered():
729 729 object.__setattr__(repo, r'_clcachekey', None)
730 730 object.__setattr__(repo, r'_clcache', None)
731 731 clearfilecache(repo.unfiltered(), 'changelog')
732 732
733 733
734 734 # perf commands
735 735
736 736
737 737 @command(b'perfwalk', formatteropts)
738 738 def perfwalk(ui, repo, *pats, **opts):
739 739 opts = _byteskwargs(opts)
740 740 timer, fm = gettimer(ui, opts)
741 741 m = scmutil.match(repo[None], pats, {})
742 742 timer(
743 743 lambda: len(
744 744 list(
745 745 repo.dirstate.walk(m, subrepos=[], unknown=True, ignored=False)
746 746 )
747 747 )
748 748 )
749 749 fm.end()
750 750
751 751
752 752 @command(b'perfannotate', formatteropts)
753 753 def perfannotate(ui, repo, f, **opts):
754 754 opts = _byteskwargs(opts)
755 755 timer, fm = gettimer(ui, opts)
756 756 fc = repo[b'.'][f]
757 757 timer(lambda: len(fc.annotate(True)))
758 758 fm.end()
759 759
760 760
761 761 @command(
762 762 b'perfstatus',
763 763 [(b'u', b'unknown', False, b'ask status to look for unknown files')]
764 764 + formatteropts,
765 765 )
766 766 def perfstatus(ui, repo, **opts):
767 767 """benchmark the performance of a single status call
768 768
769 769 The repository data are preserved between each call.
770 770
771 771 By default, only the status of the tracked file are requested. If
772 772 `--unknown` is passed, the "unknown" files are also tracked.
773 773 """
774 774 opts = _byteskwargs(opts)
775 775 # m = match.always(repo.root, repo.getcwd())
776 776 # timer(lambda: sum(map(len, repo.dirstate.status(m, [], False, False,
777 777 # False))))
778 778 timer, fm = gettimer(ui, opts)
779 779 timer(lambda: sum(map(len, repo.status(unknown=opts[b'unknown']))))
780 780 fm.end()
781 781
782 782
783 783 @command(b'perfaddremove', formatteropts)
784 784 def perfaddremove(ui, repo, **opts):
785 785 opts = _byteskwargs(opts)
786 786 timer, fm = gettimer(ui, opts)
787 787 try:
788 788 oldquiet = repo.ui.quiet
789 789 repo.ui.quiet = True
790 790 matcher = scmutil.match(repo[None])
791 791 opts[b'dry_run'] = True
792 792 if b'uipathfn' in getargspec(scmutil.addremove).args:
793 793 uipathfn = scmutil.getuipathfn(repo)
794 794 timer(lambda: scmutil.addremove(repo, matcher, b"", uipathfn, opts))
795 795 else:
796 796 timer(lambda: scmutil.addremove(repo, matcher, b"", opts))
797 797 finally:
798 798 repo.ui.quiet = oldquiet
799 799 fm.end()
800 800
801 801
802 802 def clearcaches(cl):
803 803 # behave somewhat consistently across internal API changes
804 804 if util.safehasattr(cl, b'clearcaches'):
805 805 cl.clearcaches()
806 806 elif util.safehasattr(cl, b'_nodecache'):
807 807 from mercurial.node import nullid, nullrev
808 808
809 809 cl._nodecache = {nullid: nullrev}
810 810 cl._nodepos = None
811 811
812 812
813 813 @command(b'perfheads', formatteropts)
814 814 def perfheads(ui, repo, **opts):
815 815 """benchmark the computation of a changelog heads"""
816 816 opts = _byteskwargs(opts)
817 817 timer, fm = gettimer(ui, opts)
818 818 cl = repo.changelog
819 819
820 820 def s():
821 821 clearcaches(cl)
822 822
823 823 def d():
824 824 len(cl.headrevs())
825 825
826 826 timer(d, setup=s)
827 827 fm.end()
828 828
829 829
830 830 @command(
831 831 b'perftags',
832 832 formatteropts
833 833 + [(b'', b'clear-revlogs', False, b'refresh changelog and manifest'),],
834 834 )
835 835 def perftags(ui, repo, **opts):
836 836 opts = _byteskwargs(opts)
837 837 timer, fm = gettimer(ui, opts)
838 838 repocleartagscache = repocleartagscachefunc(repo)
839 839 clearrevlogs = opts[b'clear_revlogs']
840 840
841 841 def s():
842 842 if clearrevlogs:
843 843 clearchangelog(repo)
844 844 clearfilecache(repo.unfiltered(), 'manifest')
845 845 repocleartagscache()
846 846
847 847 def t():
848 848 return len(repo.tags())
849 849
850 850 timer(t, setup=s)
851 851 fm.end()
852 852
853 853
854 854 @command(b'perfancestors', formatteropts)
855 855 def perfancestors(ui, repo, **opts):
856 856 opts = _byteskwargs(opts)
857 857 timer, fm = gettimer(ui, opts)
858 858 heads = repo.changelog.headrevs()
859 859
860 860 def d():
861 861 for a in repo.changelog.ancestors(heads):
862 862 pass
863 863
864 864 timer(d)
865 865 fm.end()
866 866
867 867
868 868 @command(b'perfancestorset', formatteropts)
869 869 def perfancestorset(ui, repo, revset, **opts):
870 870 opts = _byteskwargs(opts)
871 871 timer, fm = gettimer(ui, opts)
872 872 revs = repo.revs(revset)
873 873 heads = repo.changelog.headrevs()
874 874
875 875 def d():
876 876 s = repo.changelog.ancestors(heads)
877 877 for rev in revs:
878 878 rev in s
879 879
880 880 timer(d)
881 881 fm.end()
882 882
883 883
884 884 @command(b'perfdiscovery', formatteropts, b'PATH')
885 885 def perfdiscovery(ui, repo, path, **opts):
886 886 """benchmark discovery between local repo and the peer at given path
887 887 """
888 888 repos = [repo, None]
889 889 timer, fm = gettimer(ui, opts)
890 890 path = ui.expandpath(path)
891 891
892 892 def s():
893 893 repos[1] = hg.peer(ui, opts, path)
894 894
895 895 def d():
896 896 setdiscovery.findcommonheads(ui, *repos)
897 897
898 898 timer(d, setup=s)
899 899 fm.end()
900 900
901 901
902 902 @command(
903 903 b'perfbookmarks',
904 904 formatteropts
905 905 + [(b'', b'clear-revlogs', False, b'refresh changelog and manifest'),],
906 906 )
907 907 def perfbookmarks(ui, repo, **opts):
908 908 """benchmark parsing bookmarks from disk to memory"""
909 909 opts = _byteskwargs(opts)
910 910 timer, fm = gettimer(ui, opts)
911 911
912 912 clearrevlogs = opts[b'clear_revlogs']
913 913
914 914 def s():
915 915 if clearrevlogs:
916 916 clearchangelog(repo)
917 917 clearfilecache(repo, b'_bookmarks')
918 918
919 919 def d():
920 920 repo._bookmarks
921 921
922 922 timer(d, setup=s)
923 923 fm.end()
924 924
925 925
926 926 @command(b'perfbundleread', formatteropts, b'BUNDLE')
927 927 def perfbundleread(ui, repo, bundlepath, **opts):
928 928 """Benchmark reading of bundle files.
929 929
930 930 This command is meant to isolate the I/O part of bundle reading as
931 931 much as possible.
932 932 """
933 933 from mercurial import (
934 934 bundle2,
935 935 exchange,
936 936 streamclone,
937 937 )
938 938
939 939 opts = _byteskwargs(opts)
940 940
941 941 def makebench(fn):
942 942 def run():
943 943 with open(bundlepath, b'rb') as fh:
944 944 bundle = exchange.readbundle(ui, fh, bundlepath)
945 945 fn(bundle)
946 946
947 947 return run
948 948
949 949 def makereadnbytes(size):
950 950 def run():
951 951 with open(bundlepath, b'rb') as fh:
952 952 bundle = exchange.readbundle(ui, fh, bundlepath)
953 953 while bundle.read(size):
954 954 pass
955 955
956 956 return run
957 957
958 958 def makestdioread(size):
959 959 def run():
960 960 with open(bundlepath, b'rb') as fh:
961 961 while fh.read(size):
962 962 pass
963 963
964 964 return run
965 965
966 966 # bundle1
967 967
968 968 def deltaiter(bundle):
969 969 for delta in bundle.deltaiter():
970 970 pass
971 971
972 972 def iterchunks(bundle):
973 973 for chunk in bundle.getchunks():
974 974 pass
975 975
976 976 # bundle2
977 977
978 978 def forwardchunks(bundle):
979 979 for chunk in bundle._forwardchunks():
980 980 pass
981 981
982 982 def iterparts(bundle):
983 983 for part in bundle.iterparts():
984 984 pass
985 985
986 986 def iterpartsseekable(bundle):
987 987 for part in bundle.iterparts(seekable=True):
988 988 pass
989 989
990 990 def seek(bundle):
991 991 for part in bundle.iterparts(seekable=True):
992 992 part.seek(0, os.SEEK_END)
993 993
994 994 def makepartreadnbytes(size):
995 995 def run():
996 996 with open(bundlepath, b'rb') as fh:
997 997 bundle = exchange.readbundle(ui, fh, bundlepath)
998 998 for part in bundle.iterparts():
999 999 while part.read(size):
1000 1000 pass
1001 1001
1002 1002 return run
1003 1003
1004 1004 benches = [
1005 1005 (makestdioread(8192), b'read(8k)'),
1006 1006 (makestdioread(16384), b'read(16k)'),
1007 1007 (makestdioread(32768), b'read(32k)'),
1008 1008 (makestdioread(131072), b'read(128k)'),
1009 1009 ]
1010 1010
1011 1011 with open(bundlepath, b'rb') as fh:
1012 1012 bundle = exchange.readbundle(ui, fh, bundlepath)
1013 1013
1014 1014 if isinstance(bundle, changegroup.cg1unpacker):
1015 1015 benches.extend(
1016 1016 [
1017 1017 (makebench(deltaiter), b'cg1 deltaiter()'),
1018 1018 (makebench(iterchunks), b'cg1 getchunks()'),
1019 1019 (makereadnbytes(8192), b'cg1 read(8k)'),
1020 1020 (makereadnbytes(16384), b'cg1 read(16k)'),
1021 1021 (makereadnbytes(32768), b'cg1 read(32k)'),
1022 1022 (makereadnbytes(131072), b'cg1 read(128k)'),
1023 1023 ]
1024 1024 )
1025 1025 elif isinstance(bundle, bundle2.unbundle20):
1026 1026 benches.extend(
1027 1027 [
1028 1028 (makebench(forwardchunks), b'bundle2 forwardchunks()'),
1029 1029 (makebench(iterparts), b'bundle2 iterparts()'),
1030 1030 (
1031 1031 makebench(iterpartsseekable),
1032 1032 b'bundle2 iterparts() seekable',
1033 1033 ),
1034 1034 (makebench(seek), b'bundle2 part seek()'),
1035 1035 (makepartreadnbytes(8192), b'bundle2 part read(8k)'),
1036 1036 (makepartreadnbytes(16384), b'bundle2 part read(16k)'),
1037 1037 (makepartreadnbytes(32768), b'bundle2 part read(32k)'),
1038 1038 (makepartreadnbytes(131072), b'bundle2 part read(128k)'),
1039 1039 ]
1040 1040 )
1041 1041 elif isinstance(bundle, streamclone.streamcloneapplier):
1042 1042 raise error.Abort(b'stream clone bundles not supported')
1043 1043 else:
1044 1044 raise error.Abort(b'unhandled bundle type: %s' % type(bundle))
1045 1045
1046 1046 for fn, title in benches:
1047 1047 timer, fm = gettimer(ui, opts)
1048 1048 timer(fn, title=title)
1049 1049 fm.end()
1050 1050
1051 1051
1052 1052 @command(
1053 1053 b'perfchangegroupchangelog',
1054 1054 formatteropts
1055 1055 + [
1056 1056 (b'', b'cgversion', b'02', b'changegroup version'),
1057 1057 (b'r', b'rev', b'', b'revisions to add to changegroup'),
1058 1058 ],
1059 1059 )
1060 1060 def perfchangegroupchangelog(ui, repo, cgversion=b'02', rev=None, **opts):
1061 1061 """Benchmark producing a changelog group for a changegroup.
1062 1062
1063 1063 This measures the time spent processing the changelog during a
1064 1064 bundle operation. This occurs during `hg bundle` and on a server
1065 1065 processing a `getbundle` wire protocol request (handles clones
1066 1066 and pull requests).
1067 1067
1068 1068 By default, all revisions are added to the changegroup.
1069 1069 """
1070 1070 opts = _byteskwargs(opts)
1071 1071 cl = repo.changelog
1072 1072 nodes = [cl.lookup(r) for r in repo.revs(rev or b'all()')]
1073 1073 bundler = changegroup.getbundler(cgversion, repo)
1074 1074
1075 1075 def d():
1076 1076 state, chunks = bundler._generatechangelog(cl, nodes)
1077 1077 for chunk in chunks:
1078 1078 pass
1079 1079
1080 1080 timer, fm = gettimer(ui, opts)
1081 1081
1082 1082 # Terminal printing can interfere with timing. So disable it.
1083 1083 with ui.configoverride({(b'progress', b'disable'): True}):
1084 1084 timer(d)
1085 1085
1086 1086 fm.end()
1087 1087
1088 1088
1089 1089 @command(b'perfdirs', formatteropts)
1090 1090 def perfdirs(ui, repo, **opts):
1091 1091 opts = _byteskwargs(opts)
1092 1092 timer, fm = gettimer(ui, opts)
1093 1093 dirstate = repo.dirstate
1094 1094 b'a' in dirstate
1095 1095
1096 1096 def d():
1097 1097 dirstate.hasdir(b'a')
1098 1098 del dirstate._map._dirs
1099 1099
1100 1100 timer(d)
1101 1101 fm.end()
1102 1102
1103 1103
1104 1104 @command(b'perfdirstate', formatteropts)
1105 1105 def perfdirstate(ui, repo, **opts):
1106 1106 """benchmap the time necessary to load a dirstate from scratch
1107 1107
1108 1108 The dirstate is loaded to the point were a "contains" request can be
1109 1109 answered.
1110 1110 """
1111 1111 opts = _byteskwargs(opts)
1112 1112 timer, fm = gettimer(ui, opts)
1113 1113 b"a" in repo.dirstate
1114 1114
1115 1115 def setup():
1116 1116 repo.dirstate.invalidate()
1117 1117
1118 1118 def d():
1119 1119 b"a" in repo.dirstate
1120 1120
1121 1121 timer(d, setup=setup)
1122 1122 fm.end()
1123 1123
1124 1124
1125 1125 @command(b'perfdirstatedirs', formatteropts)
1126 1126 def perfdirstatedirs(ui, repo, **opts):
1127 1127 """benchmap a 'dirstate.hasdir' call from an empty `dirs` cache
1128 1128 """
1129 1129 opts = _byteskwargs(opts)
1130 1130 timer, fm = gettimer(ui, opts)
1131 b"a" in repo.dirstate
1131 repo.dirstate.hasdir(b"a")
1132
1133 def setup():
1134 del repo.dirstate._map._dirs
1132 1135
1133 1136 def d():
1134 1137 repo.dirstate.hasdir(b"a")
1135 del repo.dirstate._map._dirs
1136
1137 timer(d)
1138
1139 timer(d, setup=setup)
1138 1140 fm.end()
1139 1141
1140 1142
1141 1143 @command(b'perfdirstatefoldmap', formatteropts)
1142 1144 def perfdirstatefoldmap(ui, repo, **opts):
1143 1145 opts = _byteskwargs(opts)
1144 1146 timer, fm = gettimer(ui, opts)
1145 1147 dirstate = repo.dirstate
1146 1148 b'a' in dirstate
1147 1149
1148 1150 def d():
1149 1151 dirstate._map.filefoldmap.get(b'a')
1150 1152 del dirstate._map.filefoldmap
1151 1153
1152 1154 timer(d)
1153 1155 fm.end()
1154 1156
1155 1157
1156 1158 @command(b'perfdirfoldmap', formatteropts)
1157 1159 def perfdirfoldmap(ui, repo, **opts):
1158 1160 opts = _byteskwargs(opts)
1159 1161 timer, fm = gettimer(ui, opts)
1160 1162 dirstate = repo.dirstate
1161 1163 b'a' in dirstate
1162 1164
1163 1165 def d():
1164 1166 dirstate._map.dirfoldmap.get(b'a')
1165 1167 del dirstate._map.dirfoldmap
1166 1168 del dirstate._map._dirs
1167 1169
1168 1170 timer(d)
1169 1171 fm.end()
1170 1172
1171 1173
1172 1174 @command(b'perfdirstatewrite', formatteropts)
1173 1175 def perfdirstatewrite(ui, repo, **opts):
1174 1176 opts = _byteskwargs(opts)
1175 1177 timer, fm = gettimer(ui, opts)
1176 1178 ds = repo.dirstate
1177 1179 b"a" in ds
1178 1180
1179 1181 def d():
1180 1182 ds._dirty = True
1181 1183 ds.write(repo.currenttransaction())
1182 1184
1183 1185 timer(d)
1184 1186 fm.end()
1185 1187
1186 1188
1187 1189 def _getmergerevs(repo, opts):
1188 1190 """parse command argument to return rev involved in merge
1189 1191
1190 1192 input: options dictionnary with `rev`, `from` and `bse`
1191 1193 output: (localctx, otherctx, basectx)
1192 1194 """
1193 1195 if opts[b'from']:
1194 1196 fromrev = scmutil.revsingle(repo, opts[b'from'])
1195 1197 wctx = repo[fromrev]
1196 1198 else:
1197 1199 wctx = repo[None]
1198 1200 # we don't want working dir files to be stat'd in the benchmark, so
1199 1201 # prime that cache
1200 1202 wctx.dirty()
1201 1203 rctx = scmutil.revsingle(repo, opts[b'rev'], opts[b'rev'])
1202 1204 if opts[b'base']:
1203 1205 fromrev = scmutil.revsingle(repo, opts[b'base'])
1204 1206 ancestor = repo[fromrev]
1205 1207 else:
1206 1208 ancestor = wctx.ancestor(rctx)
1207 1209 return (wctx, rctx, ancestor)
1208 1210
1209 1211
1210 1212 @command(
1211 1213 b'perfmergecalculate',
1212 1214 [
1213 1215 (b'r', b'rev', b'.', b'rev to merge against'),
1214 1216 (b'', b'from', b'', b'rev to merge from'),
1215 1217 (b'', b'base', b'', b'the revision to use as base'),
1216 1218 ]
1217 1219 + formatteropts,
1218 1220 )
1219 1221 def perfmergecalculate(ui, repo, **opts):
1220 1222 opts = _byteskwargs(opts)
1221 1223 timer, fm = gettimer(ui, opts)
1222 1224
1223 1225 wctx, rctx, ancestor = _getmergerevs(repo, opts)
1224 1226
1225 1227 def d():
1226 1228 # acceptremote is True because we don't want prompts in the middle of
1227 1229 # our benchmark
1228 1230 merge.calculateupdates(
1229 1231 repo,
1230 1232 wctx,
1231 1233 rctx,
1232 1234 [ancestor],
1233 1235 branchmerge=False,
1234 1236 force=False,
1235 1237 acceptremote=True,
1236 1238 followcopies=True,
1237 1239 )
1238 1240
1239 1241 timer(d)
1240 1242 fm.end()
1241 1243
1242 1244
1243 1245 @command(
1244 1246 b'perfmergecopies',
1245 1247 [
1246 1248 (b'r', b'rev', b'.', b'rev to merge against'),
1247 1249 (b'', b'from', b'', b'rev to merge from'),
1248 1250 (b'', b'base', b'', b'the revision to use as base'),
1249 1251 ]
1250 1252 + formatteropts,
1251 1253 )
1252 1254 def perfmergecopies(ui, repo, **opts):
1253 1255 """measure runtime of `copies.mergecopies`"""
1254 1256 opts = _byteskwargs(opts)
1255 1257 timer, fm = gettimer(ui, opts)
1256 1258 wctx, rctx, ancestor = _getmergerevs(repo, opts)
1257 1259
1258 1260 def d():
1259 1261 # acceptremote is True because we don't want prompts in the middle of
1260 1262 # our benchmark
1261 1263 copies.mergecopies(repo, wctx, rctx, ancestor)
1262 1264
1263 1265 timer(d)
1264 1266 fm.end()
1265 1267
1266 1268
1267 1269 @command(b'perfpathcopies', [], b"REV REV")
1268 1270 def perfpathcopies(ui, repo, rev1, rev2, **opts):
1269 1271 """benchmark the copy tracing logic"""
1270 1272 opts = _byteskwargs(opts)
1271 1273 timer, fm = gettimer(ui, opts)
1272 1274 ctx1 = scmutil.revsingle(repo, rev1, rev1)
1273 1275 ctx2 = scmutil.revsingle(repo, rev2, rev2)
1274 1276
1275 1277 def d():
1276 1278 copies.pathcopies(ctx1, ctx2)
1277 1279
1278 1280 timer(d)
1279 1281 fm.end()
1280 1282
1281 1283
1282 1284 @command(
1283 1285 b'perfphases',
1284 1286 [(b'', b'full', False, b'include file reading time too'),],
1285 1287 b"",
1286 1288 )
1287 1289 def perfphases(ui, repo, **opts):
1288 1290 """benchmark phasesets computation"""
1289 1291 opts = _byteskwargs(opts)
1290 1292 timer, fm = gettimer(ui, opts)
1291 1293 _phases = repo._phasecache
1292 1294 full = opts.get(b'full')
1293 1295
1294 1296 def d():
1295 1297 phases = _phases
1296 1298 if full:
1297 1299 clearfilecache(repo, b'_phasecache')
1298 1300 phases = repo._phasecache
1299 1301 phases.invalidate()
1300 1302 phases.loadphaserevs(repo)
1301 1303
1302 1304 timer(d)
1303 1305 fm.end()
1304 1306
1305 1307
1306 1308 @command(b'perfphasesremote', [], b"[DEST]")
1307 1309 def perfphasesremote(ui, repo, dest=None, **opts):
1308 1310 """benchmark time needed to analyse phases of the remote server"""
1309 1311 from mercurial.node import bin
1310 1312 from mercurial import (
1311 1313 exchange,
1312 1314 hg,
1313 1315 phases,
1314 1316 )
1315 1317
1316 1318 opts = _byteskwargs(opts)
1317 1319 timer, fm = gettimer(ui, opts)
1318 1320
1319 1321 path = ui.paths.getpath(dest, default=(b'default-push', b'default'))
1320 1322 if not path:
1321 1323 raise error.Abort(
1322 1324 b'default repository not configured!',
1323 1325 hint=b"see 'hg help config.paths'",
1324 1326 )
1325 1327 dest = path.pushloc or path.loc
1326 1328 ui.statusnoi18n(b'analysing phase of %s\n' % util.hidepassword(dest))
1327 1329 other = hg.peer(repo, opts, dest)
1328 1330
1329 1331 # easier to perform discovery through the operation
1330 1332 op = exchange.pushoperation(repo, other)
1331 1333 exchange._pushdiscoverychangeset(op)
1332 1334
1333 1335 remotesubset = op.fallbackheads
1334 1336
1335 1337 with other.commandexecutor() as e:
1336 1338 remotephases = e.callcommand(
1337 1339 b'listkeys', {b'namespace': b'phases'}
1338 1340 ).result()
1339 1341 del other
1340 1342 publishing = remotephases.get(b'publishing', False)
1341 1343 if publishing:
1342 1344 ui.statusnoi18n(b'publishing: yes\n')
1343 1345 else:
1344 1346 ui.statusnoi18n(b'publishing: no\n')
1345 1347
1346 1348 nodemap = repo.changelog.nodemap
1347 1349 nonpublishroots = 0
1348 1350 for nhex, phase in remotephases.iteritems():
1349 1351 if nhex == b'publishing': # ignore data related to publish option
1350 1352 continue
1351 1353 node = bin(nhex)
1352 1354 if node in nodemap and int(phase):
1353 1355 nonpublishroots += 1
1354 1356 ui.statusnoi18n(b'number of roots: %d\n' % len(remotephases))
1355 1357 ui.statusnoi18n(b'number of known non public roots: %d\n' % nonpublishroots)
1356 1358
1357 1359 def d():
1358 1360 phases.remotephasessummary(repo, remotesubset, remotephases)
1359 1361
1360 1362 timer(d)
1361 1363 fm.end()
1362 1364
1363 1365
1364 1366 @command(
1365 1367 b'perfmanifest',
1366 1368 [
1367 1369 (b'm', b'manifest-rev', False, b'Look up a manifest node revision'),
1368 1370 (b'', b'clear-disk', False, b'clear on-disk caches too'),
1369 1371 ]
1370 1372 + formatteropts,
1371 1373 b'REV|NODE',
1372 1374 )
1373 1375 def perfmanifest(ui, repo, rev, manifest_rev=False, clear_disk=False, **opts):
1374 1376 """benchmark the time to read a manifest from disk and return a usable
1375 1377 dict-like object
1376 1378
1377 1379 Manifest caches are cleared before retrieval."""
1378 1380 opts = _byteskwargs(opts)
1379 1381 timer, fm = gettimer(ui, opts)
1380 1382 if not manifest_rev:
1381 1383 ctx = scmutil.revsingle(repo, rev, rev)
1382 1384 t = ctx.manifestnode()
1383 1385 else:
1384 1386 from mercurial.node import bin
1385 1387
1386 1388 if len(rev) == 40:
1387 1389 t = bin(rev)
1388 1390 else:
1389 1391 try:
1390 1392 rev = int(rev)
1391 1393
1392 1394 if util.safehasattr(repo.manifestlog, b'getstorage'):
1393 1395 t = repo.manifestlog.getstorage(b'').node(rev)
1394 1396 else:
1395 1397 t = repo.manifestlog._revlog.lookup(rev)
1396 1398 except ValueError:
1397 1399 raise error.Abort(
1398 1400 b'manifest revision must be integer or full node'
1399 1401 )
1400 1402
1401 1403 def d():
1402 1404 repo.manifestlog.clearcaches(clear_persisted_data=clear_disk)
1403 1405 repo.manifestlog[t].read()
1404 1406
1405 1407 timer(d)
1406 1408 fm.end()
1407 1409
1408 1410
1409 1411 @command(b'perfchangeset', formatteropts)
1410 1412 def perfchangeset(ui, repo, rev, **opts):
1411 1413 opts = _byteskwargs(opts)
1412 1414 timer, fm = gettimer(ui, opts)
1413 1415 n = scmutil.revsingle(repo, rev).node()
1414 1416
1415 1417 def d():
1416 1418 repo.changelog.read(n)
1417 1419 # repo.changelog._cache = None
1418 1420
1419 1421 timer(d)
1420 1422 fm.end()
1421 1423
1422 1424
1423 1425 @command(b'perfignore', formatteropts)
1424 1426 def perfignore(ui, repo, **opts):
1425 1427 """benchmark operation related to computing ignore"""
1426 1428 opts = _byteskwargs(opts)
1427 1429 timer, fm = gettimer(ui, opts)
1428 1430 dirstate = repo.dirstate
1429 1431
1430 1432 def setupone():
1431 1433 dirstate.invalidate()
1432 1434 clearfilecache(dirstate, b'_ignore')
1433 1435
1434 1436 def runone():
1435 1437 dirstate._ignore
1436 1438
1437 1439 timer(runone, setup=setupone, title=b"load")
1438 1440 fm.end()
1439 1441
1440 1442
1441 1443 @command(
1442 1444 b'perfindex',
1443 1445 [
1444 1446 (b'', b'rev', [], b'revision to be looked up (default tip)'),
1445 1447 (b'', b'no-lookup', None, b'do not revision lookup post creation'),
1446 1448 ]
1447 1449 + formatteropts,
1448 1450 )
1449 1451 def perfindex(ui, repo, **opts):
1450 1452 """benchmark index creation time followed by a lookup
1451 1453
1452 1454 The default is to look `tip` up. Depending on the index implementation,
1453 1455 the revision looked up can matters. For example, an implementation
1454 1456 scanning the index will have a faster lookup time for `--rev tip` than for
1455 1457 `--rev 0`. The number of looked up revisions and their order can also
1456 1458 matters.
1457 1459
1458 1460 Example of useful set to test:
1459 1461 * tip
1460 1462 * 0
1461 1463 * -10:
1462 1464 * :10
1463 1465 * -10: + :10
1464 1466 * :10: + -10:
1465 1467 * -10000:
1466 1468 * -10000: + 0
1467 1469
1468 1470 It is not currently possible to check for lookup of a missing node. For
1469 1471 deeper lookup benchmarking, checkout the `perfnodemap` command."""
1470 1472 import mercurial.revlog
1471 1473
1472 1474 opts = _byteskwargs(opts)
1473 1475 timer, fm = gettimer(ui, opts)
1474 1476 mercurial.revlog._prereadsize = 2 ** 24 # disable lazy parser in old hg
1475 1477 if opts[b'no_lookup']:
1476 1478 if opts['rev']:
1477 1479 raise error.Abort('--no-lookup and --rev are mutually exclusive')
1478 1480 nodes = []
1479 1481 elif not opts[b'rev']:
1480 1482 nodes = [repo[b"tip"].node()]
1481 1483 else:
1482 1484 revs = scmutil.revrange(repo, opts[b'rev'])
1483 1485 cl = repo.changelog
1484 1486 nodes = [cl.node(r) for r in revs]
1485 1487
1486 1488 unfi = repo.unfiltered()
1487 1489 # find the filecache func directly
1488 1490 # This avoid polluting the benchmark with the filecache logic
1489 1491 makecl = unfi.__class__.changelog.func
1490 1492
1491 1493 def setup():
1492 1494 # probably not necessary, but for good measure
1493 1495 clearchangelog(unfi)
1494 1496
1495 1497 def d():
1496 1498 cl = makecl(unfi)
1497 1499 for n in nodes:
1498 1500 cl.rev(n)
1499 1501
1500 1502 timer(d, setup=setup)
1501 1503 fm.end()
1502 1504
1503 1505
1504 1506 @command(
1505 1507 b'perfnodemap',
1506 1508 [
1507 1509 (b'', b'rev', [], b'revision to be looked up (default tip)'),
1508 1510 (b'', b'clear-caches', True, b'clear revlog cache between calls'),
1509 1511 ]
1510 1512 + formatteropts,
1511 1513 )
1512 1514 def perfnodemap(ui, repo, **opts):
1513 1515 """benchmark the time necessary to look up revision from a cold nodemap
1514 1516
1515 1517 Depending on the implementation, the amount and order of revision we look
1516 1518 up can varies. Example of useful set to test:
1517 1519 * tip
1518 1520 * 0
1519 1521 * -10:
1520 1522 * :10
1521 1523 * -10: + :10
1522 1524 * :10: + -10:
1523 1525 * -10000:
1524 1526 * -10000: + 0
1525 1527
1526 1528 The command currently focus on valid binary lookup. Benchmarking for
1527 1529 hexlookup, prefix lookup and missing lookup would also be valuable.
1528 1530 """
1529 1531 import mercurial.revlog
1530 1532
1531 1533 opts = _byteskwargs(opts)
1532 1534 timer, fm = gettimer(ui, opts)
1533 1535 mercurial.revlog._prereadsize = 2 ** 24 # disable lazy parser in old hg
1534 1536
1535 1537 unfi = repo.unfiltered()
1536 1538 clearcaches = opts['clear_caches']
1537 1539 # find the filecache func directly
1538 1540 # This avoid polluting the benchmark with the filecache logic
1539 1541 makecl = unfi.__class__.changelog.func
1540 1542 if not opts[b'rev']:
1541 1543 raise error.Abort('use --rev to specify revisions to look up')
1542 1544 revs = scmutil.revrange(repo, opts[b'rev'])
1543 1545 cl = repo.changelog
1544 1546 nodes = [cl.node(r) for r in revs]
1545 1547
1546 1548 # use a list to pass reference to a nodemap from one closure to the next
1547 1549 nodeget = [None]
1548 1550
1549 1551 def setnodeget():
1550 1552 # probably not necessary, but for good measure
1551 1553 clearchangelog(unfi)
1552 1554 nodeget[0] = makecl(unfi).nodemap.get
1553 1555
1554 1556 def d():
1555 1557 get = nodeget[0]
1556 1558 for n in nodes:
1557 1559 get(n)
1558 1560
1559 1561 setup = None
1560 1562 if clearcaches:
1561 1563
1562 1564 def setup():
1563 1565 setnodeget()
1564 1566
1565 1567 else:
1566 1568 setnodeget()
1567 1569 d() # prewarm the data structure
1568 1570 timer(d, setup=setup)
1569 1571 fm.end()
1570 1572
1571 1573
1572 1574 @command(b'perfstartup', formatteropts)
1573 1575 def perfstartup(ui, repo, **opts):
1574 1576 opts = _byteskwargs(opts)
1575 1577 timer, fm = gettimer(ui, opts)
1576 1578
1577 1579 def d():
1578 1580 if os.name != r'nt':
1579 1581 os.system(
1580 1582 b"HGRCPATH= %s version -q > /dev/null" % fsencode(sys.argv[0])
1581 1583 )
1582 1584 else:
1583 1585 os.environ[r'HGRCPATH'] = r' '
1584 1586 os.system(r"%s version -q > NUL" % sys.argv[0])
1585 1587
1586 1588 timer(d)
1587 1589 fm.end()
1588 1590
1589 1591
1590 1592 @command(b'perfparents', formatteropts)
1591 1593 def perfparents(ui, repo, **opts):
1592 1594 """benchmark the time necessary to fetch one changeset's parents.
1593 1595
1594 1596 The fetch is done using the `node identifier`, traversing all object layers
1595 1597 from the repository object. The first N revisions will be used for this
1596 1598 benchmark. N is controlled by the ``perf.parentscount`` config option
1597 1599 (default: 1000).
1598 1600 """
1599 1601 opts = _byteskwargs(opts)
1600 1602 timer, fm = gettimer(ui, opts)
1601 1603 # control the number of commits perfparents iterates over
1602 1604 # experimental config: perf.parentscount
1603 1605 count = getint(ui, b"perf", b"parentscount", 1000)
1604 1606 if len(repo.changelog) < count:
1605 1607 raise error.Abort(b"repo needs %d commits for this test" % count)
1606 1608 repo = repo.unfiltered()
1607 1609 nl = [repo.changelog.node(i) for i in _xrange(count)]
1608 1610
1609 1611 def d():
1610 1612 for n in nl:
1611 1613 repo.changelog.parents(n)
1612 1614
1613 1615 timer(d)
1614 1616 fm.end()
1615 1617
1616 1618
1617 1619 @command(b'perfctxfiles', formatteropts)
1618 1620 def perfctxfiles(ui, repo, x, **opts):
1619 1621 opts = _byteskwargs(opts)
1620 1622 x = int(x)
1621 1623 timer, fm = gettimer(ui, opts)
1622 1624
1623 1625 def d():
1624 1626 len(repo[x].files())
1625 1627
1626 1628 timer(d)
1627 1629 fm.end()
1628 1630
1629 1631
1630 1632 @command(b'perfrawfiles', formatteropts)
1631 1633 def perfrawfiles(ui, repo, x, **opts):
1632 1634 opts = _byteskwargs(opts)
1633 1635 x = int(x)
1634 1636 timer, fm = gettimer(ui, opts)
1635 1637 cl = repo.changelog
1636 1638
1637 1639 def d():
1638 1640 len(cl.read(x)[3])
1639 1641
1640 1642 timer(d)
1641 1643 fm.end()
1642 1644
1643 1645
1644 1646 @command(b'perflookup', formatteropts)
1645 1647 def perflookup(ui, repo, rev, **opts):
1646 1648 opts = _byteskwargs(opts)
1647 1649 timer, fm = gettimer(ui, opts)
1648 1650 timer(lambda: len(repo.lookup(rev)))
1649 1651 fm.end()
1650 1652
1651 1653
1652 1654 @command(
1653 1655 b'perflinelogedits',
1654 1656 [
1655 1657 (b'n', b'edits', 10000, b'number of edits'),
1656 1658 (b'', b'max-hunk-lines', 10, b'max lines in a hunk'),
1657 1659 ],
1658 1660 norepo=True,
1659 1661 )
1660 1662 def perflinelogedits(ui, **opts):
1661 1663 from mercurial import linelog
1662 1664
1663 1665 opts = _byteskwargs(opts)
1664 1666
1665 1667 edits = opts[b'edits']
1666 1668 maxhunklines = opts[b'max_hunk_lines']
1667 1669
1668 1670 maxb1 = 100000
1669 1671 random.seed(0)
1670 1672 randint = random.randint
1671 1673 currentlines = 0
1672 1674 arglist = []
1673 1675 for rev in _xrange(edits):
1674 1676 a1 = randint(0, currentlines)
1675 1677 a2 = randint(a1, min(currentlines, a1 + maxhunklines))
1676 1678 b1 = randint(0, maxb1)
1677 1679 b2 = randint(b1, b1 + maxhunklines)
1678 1680 currentlines += (b2 - b1) - (a2 - a1)
1679 1681 arglist.append((rev, a1, a2, b1, b2))
1680 1682
1681 1683 def d():
1682 1684 ll = linelog.linelog()
1683 1685 for args in arglist:
1684 1686 ll.replacelines(*args)
1685 1687
1686 1688 timer, fm = gettimer(ui, opts)
1687 1689 timer(d)
1688 1690 fm.end()
1689 1691
1690 1692
1691 1693 @command(b'perfrevrange', formatteropts)
1692 1694 def perfrevrange(ui, repo, *specs, **opts):
1693 1695 opts = _byteskwargs(opts)
1694 1696 timer, fm = gettimer(ui, opts)
1695 1697 revrange = scmutil.revrange
1696 1698 timer(lambda: len(revrange(repo, specs)))
1697 1699 fm.end()
1698 1700
1699 1701
1700 1702 @command(b'perfnodelookup', formatteropts)
1701 1703 def perfnodelookup(ui, repo, rev, **opts):
1702 1704 opts = _byteskwargs(opts)
1703 1705 timer, fm = gettimer(ui, opts)
1704 1706 import mercurial.revlog
1705 1707
1706 1708 mercurial.revlog._prereadsize = 2 ** 24 # disable lazy parser in old hg
1707 1709 n = scmutil.revsingle(repo, rev).node()
1708 1710 cl = mercurial.revlog.revlog(getsvfs(repo), b"00changelog.i")
1709 1711
1710 1712 def d():
1711 1713 cl.rev(n)
1712 1714 clearcaches(cl)
1713 1715
1714 1716 timer(d)
1715 1717 fm.end()
1716 1718
1717 1719
1718 1720 @command(
1719 1721 b'perflog',
1720 1722 [(b'', b'rename', False, b'ask log to follow renames')] + formatteropts,
1721 1723 )
1722 1724 def perflog(ui, repo, rev=None, **opts):
1723 1725 opts = _byteskwargs(opts)
1724 1726 if rev is None:
1725 1727 rev = []
1726 1728 timer, fm = gettimer(ui, opts)
1727 1729 ui.pushbuffer()
1728 1730 timer(
1729 1731 lambda: commands.log(
1730 1732 ui, repo, rev=rev, date=b'', user=b'', copies=opts.get(b'rename')
1731 1733 )
1732 1734 )
1733 1735 ui.popbuffer()
1734 1736 fm.end()
1735 1737
1736 1738
1737 1739 @command(b'perfmoonwalk', formatteropts)
1738 1740 def perfmoonwalk(ui, repo, **opts):
1739 1741 """benchmark walking the changelog backwards
1740 1742
1741 1743 This also loads the changelog data for each revision in the changelog.
1742 1744 """
1743 1745 opts = _byteskwargs(opts)
1744 1746 timer, fm = gettimer(ui, opts)
1745 1747
1746 1748 def moonwalk():
1747 1749 for i in repo.changelog.revs(start=(len(repo) - 1), stop=-1):
1748 1750 ctx = repo[i]
1749 1751 ctx.branch() # read changelog data (in addition to the index)
1750 1752
1751 1753 timer(moonwalk)
1752 1754 fm.end()
1753 1755
1754 1756
1755 1757 @command(
1756 1758 b'perftemplating',
1757 1759 [(b'r', b'rev', [], b'revisions to run the template on'),] + formatteropts,
1758 1760 )
1759 1761 def perftemplating(ui, repo, testedtemplate=None, **opts):
1760 1762 """test the rendering time of a given template"""
1761 1763 if makelogtemplater is None:
1762 1764 raise error.Abort(
1763 1765 b"perftemplating not available with this Mercurial",
1764 1766 hint=b"use 4.3 or later",
1765 1767 )
1766 1768
1767 1769 opts = _byteskwargs(opts)
1768 1770
1769 1771 nullui = ui.copy()
1770 1772 nullui.fout = open(os.devnull, r'wb')
1771 1773 nullui.disablepager()
1772 1774 revs = opts.get(b'rev')
1773 1775 if not revs:
1774 1776 revs = [b'all()']
1775 1777 revs = list(scmutil.revrange(repo, revs))
1776 1778
1777 1779 defaulttemplate = (
1778 1780 b'{date|shortdate} [{rev}:{node|short}]'
1779 1781 b' {author|person}: {desc|firstline}\n'
1780 1782 )
1781 1783 if testedtemplate is None:
1782 1784 testedtemplate = defaulttemplate
1783 1785 displayer = makelogtemplater(nullui, repo, testedtemplate)
1784 1786
1785 1787 def format():
1786 1788 for r in revs:
1787 1789 ctx = repo[r]
1788 1790 displayer.show(ctx)
1789 1791 displayer.flush(ctx)
1790 1792
1791 1793 timer, fm = gettimer(ui, opts)
1792 1794 timer(format)
1793 1795 fm.end()
1794 1796
1795 1797
1796 1798 def _displaystats(ui, opts, entries, data):
1797 1799 pass
1798 1800 # use a second formatter because the data are quite different, not sure
1799 1801 # how it flies with the templater.
1800 1802 fm = ui.formatter(b'perf-stats', opts)
1801 1803 for key, title in entries:
1802 1804 values = data[key]
1803 1805 nbvalues = len(data)
1804 1806 values.sort()
1805 1807 stats = {
1806 1808 'key': key,
1807 1809 'title': title,
1808 1810 'nbitems': len(values),
1809 1811 'min': values[0][0],
1810 1812 '10%': values[(nbvalues * 10) // 100][0],
1811 1813 '25%': values[(nbvalues * 25) // 100][0],
1812 1814 '50%': values[(nbvalues * 50) // 100][0],
1813 1815 '75%': values[(nbvalues * 75) // 100][0],
1814 1816 '80%': values[(nbvalues * 80) // 100][0],
1815 1817 '85%': values[(nbvalues * 85) // 100][0],
1816 1818 '90%': values[(nbvalues * 90) // 100][0],
1817 1819 '95%': values[(nbvalues * 95) // 100][0],
1818 1820 '99%': values[(nbvalues * 99) // 100][0],
1819 1821 'max': values[-1][0],
1820 1822 }
1821 1823 fm.startitem()
1822 1824 fm.data(**stats)
1823 1825 # make node pretty for the human output
1824 1826 fm.plain('### %s (%d items)\n' % (title, len(values)))
1825 1827 lines = [
1826 1828 'min',
1827 1829 '10%',
1828 1830 '25%',
1829 1831 '50%',
1830 1832 '75%',
1831 1833 '80%',
1832 1834 '85%',
1833 1835 '90%',
1834 1836 '95%',
1835 1837 '99%',
1836 1838 'max',
1837 1839 ]
1838 1840 for l in lines:
1839 1841 fm.plain('%s: %s\n' % (l, stats[l]))
1840 1842 fm.end()
1841 1843
1842 1844
1843 1845 @command(
1844 1846 b'perfhelper-mergecopies',
1845 1847 formatteropts
1846 1848 + [
1847 1849 (b'r', b'revs', [], b'restrict search to these revisions'),
1848 1850 (b'', b'timing', False, b'provides extra data (costly)'),
1849 1851 (b'', b'stats', False, b'provides statistic about the measured data'),
1850 1852 ],
1851 1853 )
1852 1854 def perfhelpermergecopies(ui, repo, revs=[], **opts):
1853 1855 """find statistics about potential parameters for `perfmergecopies`
1854 1856
1855 1857 This command find (base, p1, p2) triplet relevant for copytracing
1856 1858 benchmarking in the context of a merge. It reports values for some of the
1857 1859 parameters that impact merge copy tracing time during merge.
1858 1860
1859 1861 If `--timing` is set, rename detection is run and the associated timing
1860 1862 will be reported. The extra details come at the cost of slower command
1861 1863 execution.
1862 1864
1863 1865 Since rename detection is only run once, other factors might easily
1864 1866 affect the precision of the timing. However it should give a good
1865 1867 approximation of which revision triplets are very costly.
1866 1868 """
1867 1869 opts = _byteskwargs(opts)
1868 1870 fm = ui.formatter(b'perf', opts)
1869 1871 dotiming = opts[b'timing']
1870 1872 dostats = opts[b'stats']
1871 1873
1872 1874 output_template = [
1873 1875 ("base", "%(base)12s"),
1874 1876 ("p1", "%(p1.node)12s"),
1875 1877 ("p2", "%(p2.node)12s"),
1876 1878 ("p1.nb-revs", "%(p1.nbrevs)12d"),
1877 1879 ("p1.nb-files", "%(p1.nbmissingfiles)12d"),
1878 1880 ("p1.renames", "%(p1.renamedfiles)12d"),
1879 1881 ("p1.time", "%(p1.time)12.3f"),
1880 1882 ("p2.nb-revs", "%(p2.nbrevs)12d"),
1881 1883 ("p2.nb-files", "%(p2.nbmissingfiles)12d"),
1882 1884 ("p2.renames", "%(p2.renamedfiles)12d"),
1883 1885 ("p2.time", "%(p2.time)12.3f"),
1884 1886 ("renames", "%(nbrenamedfiles)12d"),
1885 1887 ("total.time", "%(time)12.3f"),
1886 1888 ]
1887 1889 if not dotiming:
1888 1890 output_template = [
1889 1891 i
1890 1892 for i in output_template
1891 1893 if not ('time' in i[0] or 'renames' in i[0])
1892 1894 ]
1893 1895 header_names = [h for (h, v) in output_template]
1894 1896 output = ' '.join([v for (h, v) in output_template]) + '\n'
1895 1897 header = ' '.join(['%12s'] * len(header_names)) + '\n'
1896 1898 fm.plain(header % tuple(header_names))
1897 1899
1898 1900 if not revs:
1899 1901 revs = ['all()']
1900 1902 revs = scmutil.revrange(repo, revs)
1901 1903
1902 1904 if dostats:
1903 1905 alldata = {
1904 1906 'nbrevs': [],
1905 1907 'nbmissingfiles': [],
1906 1908 }
1907 1909 if dotiming:
1908 1910 alldata['parentnbrenames'] = []
1909 1911 alldata['totalnbrenames'] = []
1910 1912 alldata['parenttime'] = []
1911 1913 alldata['totaltime'] = []
1912 1914
1913 1915 roi = repo.revs('merge() and %ld', revs)
1914 1916 for r in roi:
1915 1917 ctx = repo[r]
1916 1918 p1 = ctx.p1()
1917 1919 p2 = ctx.p2()
1918 1920 bases = repo.changelog._commonancestorsheads(p1.rev(), p2.rev())
1919 1921 for b in bases:
1920 1922 b = repo[b]
1921 1923 p1missing = copies._computeforwardmissing(b, p1)
1922 1924 p2missing = copies._computeforwardmissing(b, p2)
1923 1925 data = {
1924 1926 b'base': b.hex(),
1925 1927 b'p1.node': p1.hex(),
1926 1928 b'p1.nbrevs': len(repo.revs('%d::%d', b.rev(), p1.rev())),
1927 1929 b'p1.nbmissingfiles': len(p1missing),
1928 1930 b'p2.node': p2.hex(),
1929 1931 b'p2.nbrevs': len(repo.revs('%d::%d', b.rev(), p2.rev())),
1930 1932 b'p2.nbmissingfiles': len(p2missing),
1931 1933 }
1932 1934 if dostats:
1933 1935 if p1missing:
1934 1936 alldata['nbrevs'].append(
1935 1937 (data['p1.nbrevs'], b.hex(), p1.hex())
1936 1938 )
1937 1939 alldata['nbmissingfiles'].append(
1938 1940 (data['p1.nbmissingfiles'], b.hex(), p1.hex())
1939 1941 )
1940 1942 if p2missing:
1941 1943 alldata['nbrevs'].append(
1942 1944 (data['p2.nbrevs'], b.hex(), p2.hex())
1943 1945 )
1944 1946 alldata['nbmissingfiles'].append(
1945 1947 (data['p2.nbmissingfiles'], b.hex(), p2.hex())
1946 1948 )
1947 1949 if dotiming:
1948 1950 begin = util.timer()
1949 1951 mergedata = copies.mergecopies(repo, p1, p2, b)
1950 1952 end = util.timer()
1951 1953 # not very stable timing since we did only one run
1952 1954 data['time'] = end - begin
1953 1955 # mergedata contains five dicts: "copy", "movewithdir",
1954 1956 # "diverge", "renamedelete" and "dirmove".
1955 1957 # The first 4 are about renamed file so lets count that.
1956 1958 renames = len(mergedata[0])
1957 1959 renames += len(mergedata[1])
1958 1960 renames += len(mergedata[2])
1959 1961 renames += len(mergedata[3])
1960 1962 data['nbrenamedfiles'] = renames
1961 1963 begin = util.timer()
1962 1964 p1renames = copies.pathcopies(b, p1)
1963 1965 end = util.timer()
1964 1966 data['p1.time'] = end - begin
1965 1967 begin = util.timer()
1966 1968 p2renames = copies.pathcopies(b, p2)
1967 1969 data['p2.time'] = end - begin
1968 1970 end = util.timer()
1969 1971 data['p1.renamedfiles'] = len(p1renames)
1970 1972 data['p2.renamedfiles'] = len(p2renames)
1971 1973
1972 1974 if dostats:
1973 1975 if p1missing:
1974 1976 alldata['parentnbrenames'].append(
1975 1977 (data['p1.renamedfiles'], b.hex(), p1.hex())
1976 1978 )
1977 1979 alldata['parenttime'].append(
1978 1980 (data['p1.time'], b.hex(), p1.hex())
1979 1981 )
1980 1982 if p2missing:
1981 1983 alldata['parentnbrenames'].append(
1982 1984 (data['p2.renamedfiles'], b.hex(), p2.hex())
1983 1985 )
1984 1986 alldata['parenttime'].append(
1985 1987 (data['p2.time'], b.hex(), p2.hex())
1986 1988 )
1987 1989 if p1missing or p2missing:
1988 1990 alldata['totalnbrenames'].append(
1989 1991 (
1990 1992 data['nbrenamedfiles'],
1991 1993 b.hex(),
1992 1994 p1.hex(),
1993 1995 p2.hex(),
1994 1996 )
1995 1997 )
1996 1998 alldata['totaltime'].append(
1997 1999 (data['time'], b.hex(), p1.hex(), p2.hex())
1998 2000 )
1999 2001 fm.startitem()
2000 2002 fm.data(**data)
2001 2003 # make node pretty for the human output
2002 2004 out = data.copy()
2003 2005 out['base'] = fm.hexfunc(b.node())
2004 2006 out['p1.node'] = fm.hexfunc(p1.node())
2005 2007 out['p2.node'] = fm.hexfunc(p2.node())
2006 2008 fm.plain(output % out)
2007 2009
2008 2010 fm.end()
2009 2011 if dostats:
2010 2012 # use a second formatter because the data are quite different, not sure
2011 2013 # how it flies with the templater.
2012 2014 entries = [
2013 2015 ('nbrevs', 'number of revision covered'),
2014 2016 ('nbmissingfiles', 'number of missing files at head'),
2015 2017 ]
2016 2018 if dotiming:
2017 2019 entries.append(
2018 2020 ('parentnbrenames', 'rename from one parent to base')
2019 2021 )
2020 2022 entries.append(('totalnbrenames', 'total number of renames'))
2021 2023 entries.append(('parenttime', 'time for one parent'))
2022 2024 entries.append(('totaltime', 'time for both parents'))
2023 2025 _displaystats(ui, opts, entries, alldata)
2024 2026
2025 2027
2026 2028 @command(
2027 2029 b'perfhelper-pathcopies',
2028 2030 formatteropts
2029 2031 + [
2030 2032 (b'r', b'revs', [], b'restrict search to these revisions'),
2031 2033 (b'', b'timing', False, b'provides extra data (costly)'),
2032 2034 (b'', b'stats', False, b'provides statistic about the measured data'),
2033 2035 ],
2034 2036 )
2035 2037 def perfhelperpathcopies(ui, repo, revs=[], **opts):
2036 2038 """find statistic about potential parameters for the `perftracecopies`
2037 2039
2038 2040 This command find source-destination pair relevant for copytracing testing.
2039 2041 It report value for some of the parameters that impact copy tracing time.
2040 2042
2041 2043 If `--timing` is set, rename detection is run and the associated timing
2042 2044 will be reported. The extra details comes at the cost of a slower command
2043 2045 execution.
2044 2046
2045 2047 Since the rename detection is only run once, other factors might easily
2046 2048 affect the precision of the timing. However it should give a good
2047 2049 approximation of which revision pairs are very costly.
2048 2050 """
2049 2051 opts = _byteskwargs(opts)
2050 2052 fm = ui.formatter(b'perf', opts)
2051 2053 dotiming = opts[b'timing']
2052 2054 dostats = opts[b'stats']
2053 2055
2054 2056 if dotiming:
2055 2057 header = '%12s %12s %12s %12s %12s %12s\n'
2056 2058 output = (
2057 2059 "%(source)12s %(destination)12s "
2058 2060 "%(nbrevs)12d %(nbmissingfiles)12d "
2059 2061 "%(nbrenamedfiles)12d %(time)18.5f\n"
2060 2062 )
2061 2063 header_names = (
2062 2064 "source",
2063 2065 "destination",
2064 2066 "nb-revs",
2065 2067 "nb-files",
2066 2068 "nb-renames",
2067 2069 "time",
2068 2070 )
2069 2071 fm.plain(header % header_names)
2070 2072 else:
2071 2073 header = '%12s %12s %12s %12s\n'
2072 2074 output = (
2073 2075 "%(source)12s %(destination)12s "
2074 2076 "%(nbrevs)12d %(nbmissingfiles)12d\n"
2075 2077 )
2076 2078 fm.plain(header % ("source", "destination", "nb-revs", "nb-files"))
2077 2079
2078 2080 if not revs:
2079 2081 revs = ['all()']
2080 2082 revs = scmutil.revrange(repo, revs)
2081 2083
2082 2084 if dostats:
2083 2085 alldata = {
2084 2086 'nbrevs': [],
2085 2087 'nbmissingfiles': [],
2086 2088 }
2087 2089 if dotiming:
2088 2090 alldata['nbrenames'] = []
2089 2091 alldata['time'] = []
2090 2092
2091 2093 roi = repo.revs('merge() and %ld', revs)
2092 2094 for r in roi:
2093 2095 ctx = repo[r]
2094 2096 p1 = ctx.p1().rev()
2095 2097 p2 = ctx.p2().rev()
2096 2098 bases = repo.changelog._commonancestorsheads(p1, p2)
2097 2099 for p in (p1, p2):
2098 2100 for b in bases:
2099 2101 base = repo[b]
2100 2102 parent = repo[p]
2101 2103 missing = copies._computeforwardmissing(base, parent)
2102 2104 if not missing:
2103 2105 continue
2104 2106 data = {
2105 2107 b'source': base.hex(),
2106 2108 b'destination': parent.hex(),
2107 2109 b'nbrevs': len(repo.revs('%d::%d', b, p)),
2108 2110 b'nbmissingfiles': len(missing),
2109 2111 }
2110 2112 if dostats:
2111 2113 alldata['nbrevs'].append(
2112 2114 (data['nbrevs'], base.hex(), parent.hex(),)
2113 2115 )
2114 2116 alldata['nbmissingfiles'].append(
2115 2117 (data['nbmissingfiles'], base.hex(), parent.hex(),)
2116 2118 )
2117 2119 if dotiming:
2118 2120 begin = util.timer()
2119 2121 renames = copies.pathcopies(base, parent)
2120 2122 end = util.timer()
2121 2123 # not very stable timing since we did only one run
2122 2124 data['time'] = end - begin
2123 2125 data['nbrenamedfiles'] = len(renames)
2124 2126 if dostats:
2125 2127 alldata['time'].append(
2126 2128 (data['time'], base.hex(), parent.hex(),)
2127 2129 )
2128 2130 alldata['nbrenames'].append(
2129 2131 (data['nbrenamedfiles'], base.hex(), parent.hex(),)
2130 2132 )
2131 2133 fm.startitem()
2132 2134 fm.data(**data)
2133 2135 out = data.copy()
2134 2136 out['source'] = fm.hexfunc(base.node())
2135 2137 out['destination'] = fm.hexfunc(parent.node())
2136 2138 fm.plain(output % out)
2137 2139
2138 2140 fm.end()
2139 2141 if dostats:
2140 2142 # use a second formatter because the data are quite different, not sure
2141 2143 # how it flies with the templater.
2142 2144 fm = ui.formatter(b'perf', opts)
2143 2145 entries = [
2144 2146 ('nbrevs', 'number of revision covered'),
2145 2147 ('nbmissingfiles', 'number of missing files at head'),
2146 2148 ]
2147 2149 if dotiming:
2148 2150 entries.append(('nbrenames', 'renamed files'))
2149 2151 entries.append(('time', 'time'))
2150 2152 _displaystats(ui, opts, entries, alldata)
2151 2153
2152 2154
2153 2155 @command(b'perfcca', formatteropts)
2154 2156 def perfcca(ui, repo, **opts):
2155 2157 opts = _byteskwargs(opts)
2156 2158 timer, fm = gettimer(ui, opts)
2157 2159 timer(lambda: scmutil.casecollisionauditor(ui, False, repo.dirstate))
2158 2160 fm.end()
2159 2161
2160 2162
2161 2163 @command(b'perffncacheload', formatteropts)
2162 2164 def perffncacheload(ui, repo, **opts):
2163 2165 opts = _byteskwargs(opts)
2164 2166 timer, fm = gettimer(ui, opts)
2165 2167 s = repo.store
2166 2168
2167 2169 def d():
2168 2170 s.fncache._load()
2169 2171
2170 2172 timer(d)
2171 2173 fm.end()
2172 2174
2173 2175
2174 2176 @command(b'perffncachewrite', formatteropts)
2175 2177 def perffncachewrite(ui, repo, **opts):
2176 2178 opts = _byteskwargs(opts)
2177 2179 timer, fm = gettimer(ui, opts)
2178 2180 s = repo.store
2179 2181 lock = repo.lock()
2180 2182 s.fncache._load()
2181 2183 tr = repo.transaction(b'perffncachewrite')
2182 2184 tr.addbackup(b'fncache')
2183 2185
2184 2186 def d():
2185 2187 s.fncache._dirty = True
2186 2188 s.fncache.write(tr)
2187 2189
2188 2190 timer(d)
2189 2191 tr.close()
2190 2192 lock.release()
2191 2193 fm.end()
2192 2194
2193 2195
2194 2196 @command(b'perffncacheencode', formatteropts)
2195 2197 def perffncacheencode(ui, repo, **opts):
2196 2198 opts = _byteskwargs(opts)
2197 2199 timer, fm = gettimer(ui, opts)
2198 2200 s = repo.store
2199 2201 s.fncache._load()
2200 2202
2201 2203 def d():
2202 2204 for p in s.fncache.entries:
2203 2205 s.encode(p)
2204 2206
2205 2207 timer(d)
2206 2208 fm.end()
2207 2209
2208 2210
2209 2211 def _bdiffworker(q, blocks, xdiff, ready, done):
2210 2212 while not done.is_set():
2211 2213 pair = q.get()
2212 2214 while pair is not None:
2213 2215 if xdiff:
2214 2216 mdiff.bdiff.xdiffblocks(*pair)
2215 2217 elif blocks:
2216 2218 mdiff.bdiff.blocks(*pair)
2217 2219 else:
2218 2220 mdiff.textdiff(*pair)
2219 2221 q.task_done()
2220 2222 pair = q.get()
2221 2223 q.task_done() # for the None one
2222 2224 with ready:
2223 2225 ready.wait()
2224 2226
2225 2227
2226 2228 def _manifestrevision(repo, mnode):
2227 2229 ml = repo.manifestlog
2228 2230
2229 2231 if util.safehasattr(ml, b'getstorage'):
2230 2232 store = ml.getstorage(b'')
2231 2233 else:
2232 2234 store = ml._revlog
2233 2235
2234 2236 return store.revision(mnode)
2235 2237
2236 2238
2237 2239 @command(
2238 2240 b'perfbdiff',
2239 2241 revlogopts
2240 2242 + formatteropts
2241 2243 + [
2242 2244 (
2243 2245 b'',
2244 2246 b'count',
2245 2247 1,
2246 2248 b'number of revisions to test (when using --startrev)',
2247 2249 ),
2248 2250 (b'', b'alldata', False, b'test bdiffs for all associated revisions'),
2249 2251 (b'', b'threads', 0, b'number of thread to use (disable with 0)'),
2250 2252 (b'', b'blocks', False, b'test computing diffs into blocks'),
2251 2253 (b'', b'xdiff', False, b'use xdiff algorithm'),
2252 2254 ],
2253 2255 b'-c|-m|FILE REV',
2254 2256 )
2255 2257 def perfbdiff(ui, repo, file_, rev=None, count=None, threads=0, **opts):
2256 2258 """benchmark a bdiff between revisions
2257 2259
2258 2260 By default, benchmark a bdiff between its delta parent and itself.
2259 2261
2260 2262 With ``--count``, benchmark bdiffs between delta parents and self for N
2261 2263 revisions starting at the specified revision.
2262 2264
2263 2265 With ``--alldata``, assume the requested revision is a changeset and
2264 2266 measure bdiffs for all changes related to that changeset (manifest
2265 2267 and filelogs).
2266 2268 """
2267 2269 opts = _byteskwargs(opts)
2268 2270
2269 2271 if opts[b'xdiff'] and not opts[b'blocks']:
2270 2272 raise error.CommandError(b'perfbdiff', b'--xdiff requires --blocks')
2271 2273
2272 2274 if opts[b'alldata']:
2273 2275 opts[b'changelog'] = True
2274 2276
2275 2277 if opts.get(b'changelog') or opts.get(b'manifest'):
2276 2278 file_, rev = None, file_
2277 2279 elif rev is None:
2278 2280 raise error.CommandError(b'perfbdiff', b'invalid arguments')
2279 2281
2280 2282 blocks = opts[b'blocks']
2281 2283 xdiff = opts[b'xdiff']
2282 2284 textpairs = []
2283 2285
2284 2286 r = cmdutil.openrevlog(repo, b'perfbdiff', file_, opts)
2285 2287
2286 2288 startrev = r.rev(r.lookup(rev))
2287 2289 for rev in range(startrev, min(startrev + count, len(r) - 1)):
2288 2290 if opts[b'alldata']:
2289 2291 # Load revisions associated with changeset.
2290 2292 ctx = repo[rev]
2291 2293 mtext = _manifestrevision(repo, ctx.manifestnode())
2292 2294 for pctx in ctx.parents():
2293 2295 pman = _manifestrevision(repo, pctx.manifestnode())
2294 2296 textpairs.append((pman, mtext))
2295 2297
2296 2298 # Load filelog revisions by iterating manifest delta.
2297 2299 man = ctx.manifest()
2298 2300 pman = ctx.p1().manifest()
2299 2301 for filename, change in pman.diff(man).items():
2300 2302 fctx = repo.file(filename)
2301 2303 f1 = fctx.revision(change[0][0] or -1)
2302 2304 f2 = fctx.revision(change[1][0] or -1)
2303 2305 textpairs.append((f1, f2))
2304 2306 else:
2305 2307 dp = r.deltaparent(rev)
2306 2308 textpairs.append((r.revision(dp), r.revision(rev)))
2307 2309
2308 2310 withthreads = threads > 0
2309 2311 if not withthreads:
2310 2312
2311 2313 def d():
2312 2314 for pair in textpairs:
2313 2315 if xdiff:
2314 2316 mdiff.bdiff.xdiffblocks(*pair)
2315 2317 elif blocks:
2316 2318 mdiff.bdiff.blocks(*pair)
2317 2319 else:
2318 2320 mdiff.textdiff(*pair)
2319 2321
2320 2322 else:
2321 2323 q = queue()
2322 2324 for i in _xrange(threads):
2323 2325 q.put(None)
2324 2326 ready = threading.Condition()
2325 2327 done = threading.Event()
2326 2328 for i in _xrange(threads):
2327 2329 threading.Thread(
2328 2330 target=_bdiffworker, args=(q, blocks, xdiff, ready, done)
2329 2331 ).start()
2330 2332 q.join()
2331 2333
2332 2334 def d():
2333 2335 for pair in textpairs:
2334 2336 q.put(pair)
2335 2337 for i in _xrange(threads):
2336 2338 q.put(None)
2337 2339 with ready:
2338 2340 ready.notify_all()
2339 2341 q.join()
2340 2342
2341 2343 timer, fm = gettimer(ui, opts)
2342 2344 timer(d)
2343 2345 fm.end()
2344 2346
2345 2347 if withthreads:
2346 2348 done.set()
2347 2349 for i in _xrange(threads):
2348 2350 q.put(None)
2349 2351 with ready:
2350 2352 ready.notify_all()
2351 2353
2352 2354
2353 2355 @command(
2354 2356 b'perfunidiff',
2355 2357 revlogopts
2356 2358 + formatteropts
2357 2359 + [
2358 2360 (
2359 2361 b'',
2360 2362 b'count',
2361 2363 1,
2362 2364 b'number of revisions to test (when using --startrev)',
2363 2365 ),
2364 2366 (b'', b'alldata', False, b'test unidiffs for all associated revisions'),
2365 2367 ],
2366 2368 b'-c|-m|FILE REV',
2367 2369 )
2368 2370 def perfunidiff(ui, repo, file_, rev=None, count=None, **opts):
2369 2371 """benchmark a unified diff between revisions
2370 2372
2371 2373 This doesn't include any copy tracing - it's just a unified diff
2372 2374 of the texts.
2373 2375
2374 2376 By default, benchmark a diff between its delta parent and itself.
2375 2377
2376 2378 With ``--count``, benchmark diffs between delta parents and self for N
2377 2379 revisions starting at the specified revision.
2378 2380
2379 2381 With ``--alldata``, assume the requested revision is a changeset and
2380 2382 measure diffs for all changes related to that changeset (manifest
2381 2383 and filelogs).
2382 2384 """
2383 2385 opts = _byteskwargs(opts)
2384 2386 if opts[b'alldata']:
2385 2387 opts[b'changelog'] = True
2386 2388
2387 2389 if opts.get(b'changelog') or opts.get(b'manifest'):
2388 2390 file_, rev = None, file_
2389 2391 elif rev is None:
2390 2392 raise error.CommandError(b'perfunidiff', b'invalid arguments')
2391 2393
2392 2394 textpairs = []
2393 2395
2394 2396 r = cmdutil.openrevlog(repo, b'perfunidiff', file_, opts)
2395 2397
2396 2398 startrev = r.rev(r.lookup(rev))
2397 2399 for rev in range(startrev, min(startrev + count, len(r) - 1)):
2398 2400 if opts[b'alldata']:
2399 2401 # Load revisions associated with changeset.
2400 2402 ctx = repo[rev]
2401 2403 mtext = _manifestrevision(repo, ctx.manifestnode())
2402 2404 for pctx in ctx.parents():
2403 2405 pman = _manifestrevision(repo, pctx.manifestnode())
2404 2406 textpairs.append((pman, mtext))
2405 2407
2406 2408 # Load filelog revisions by iterating manifest delta.
2407 2409 man = ctx.manifest()
2408 2410 pman = ctx.p1().manifest()
2409 2411 for filename, change in pman.diff(man).items():
2410 2412 fctx = repo.file(filename)
2411 2413 f1 = fctx.revision(change[0][0] or -1)
2412 2414 f2 = fctx.revision(change[1][0] or -1)
2413 2415 textpairs.append((f1, f2))
2414 2416 else:
2415 2417 dp = r.deltaparent(rev)
2416 2418 textpairs.append((r.revision(dp), r.revision(rev)))
2417 2419
2418 2420 def d():
2419 2421 for left, right in textpairs:
2420 2422 # The date strings don't matter, so we pass empty strings.
2421 2423 headerlines, hunks = mdiff.unidiff(
2422 2424 left, b'', right, b'', b'left', b'right', binary=False
2423 2425 )
2424 2426 # consume iterators in roughly the way patch.py does
2425 2427 b'\n'.join(headerlines)
2426 2428 b''.join(sum((list(hlines) for hrange, hlines in hunks), []))
2427 2429
2428 2430 timer, fm = gettimer(ui, opts)
2429 2431 timer(d)
2430 2432 fm.end()
2431 2433
2432 2434
2433 2435 @command(b'perfdiffwd', formatteropts)
2434 2436 def perfdiffwd(ui, repo, **opts):
2435 2437 """Profile diff of working directory changes"""
2436 2438 opts = _byteskwargs(opts)
2437 2439 timer, fm = gettimer(ui, opts)
2438 2440 options = {
2439 2441 'w': 'ignore_all_space',
2440 2442 'b': 'ignore_space_change',
2441 2443 'B': 'ignore_blank_lines',
2442 2444 }
2443 2445
2444 2446 for diffopt in ('', 'w', 'b', 'B', 'wB'):
2445 2447 opts = dict((options[c], b'1') for c in diffopt)
2446 2448
2447 2449 def d():
2448 2450 ui.pushbuffer()
2449 2451 commands.diff(ui, repo, **opts)
2450 2452 ui.popbuffer()
2451 2453
2452 2454 diffopt = diffopt.encode('ascii')
2453 2455 title = b'diffopts: %s' % (diffopt and (b'-' + diffopt) or b'none')
2454 2456 timer(d, title=title)
2455 2457 fm.end()
2456 2458
2457 2459
2458 2460 @command(b'perfrevlogindex', revlogopts + formatteropts, b'-c|-m|FILE')
2459 2461 def perfrevlogindex(ui, repo, file_=None, **opts):
2460 2462 """Benchmark operations against a revlog index.
2461 2463
2462 2464 This tests constructing a revlog instance, reading index data,
2463 2465 parsing index data, and performing various operations related to
2464 2466 index data.
2465 2467 """
2466 2468
2467 2469 opts = _byteskwargs(opts)
2468 2470
2469 2471 rl = cmdutil.openrevlog(repo, b'perfrevlogindex', file_, opts)
2470 2472
2471 2473 opener = getattr(rl, 'opener') # trick linter
2472 2474 indexfile = rl.indexfile
2473 2475 data = opener.read(indexfile)
2474 2476
2475 2477 header = struct.unpack(b'>I', data[0:4])[0]
2476 2478 version = header & 0xFFFF
2477 2479 if version == 1:
2478 2480 revlogio = revlog.revlogio()
2479 2481 inline = header & (1 << 16)
2480 2482 else:
2481 2483 raise error.Abort(b'unsupported revlog version: %d' % version)
2482 2484
2483 2485 rllen = len(rl)
2484 2486
2485 2487 node0 = rl.node(0)
2486 2488 node25 = rl.node(rllen // 4)
2487 2489 node50 = rl.node(rllen // 2)
2488 2490 node75 = rl.node(rllen // 4 * 3)
2489 2491 node100 = rl.node(rllen - 1)
2490 2492
2491 2493 allrevs = range(rllen)
2492 2494 allrevsrev = list(reversed(allrevs))
2493 2495 allnodes = [rl.node(rev) for rev in range(rllen)]
2494 2496 allnodesrev = list(reversed(allnodes))
2495 2497
2496 2498 def constructor():
2497 2499 revlog.revlog(opener, indexfile)
2498 2500
2499 2501 def read():
2500 2502 with opener(indexfile) as fh:
2501 2503 fh.read()
2502 2504
2503 2505 def parseindex():
2504 2506 revlogio.parseindex(data, inline)
2505 2507
2506 2508 def getentry(revornode):
2507 2509 index = revlogio.parseindex(data, inline)[0]
2508 2510 index[revornode]
2509 2511
2510 2512 def getentries(revs, count=1):
2511 2513 index = revlogio.parseindex(data, inline)[0]
2512 2514
2513 2515 for i in range(count):
2514 2516 for rev in revs:
2515 2517 index[rev]
2516 2518
2517 2519 def resolvenode(node):
2518 2520 nodemap = revlogio.parseindex(data, inline)[1]
2519 2521 # This only works for the C code.
2520 2522 if nodemap is None:
2521 2523 return
2522 2524
2523 2525 try:
2524 2526 nodemap[node]
2525 2527 except error.RevlogError:
2526 2528 pass
2527 2529
2528 2530 def resolvenodes(nodes, count=1):
2529 2531 nodemap = revlogio.parseindex(data, inline)[1]
2530 2532 if nodemap is None:
2531 2533 return
2532 2534
2533 2535 for i in range(count):
2534 2536 for node in nodes:
2535 2537 try:
2536 2538 nodemap[node]
2537 2539 except error.RevlogError:
2538 2540 pass
2539 2541
2540 2542 benches = [
2541 2543 (constructor, b'revlog constructor'),
2542 2544 (read, b'read'),
2543 2545 (parseindex, b'create index object'),
2544 2546 (lambda: getentry(0), b'retrieve index entry for rev 0'),
2545 2547 (lambda: resolvenode(b'a' * 20), b'look up missing node'),
2546 2548 (lambda: resolvenode(node0), b'look up node at rev 0'),
2547 2549 (lambda: resolvenode(node25), b'look up node at 1/4 len'),
2548 2550 (lambda: resolvenode(node50), b'look up node at 1/2 len'),
2549 2551 (lambda: resolvenode(node75), b'look up node at 3/4 len'),
2550 2552 (lambda: resolvenode(node100), b'look up node at tip'),
2551 2553 # 2x variation is to measure caching impact.
2552 2554 (lambda: resolvenodes(allnodes), b'look up all nodes (forward)'),
2553 2555 (lambda: resolvenodes(allnodes, 2), b'look up all nodes 2x (forward)'),
2554 2556 (lambda: resolvenodes(allnodesrev), b'look up all nodes (reverse)'),
2555 2557 (
2556 2558 lambda: resolvenodes(allnodesrev, 2),
2557 2559 b'look up all nodes 2x (reverse)',
2558 2560 ),
2559 2561 (lambda: getentries(allrevs), b'retrieve all index entries (forward)'),
2560 2562 (
2561 2563 lambda: getentries(allrevs, 2),
2562 2564 b'retrieve all index entries 2x (forward)',
2563 2565 ),
2564 2566 (
2565 2567 lambda: getentries(allrevsrev),
2566 2568 b'retrieve all index entries (reverse)',
2567 2569 ),
2568 2570 (
2569 2571 lambda: getentries(allrevsrev, 2),
2570 2572 b'retrieve all index entries 2x (reverse)',
2571 2573 ),
2572 2574 ]
2573 2575
2574 2576 for fn, title in benches:
2575 2577 timer, fm = gettimer(ui, opts)
2576 2578 timer(fn, title=title)
2577 2579 fm.end()
2578 2580
2579 2581
2580 2582 @command(
2581 2583 b'perfrevlogrevisions',
2582 2584 revlogopts
2583 2585 + formatteropts
2584 2586 + [
2585 2587 (b'd', b'dist', 100, b'distance between the revisions'),
2586 2588 (b's', b'startrev', 0, b'revision to start reading at'),
2587 2589 (b'', b'reverse', False, b'read in reverse'),
2588 2590 ],
2589 2591 b'-c|-m|FILE',
2590 2592 )
2591 2593 def perfrevlogrevisions(
2592 2594 ui, repo, file_=None, startrev=0, reverse=False, **opts
2593 2595 ):
2594 2596 """Benchmark reading a series of revisions from a revlog.
2595 2597
2596 2598 By default, we read every ``-d/--dist`` revision from 0 to tip of
2597 2599 the specified revlog.
2598 2600
2599 2601 The start revision can be defined via ``-s/--startrev``.
2600 2602 """
2601 2603 opts = _byteskwargs(opts)
2602 2604
2603 2605 rl = cmdutil.openrevlog(repo, b'perfrevlogrevisions', file_, opts)
2604 2606 rllen = getlen(ui)(rl)
2605 2607
2606 2608 if startrev < 0:
2607 2609 startrev = rllen + startrev
2608 2610
2609 2611 def d():
2610 2612 rl.clearcaches()
2611 2613
2612 2614 beginrev = startrev
2613 2615 endrev = rllen
2614 2616 dist = opts[b'dist']
2615 2617
2616 2618 if reverse:
2617 2619 beginrev, endrev = endrev - 1, beginrev - 1
2618 2620 dist = -1 * dist
2619 2621
2620 2622 for x in _xrange(beginrev, endrev, dist):
2621 2623 # Old revisions don't support passing int.
2622 2624 n = rl.node(x)
2623 2625 rl.revision(n)
2624 2626
2625 2627 timer, fm = gettimer(ui, opts)
2626 2628 timer(d)
2627 2629 fm.end()
2628 2630
2629 2631
2630 2632 @command(
2631 2633 b'perfrevlogwrite',
2632 2634 revlogopts
2633 2635 + formatteropts
2634 2636 + [
2635 2637 (b's', b'startrev', 1000, b'revision to start writing at'),
2636 2638 (b'', b'stoprev', -1, b'last revision to write'),
2637 2639 (b'', b'count', 3, b'number of passes to perform'),
2638 2640 (b'', b'details', False, b'print timing for every revisions tested'),
2639 2641 (b'', b'source', b'full', b'the kind of data feed in the revlog'),
2640 2642 (b'', b'lazydeltabase', True, b'try the provided delta first'),
2641 2643 (b'', b'clear-caches', True, b'clear revlog cache between calls'),
2642 2644 ],
2643 2645 b'-c|-m|FILE',
2644 2646 )
2645 2647 def perfrevlogwrite(ui, repo, file_=None, startrev=1000, stoprev=-1, **opts):
2646 2648 """Benchmark writing a series of revisions to a revlog.
2647 2649
2648 2650 Possible source values are:
2649 2651 * `full`: add from a full text (default).
2650 2652 * `parent-1`: add from a delta to the first parent
2651 2653 * `parent-2`: add from a delta to the second parent if it exists
2652 2654 (use a delta from the first parent otherwise)
2653 2655 * `parent-smallest`: add from the smallest delta (either p1 or p2)
2654 2656 * `storage`: add from the existing precomputed deltas
2655 2657
2656 2658 Note: This performance command measures performance in a custom way. As a
2657 2659 result some of the global configuration of the 'perf' command does not
2658 2660 apply to it:
2659 2661
2660 2662 * ``pre-run``: disabled
2661 2663
2662 2664 * ``profile-benchmark``: disabled
2663 2665
2664 2666 * ``run-limits``: disabled use --count instead
2665 2667 """
2666 2668 opts = _byteskwargs(opts)
2667 2669
2668 2670 rl = cmdutil.openrevlog(repo, b'perfrevlogwrite', file_, opts)
2669 2671 rllen = getlen(ui)(rl)
2670 2672 if startrev < 0:
2671 2673 startrev = rllen + startrev
2672 2674 if stoprev < 0:
2673 2675 stoprev = rllen + stoprev
2674 2676
2675 2677 lazydeltabase = opts['lazydeltabase']
2676 2678 source = opts['source']
2677 2679 clearcaches = opts['clear_caches']
2678 2680 validsource = (
2679 2681 b'full',
2680 2682 b'parent-1',
2681 2683 b'parent-2',
2682 2684 b'parent-smallest',
2683 2685 b'storage',
2684 2686 )
2685 2687 if source not in validsource:
2686 2688 raise error.Abort('invalid source type: %s' % source)
2687 2689
2688 2690 ### actually gather results
2689 2691 count = opts['count']
2690 2692 if count <= 0:
2691 2693 raise error.Abort('invalide run count: %d' % count)
2692 2694 allresults = []
2693 2695 for c in range(count):
2694 2696 timing = _timeonewrite(
2695 2697 ui,
2696 2698 rl,
2697 2699 source,
2698 2700 startrev,
2699 2701 stoprev,
2700 2702 c + 1,
2701 2703 lazydeltabase=lazydeltabase,
2702 2704 clearcaches=clearcaches,
2703 2705 )
2704 2706 allresults.append(timing)
2705 2707
2706 2708 ### consolidate the results in a single list
2707 2709 results = []
2708 2710 for idx, (rev, t) in enumerate(allresults[0]):
2709 2711 ts = [t]
2710 2712 for other in allresults[1:]:
2711 2713 orev, ot = other[idx]
2712 2714 assert orev == rev
2713 2715 ts.append(ot)
2714 2716 results.append((rev, ts))
2715 2717 resultcount = len(results)
2716 2718
2717 2719 ### Compute and display relevant statistics
2718 2720
2719 2721 # get a formatter
2720 2722 fm = ui.formatter(b'perf', opts)
2721 2723 displayall = ui.configbool(b"perf", b"all-timing", False)
2722 2724
2723 2725 # print individual details if requested
2724 2726 if opts['details']:
2725 2727 for idx, item in enumerate(results, 1):
2726 2728 rev, data = item
2727 2729 title = 'revisions #%d of %d, rev %d' % (idx, resultcount, rev)
2728 2730 formatone(fm, data, title=title, displayall=displayall)
2729 2731
2730 2732 # sorts results by median time
2731 2733 results.sort(key=lambda x: sorted(x[1])[len(x[1]) // 2])
2732 2734 # list of (name, index) to display)
2733 2735 relevants = [
2734 2736 ("min", 0),
2735 2737 ("10%", resultcount * 10 // 100),
2736 2738 ("25%", resultcount * 25 // 100),
2737 2739 ("50%", resultcount * 70 // 100),
2738 2740 ("75%", resultcount * 75 // 100),
2739 2741 ("90%", resultcount * 90 // 100),
2740 2742 ("95%", resultcount * 95 // 100),
2741 2743 ("99%", resultcount * 99 // 100),
2742 2744 ("99.9%", resultcount * 999 // 1000),
2743 2745 ("99.99%", resultcount * 9999 // 10000),
2744 2746 ("99.999%", resultcount * 99999 // 100000),
2745 2747 ("max", -1),
2746 2748 ]
2747 2749 if not ui.quiet:
2748 2750 for name, idx in relevants:
2749 2751 data = results[idx]
2750 2752 title = '%s of %d, rev %d' % (name, resultcount, data[0])
2751 2753 formatone(fm, data[1], title=title, displayall=displayall)
2752 2754
2753 2755 # XXX summing that many float will not be very precise, we ignore this fact
2754 2756 # for now
2755 2757 totaltime = []
2756 2758 for item in allresults:
2757 2759 totaltime.append(
2758 2760 (
2759 2761 sum(x[1][0] for x in item),
2760 2762 sum(x[1][1] for x in item),
2761 2763 sum(x[1][2] for x in item),
2762 2764 )
2763 2765 )
2764 2766 formatone(
2765 2767 fm,
2766 2768 totaltime,
2767 2769 title="total time (%d revs)" % resultcount,
2768 2770 displayall=displayall,
2769 2771 )
2770 2772 fm.end()
2771 2773
2772 2774
2773 2775 class _faketr(object):
2774 2776 def add(s, x, y, z=None):
2775 2777 return None
2776 2778
2777 2779
2778 2780 def _timeonewrite(
2779 2781 ui,
2780 2782 orig,
2781 2783 source,
2782 2784 startrev,
2783 2785 stoprev,
2784 2786 runidx=None,
2785 2787 lazydeltabase=True,
2786 2788 clearcaches=True,
2787 2789 ):
2788 2790 timings = []
2789 2791 tr = _faketr()
2790 2792 with _temprevlog(ui, orig, startrev) as dest:
2791 2793 dest._lazydeltabase = lazydeltabase
2792 2794 revs = list(orig.revs(startrev, stoprev))
2793 2795 total = len(revs)
2794 2796 topic = 'adding'
2795 2797 if runidx is not None:
2796 2798 topic += ' (run #%d)' % runidx
2797 2799 # Support both old and new progress API
2798 2800 if util.safehasattr(ui, 'makeprogress'):
2799 2801 progress = ui.makeprogress(topic, unit='revs', total=total)
2800 2802
2801 2803 def updateprogress(pos):
2802 2804 progress.update(pos)
2803 2805
2804 2806 def completeprogress():
2805 2807 progress.complete()
2806 2808
2807 2809 else:
2808 2810
2809 2811 def updateprogress(pos):
2810 2812 ui.progress(topic, pos, unit='revs', total=total)
2811 2813
2812 2814 def completeprogress():
2813 2815 ui.progress(topic, None, unit='revs', total=total)
2814 2816
2815 2817 for idx, rev in enumerate(revs):
2816 2818 updateprogress(idx)
2817 2819 addargs, addkwargs = _getrevisionseed(orig, rev, tr, source)
2818 2820 if clearcaches:
2819 2821 dest.index.clearcaches()
2820 2822 dest.clearcaches()
2821 2823 with timeone() as r:
2822 2824 dest.addrawrevision(*addargs, **addkwargs)
2823 2825 timings.append((rev, r[0]))
2824 2826 updateprogress(total)
2825 2827 completeprogress()
2826 2828 return timings
2827 2829
2828 2830
2829 2831 def _getrevisionseed(orig, rev, tr, source):
2830 2832 from mercurial.node import nullid
2831 2833
2832 2834 linkrev = orig.linkrev(rev)
2833 2835 node = orig.node(rev)
2834 2836 p1, p2 = orig.parents(node)
2835 2837 flags = orig.flags(rev)
2836 2838 cachedelta = None
2837 2839 text = None
2838 2840
2839 2841 if source == b'full':
2840 2842 text = orig.revision(rev)
2841 2843 elif source == b'parent-1':
2842 2844 baserev = orig.rev(p1)
2843 2845 cachedelta = (baserev, orig.revdiff(p1, rev))
2844 2846 elif source == b'parent-2':
2845 2847 parent = p2
2846 2848 if p2 == nullid:
2847 2849 parent = p1
2848 2850 baserev = orig.rev(parent)
2849 2851 cachedelta = (baserev, orig.revdiff(parent, rev))
2850 2852 elif source == b'parent-smallest':
2851 2853 p1diff = orig.revdiff(p1, rev)
2852 2854 parent = p1
2853 2855 diff = p1diff
2854 2856 if p2 != nullid:
2855 2857 p2diff = orig.revdiff(p2, rev)
2856 2858 if len(p1diff) > len(p2diff):
2857 2859 parent = p2
2858 2860 diff = p2diff
2859 2861 baserev = orig.rev(parent)
2860 2862 cachedelta = (baserev, diff)
2861 2863 elif source == b'storage':
2862 2864 baserev = orig.deltaparent(rev)
2863 2865 cachedelta = (baserev, orig.revdiff(orig.node(baserev), rev))
2864 2866
2865 2867 return (
2866 2868 (text, tr, linkrev, p1, p2),
2867 2869 {'node': node, 'flags': flags, 'cachedelta': cachedelta},
2868 2870 )
2869 2871
2870 2872
2871 2873 @contextlib.contextmanager
2872 2874 def _temprevlog(ui, orig, truncaterev):
2873 2875 from mercurial import vfs as vfsmod
2874 2876
2875 2877 if orig._inline:
2876 2878 raise error.Abort('not supporting inline revlog (yet)')
2877 2879 revlogkwargs = {}
2878 2880 k = 'upperboundcomp'
2879 2881 if util.safehasattr(orig, k):
2880 2882 revlogkwargs[k] = getattr(orig, k)
2881 2883
2882 2884 origindexpath = orig.opener.join(orig.indexfile)
2883 2885 origdatapath = orig.opener.join(orig.datafile)
2884 2886 indexname = 'revlog.i'
2885 2887 dataname = 'revlog.d'
2886 2888
2887 2889 tmpdir = tempfile.mkdtemp(prefix='tmp-hgperf-')
2888 2890 try:
2889 2891 # copy the data file in a temporary directory
2890 2892 ui.debug('copying data in %s\n' % tmpdir)
2891 2893 destindexpath = os.path.join(tmpdir, 'revlog.i')
2892 2894 destdatapath = os.path.join(tmpdir, 'revlog.d')
2893 2895 shutil.copyfile(origindexpath, destindexpath)
2894 2896 shutil.copyfile(origdatapath, destdatapath)
2895 2897
2896 2898 # remove the data we want to add again
2897 2899 ui.debug('truncating data to be rewritten\n')
2898 2900 with open(destindexpath, 'ab') as index:
2899 2901 index.seek(0)
2900 2902 index.truncate(truncaterev * orig._io.size)
2901 2903 with open(destdatapath, 'ab') as data:
2902 2904 data.seek(0)
2903 2905 data.truncate(orig.start(truncaterev))
2904 2906
2905 2907 # instantiate a new revlog from the temporary copy
2906 2908 ui.debug('truncating adding to be rewritten\n')
2907 2909 vfs = vfsmod.vfs(tmpdir)
2908 2910 vfs.options = getattr(orig.opener, 'options', None)
2909 2911
2910 2912 dest = revlog.revlog(
2911 2913 vfs, indexfile=indexname, datafile=dataname, **revlogkwargs
2912 2914 )
2913 2915 if dest._inline:
2914 2916 raise error.Abort('not supporting inline revlog (yet)')
2915 2917 # make sure internals are initialized
2916 2918 dest.revision(len(dest) - 1)
2917 2919 yield dest
2918 2920 del dest, vfs
2919 2921 finally:
2920 2922 shutil.rmtree(tmpdir, True)
2921 2923
2922 2924
2923 2925 @command(
2924 2926 b'perfrevlogchunks',
2925 2927 revlogopts
2926 2928 + formatteropts
2927 2929 + [
2928 2930 (b'e', b'engines', b'', b'compression engines to use'),
2929 2931 (b's', b'startrev', 0, b'revision to start at'),
2930 2932 ],
2931 2933 b'-c|-m|FILE',
2932 2934 )
2933 2935 def perfrevlogchunks(ui, repo, file_=None, engines=None, startrev=0, **opts):
2934 2936 """Benchmark operations on revlog chunks.
2935 2937
2936 2938 Logically, each revlog is a collection of fulltext revisions. However,
2937 2939 stored within each revlog are "chunks" of possibly compressed data. This
2938 2940 data needs to be read and decompressed or compressed and written.
2939 2941
2940 2942 This command measures the time it takes to read+decompress and recompress
2941 2943 chunks in a revlog. It effectively isolates I/O and compression performance.
2942 2944 For measurements of higher-level operations like resolving revisions,
2943 2945 see ``perfrevlogrevisions`` and ``perfrevlogrevision``.
2944 2946 """
2945 2947 opts = _byteskwargs(opts)
2946 2948
2947 2949 rl = cmdutil.openrevlog(repo, b'perfrevlogchunks', file_, opts)
2948 2950
2949 2951 # _chunkraw was renamed to _getsegmentforrevs.
2950 2952 try:
2951 2953 segmentforrevs = rl._getsegmentforrevs
2952 2954 except AttributeError:
2953 2955 segmentforrevs = rl._chunkraw
2954 2956
2955 2957 # Verify engines argument.
2956 2958 if engines:
2957 2959 engines = set(e.strip() for e in engines.split(b','))
2958 2960 for engine in engines:
2959 2961 try:
2960 2962 util.compressionengines[engine]
2961 2963 except KeyError:
2962 2964 raise error.Abort(b'unknown compression engine: %s' % engine)
2963 2965 else:
2964 2966 engines = []
2965 2967 for e in util.compengines:
2966 2968 engine = util.compengines[e]
2967 2969 try:
2968 2970 if engine.available():
2969 2971 engine.revlogcompressor().compress(b'dummy')
2970 2972 engines.append(e)
2971 2973 except NotImplementedError:
2972 2974 pass
2973 2975
2974 2976 revs = list(rl.revs(startrev, len(rl) - 1))
2975 2977
2976 2978 def rlfh(rl):
2977 2979 if rl._inline:
2978 2980 return getsvfs(repo)(rl.indexfile)
2979 2981 else:
2980 2982 return getsvfs(repo)(rl.datafile)
2981 2983
2982 2984 def doread():
2983 2985 rl.clearcaches()
2984 2986 for rev in revs:
2985 2987 segmentforrevs(rev, rev)
2986 2988
2987 2989 def doreadcachedfh():
2988 2990 rl.clearcaches()
2989 2991 fh = rlfh(rl)
2990 2992 for rev in revs:
2991 2993 segmentforrevs(rev, rev, df=fh)
2992 2994
2993 2995 def doreadbatch():
2994 2996 rl.clearcaches()
2995 2997 segmentforrevs(revs[0], revs[-1])
2996 2998
2997 2999 def doreadbatchcachedfh():
2998 3000 rl.clearcaches()
2999 3001 fh = rlfh(rl)
3000 3002 segmentforrevs(revs[0], revs[-1], df=fh)
3001 3003
3002 3004 def dochunk():
3003 3005 rl.clearcaches()
3004 3006 fh = rlfh(rl)
3005 3007 for rev in revs:
3006 3008 rl._chunk(rev, df=fh)
3007 3009
3008 3010 chunks = [None]
3009 3011
3010 3012 def dochunkbatch():
3011 3013 rl.clearcaches()
3012 3014 fh = rlfh(rl)
3013 3015 # Save chunks as a side-effect.
3014 3016 chunks[0] = rl._chunks(revs, df=fh)
3015 3017
3016 3018 def docompress(compressor):
3017 3019 rl.clearcaches()
3018 3020
3019 3021 try:
3020 3022 # Swap in the requested compression engine.
3021 3023 oldcompressor = rl._compressor
3022 3024 rl._compressor = compressor
3023 3025 for chunk in chunks[0]:
3024 3026 rl.compress(chunk)
3025 3027 finally:
3026 3028 rl._compressor = oldcompressor
3027 3029
3028 3030 benches = [
3029 3031 (lambda: doread(), b'read'),
3030 3032 (lambda: doreadcachedfh(), b'read w/ reused fd'),
3031 3033 (lambda: doreadbatch(), b'read batch'),
3032 3034 (lambda: doreadbatchcachedfh(), b'read batch w/ reused fd'),
3033 3035 (lambda: dochunk(), b'chunk'),
3034 3036 (lambda: dochunkbatch(), b'chunk batch'),
3035 3037 ]
3036 3038
3037 3039 for engine in sorted(engines):
3038 3040 compressor = util.compengines[engine].revlogcompressor()
3039 3041 benches.append(
3040 3042 (
3041 3043 functools.partial(docompress, compressor),
3042 3044 b'compress w/ %s' % engine,
3043 3045 )
3044 3046 )
3045 3047
3046 3048 for fn, title in benches:
3047 3049 timer, fm = gettimer(ui, opts)
3048 3050 timer(fn, title=title)
3049 3051 fm.end()
3050 3052
3051 3053
3052 3054 @command(
3053 3055 b'perfrevlogrevision',
3054 3056 revlogopts
3055 3057 + formatteropts
3056 3058 + [(b'', b'cache', False, b'use caches instead of clearing')],
3057 3059 b'-c|-m|FILE REV',
3058 3060 )
3059 3061 def perfrevlogrevision(ui, repo, file_, rev=None, cache=None, **opts):
3060 3062 """Benchmark obtaining a revlog revision.
3061 3063
3062 3064 Obtaining a revlog revision consists of roughly the following steps:
3063 3065
3064 3066 1. Compute the delta chain
3065 3067 2. Slice the delta chain if applicable
3066 3068 3. Obtain the raw chunks for that delta chain
3067 3069 4. Decompress each raw chunk
3068 3070 5. Apply binary patches to obtain fulltext
3069 3071 6. Verify hash of fulltext
3070 3072
3071 3073 This command measures the time spent in each of these phases.
3072 3074 """
3073 3075 opts = _byteskwargs(opts)
3074 3076
3075 3077 if opts.get(b'changelog') or opts.get(b'manifest'):
3076 3078 file_, rev = None, file_
3077 3079 elif rev is None:
3078 3080 raise error.CommandError(b'perfrevlogrevision', b'invalid arguments')
3079 3081
3080 3082 r = cmdutil.openrevlog(repo, b'perfrevlogrevision', file_, opts)
3081 3083
3082 3084 # _chunkraw was renamed to _getsegmentforrevs.
3083 3085 try:
3084 3086 segmentforrevs = r._getsegmentforrevs
3085 3087 except AttributeError:
3086 3088 segmentforrevs = r._chunkraw
3087 3089
3088 3090 node = r.lookup(rev)
3089 3091 rev = r.rev(node)
3090 3092
3091 3093 def getrawchunks(data, chain):
3092 3094 start = r.start
3093 3095 length = r.length
3094 3096 inline = r._inline
3095 3097 iosize = r._io.size
3096 3098 buffer = util.buffer
3097 3099
3098 3100 chunks = []
3099 3101 ladd = chunks.append
3100 3102 for idx, item in enumerate(chain):
3101 3103 offset = start(item[0])
3102 3104 bits = data[idx]
3103 3105 for rev in item:
3104 3106 chunkstart = start(rev)
3105 3107 if inline:
3106 3108 chunkstart += (rev + 1) * iosize
3107 3109 chunklength = length(rev)
3108 3110 ladd(buffer(bits, chunkstart - offset, chunklength))
3109 3111
3110 3112 return chunks
3111 3113
3112 3114 def dodeltachain(rev):
3113 3115 if not cache:
3114 3116 r.clearcaches()
3115 3117 r._deltachain(rev)
3116 3118
3117 3119 def doread(chain):
3118 3120 if not cache:
3119 3121 r.clearcaches()
3120 3122 for item in slicedchain:
3121 3123 segmentforrevs(item[0], item[-1])
3122 3124
3123 3125 def doslice(r, chain, size):
3124 3126 for s in slicechunk(r, chain, targetsize=size):
3125 3127 pass
3126 3128
3127 3129 def dorawchunks(data, chain):
3128 3130 if not cache:
3129 3131 r.clearcaches()
3130 3132 getrawchunks(data, chain)
3131 3133
3132 3134 def dodecompress(chunks):
3133 3135 decomp = r.decompress
3134 3136 for chunk in chunks:
3135 3137 decomp(chunk)
3136 3138
3137 3139 def dopatch(text, bins):
3138 3140 if not cache:
3139 3141 r.clearcaches()
3140 3142 mdiff.patches(text, bins)
3141 3143
3142 3144 def dohash(text):
3143 3145 if not cache:
3144 3146 r.clearcaches()
3145 3147 r.checkhash(text, node, rev=rev)
3146 3148
3147 3149 def dorevision():
3148 3150 if not cache:
3149 3151 r.clearcaches()
3150 3152 r.revision(node)
3151 3153
3152 3154 try:
3153 3155 from mercurial.revlogutils.deltas import slicechunk
3154 3156 except ImportError:
3155 3157 slicechunk = getattr(revlog, '_slicechunk', None)
3156 3158
3157 3159 size = r.length(rev)
3158 3160 chain = r._deltachain(rev)[0]
3159 3161 if not getattr(r, '_withsparseread', False):
3160 3162 slicedchain = (chain,)
3161 3163 else:
3162 3164 slicedchain = tuple(slicechunk(r, chain, targetsize=size))
3163 3165 data = [segmentforrevs(seg[0], seg[-1])[1] for seg in slicedchain]
3164 3166 rawchunks = getrawchunks(data, slicedchain)
3165 3167 bins = r._chunks(chain)
3166 3168 text = bytes(bins[0])
3167 3169 bins = bins[1:]
3168 3170 text = mdiff.patches(text, bins)
3169 3171
3170 3172 benches = [
3171 3173 (lambda: dorevision(), b'full'),
3172 3174 (lambda: dodeltachain(rev), b'deltachain'),
3173 3175 (lambda: doread(chain), b'read'),
3174 3176 ]
3175 3177
3176 3178 if getattr(r, '_withsparseread', False):
3177 3179 slicing = (lambda: doslice(r, chain, size), b'slice-sparse-chain')
3178 3180 benches.append(slicing)
3179 3181
3180 3182 benches.extend(
3181 3183 [
3182 3184 (lambda: dorawchunks(data, slicedchain), b'rawchunks'),
3183 3185 (lambda: dodecompress(rawchunks), b'decompress'),
3184 3186 (lambda: dopatch(text, bins), b'patch'),
3185 3187 (lambda: dohash(text), b'hash'),
3186 3188 ]
3187 3189 )
3188 3190
3189 3191 timer, fm = gettimer(ui, opts)
3190 3192 for fn, title in benches:
3191 3193 timer(fn, title=title)
3192 3194 fm.end()
3193 3195
3194 3196
3195 3197 @command(
3196 3198 b'perfrevset',
3197 3199 [
3198 3200 (b'C', b'clear', False, b'clear volatile cache between each call.'),
3199 3201 (b'', b'contexts', False, b'obtain changectx for each revision'),
3200 3202 ]
3201 3203 + formatteropts,
3202 3204 b"REVSET",
3203 3205 )
3204 3206 def perfrevset(ui, repo, expr, clear=False, contexts=False, **opts):
3205 3207 """benchmark the execution time of a revset
3206 3208
3207 3209 Use the --clean option if need to evaluate the impact of build volatile
3208 3210 revisions set cache on the revset execution. Volatile cache hold filtered
3209 3211 and obsolete related cache."""
3210 3212 opts = _byteskwargs(opts)
3211 3213
3212 3214 timer, fm = gettimer(ui, opts)
3213 3215
3214 3216 def d():
3215 3217 if clear:
3216 3218 repo.invalidatevolatilesets()
3217 3219 if contexts:
3218 3220 for ctx in repo.set(expr):
3219 3221 pass
3220 3222 else:
3221 3223 for r in repo.revs(expr):
3222 3224 pass
3223 3225
3224 3226 timer(d)
3225 3227 fm.end()
3226 3228
3227 3229
3228 3230 @command(
3229 3231 b'perfvolatilesets',
3230 3232 [(b'', b'clear-obsstore', False, b'drop obsstore between each call.'),]
3231 3233 + formatteropts,
3232 3234 )
3233 3235 def perfvolatilesets(ui, repo, *names, **opts):
3234 3236 """benchmark the computation of various volatile set
3235 3237
3236 3238 Volatile set computes element related to filtering and obsolescence."""
3237 3239 opts = _byteskwargs(opts)
3238 3240 timer, fm = gettimer(ui, opts)
3239 3241 repo = repo.unfiltered()
3240 3242
3241 3243 def getobs(name):
3242 3244 def d():
3243 3245 repo.invalidatevolatilesets()
3244 3246 if opts[b'clear_obsstore']:
3245 3247 clearfilecache(repo, b'obsstore')
3246 3248 obsolete.getrevs(repo, name)
3247 3249
3248 3250 return d
3249 3251
3250 3252 allobs = sorted(obsolete.cachefuncs)
3251 3253 if names:
3252 3254 allobs = [n for n in allobs if n in names]
3253 3255
3254 3256 for name in allobs:
3255 3257 timer(getobs(name), title=name)
3256 3258
3257 3259 def getfiltered(name):
3258 3260 def d():
3259 3261 repo.invalidatevolatilesets()
3260 3262 if opts[b'clear_obsstore']:
3261 3263 clearfilecache(repo, b'obsstore')
3262 3264 repoview.filterrevs(repo, name)
3263 3265
3264 3266 return d
3265 3267
3266 3268 allfilter = sorted(repoview.filtertable)
3267 3269 if names:
3268 3270 allfilter = [n for n in allfilter if n in names]
3269 3271
3270 3272 for name in allfilter:
3271 3273 timer(getfiltered(name), title=name)
3272 3274 fm.end()
3273 3275
3274 3276
3275 3277 @command(
3276 3278 b'perfbranchmap',
3277 3279 [
3278 3280 (b'f', b'full', False, b'Includes build time of subset'),
3279 3281 (
3280 3282 b'',
3281 3283 b'clear-revbranch',
3282 3284 False,
3283 3285 b'purge the revbranch cache between computation',
3284 3286 ),
3285 3287 ]
3286 3288 + formatteropts,
3287 3289 )
3288 3290 def perfbranchmap(ui, repo, *filternames, **opts):
3289 3291 """benchmark the update of a branchmap
3290 3292
3291 3293 This benchmarks the full repo.branchmap() call with read and write disabled
3292 3294 """
3293 3295 opts = _byteskwargs(opts)
3294 3296 full = opts.get(b"full", False)
3295 3297 clear_revbranch = opts.get(b"clear_revbranch", False)
3296 3298 timer, fm = gettimer(ui, opts)
3297 3299
3298 3300 def getbranchmap(filtername):
3299 3301 """generate a benchmark function for the filtername"""
3300 3302 if filtername is None:
3301 3303 view = repo
3302 3304 else:
3303 3305 view = repo.filtered(filtername)
3304 3306 if util.safehasattr(view._branchcaches, '_per_filter'):
3305 3307 filtered = view._branchcaches._per_filter
3306 3308 else:
3307 3309 # older versions
3308 3310 filtered = view._branchcaches
3309 3311
3310 3312 def d():
3311 3313 if clear_revbranch:
3312 3314 repo.revbranchcache()._clear()
3313 3315 if full:
3314 3316 view._branchcaches.clear()
3315 3317 else:
3316 3318 filtered.pop(filtername, None)
3317 3319 view.branchmap()
3318 3320
3319 3321 return d
3320 3322
3321 3323 # add filter in smaller subset to bigger subset
3322 3324 possiblefilters = set(repoview.filtertable)
3323 3325 if filternames:
3324 3326 possiblefilters &= set(filternames)
3325 3327 subsettable = getbranchmapsubsettable()
3326 3328 allfilters = []
3327 3329 while possiblefilters:
3328 3330 for name in possiblefilters:
3329 3331 subset = subsettable.get(name)
3330 3332 if subset not in possiblefilters:
3331 3333 break
3332 3334 else:
3333 3335 assert False, b'subset cycle %s!' % possiblefilters
3334 3336 allfilters.append(name)
3335 3337 possiblefilters.remove(name)
3336 3338
3337 3339 # warm the cache
3338 3340 if not full:
3339 3341 for name in allfilters:
3340 3342 repo.filtered(name).branchmap()
3341 3343 if not filternames or b'unfiltered' in filternames:
3342 3344 # add unfiltered
3343 3345 allfilters.append(None)
3344 3346
3345 3347 if util.safehasattr(branchmap.branchcache, 'fromfile'):
3346 3348 branchcacheread = safeattrsetter(branchmap.branchcache, b'fromfile')
3347 3349 branchcacheread.set(classmethod(lambda *args: None))
3348 3350 else:
3349 3351 # older versions
3350 3352 branchcacheread = safeattrsetter(branchmap, b'read')
3351 3353 branchcacheread.set(lambda *args: None)
3352 3354 branchcachewrite = safeattrsetter(branchmap.branchcache, b'write')
3353 3355 branchcachewrite.set(lambda *args: None)
3354 3356 try:
3355 3357 for name in allfilters:
3356 3358 printname = name
3357 3359 if name is None:
3358 3360 printname = b'unfiltered'
3359 3361 timer(getbranchmap(name), title=str(printname))
3360 3362 finally:
3361 3363 branchcacheread.restore()
3362 3364 branchcachewrite.restore()
3363 3365 fm.end()
3364 3366
3365 3367
3366 3368 @command(
3367 3369 b'perfbranchmapupdate',
3368 3370 [
3369 3371 (b'', b'base', [], b'subset of revision to start from'),
3370 3372 (b'', b'target', [], b'subset of revision to end with'),
3371 3373 (b'', b'clear-caches', False, b'clear cache between each runs'),
3372 3374 ]
3373 3375 + formatteropts,
3374 3376 )
3375 3377 def perfbranchmapupdate(ui, repo, base=(), target=(), **opts):
3376 3378 """benchmark branchmap update from for <base> revs to <target> revs
3377 3379
3378 3380 If `--clear-caches` is passed, the following items will be reset before
3379 3381 each update:
3380 3382 * the changelog instance and associated indexes
3381 3383 * the rev-branch-cache instance
3382 3384
3383 3385 Examples:
3384 3386
3385 3387 # update for the one last revision
3386 3388 $ hg perfbranchmapupdate --base 'not tip' --target 'tip'
3387 3389
3388 3390 $ update for change coming with a new branch
3389 3391 $ hg perfbranchmapupdate --base 'stable' --target 'default'
3390 3392 """
3391 3393 from mercurial import branchmap
3392 3394 from mercurial import repoview
3393 3395
3394 3396 opts = _byteskwargs(opts)
3395 3397 timer, fm = gettimer(ui, opts)
3396 3398 clearcaches = opts[b'clear_caches']
3397 3399 unfi = repo.unfiltered()
3398 3400 x = [None] # used to pass data between closure
3399 3401
3400 3402 # we use a `list` here to avoid possible side effect from smartset
3401 3403 baserevs = list(scmutil.revrange(repo, base))
3402 3404 targetrevs = list(scmutil.revrange(repo, target))
3403 3405 if not baserevs:
3404 3406 raise error.Abort(b'no revisions selected for --base')
3405 3407 if not targetrevs:
3406 3408 raise error.Abort(b'no revisions selected for --target')
3407 3409
3408 3410 # make sure the target branchmap also contains the one in the base
3409 3411 targetrevs = list(set(baserevs) | set(targetrevs))
3410 3412 targetrevs.sort()
3411 3413
3412 3414 cl = repo.changelog
3413 3415 allbaserevs = list(cl.ancestors(baserevs, inclusive=True))
3414 3416 allbaserevs.sort()
3415 3417 alltargetrevs = frozenset(cl.ancestors(targetrevs, inclusive=True))
3416 3418
3417 3419 newrevs = list(alltargetrevs.difference(allbaserevs))
3418 3420 newrevs.sort()
3419 3421
3420 3422 allrevs = frozenset(unfi.changelog.revs())
3421 3423 basefilterrevs = frozenset(allrevs.difference(allbaserevs))
3422 3424 targetfilterrevs = frozenset(allrevs.difference(alltargetrevs))
3423 3425
3424 3426 def basefilter(repo, visibilityexceptions=None):
3425 3427 return basefilterrevs
3426 3428
3427 3429 def targetfilter(repo, visibilityexceptions=None):
3428 3430 return targetfilterrevs
3429 3431
3430 3432 msg = b'benchmark of branchmap with %d revisions with %d new ones\n'
3431 3433 ui.status(msg % (len(allbaserevs), len(newrevs)))
3432 3434 if targetfilterrevs:
3433 3435 msg = b'(%d revisions still filtered)\n'
3434 3436 ui.status(msg % len(targetfilterrevs))
3435 3437
3436 3438 try:
3437 3439 repoview.filtertable[b'__perf_branchmap_update_base'] = basefilter
3438 3440 repoview.filtertable[b'__perf_branchmap_update_target'] = targetfilter
3439 3441
3440 3442 baserepo = repo.filtered(b'__perf_branchmap_update_base')
3441 3443 targetrepo = repo.filtered(b'__perf_branchmap_update_target')
3442 3444
3443 3445 # try to find an existing branchmap to reuse
3444 3446 subsettable = getbranchmapsubsettable()
3445 3447 candidatefilter = subsettable.get(None)
3446 3448 while candidatefilter is not None:
3447 3449 candidatebm = repo.filtered(candidatefilter).branchmap()
3448 3450 if candidatebm.validfor(baserepo):
3449 3451 filtered = repoview.filterrevs(repo, candidatefilter)
3450 3452 missing = [r for r in allbaserevs if r in filtered]
3451 3453 base = candidatebm.copy()
3452 3454 base.update(baserepo, missing)
3453 3455 break
3454 3456 candidatefilter = subsettable.get(candidatefilter)
3455 3457 else:
3456 3458 # no suitable subset where found
3457 3459 base = branchmap.branchcache()
3458 3460 base.update(baserepo, allbaserevs)
3459 3461
3460 3462 def setup():
3461 3463 x[0] = base.copy()
3462 3464 if clearcaches:
3463 3465 unfi._revbranchcache = None
3464 3466 clearchangelog(repo)
3465 3467
3466 3468 def bench():
3467 3469 x[0].update(targetrepo, newrevs)
3468 3470
3469 3471 timer(bench, setup=setup)
3470 3472 fm.end()
3471 3473 finally:
3472 3474 repoview.filtertable.pop(b'__perf_branchmap_update_base', None)
3473 3475 repoview.filtertable.pop(b'__perf_branchmap_update_target', None)
3474 3476
3475 3477
3476 3478 @command(
3477 3479 b'perfbranchmapload',
3478 3480 [
3479 3481 (b'f', b'filter', b'', b'Specify repoview filter'),
3480 3482 (b'', b'list', False, b'List brachmap filter caches'),
3481 3483 (b'', b'clear-revlogs', False, b'refresh changelog and manifest'),
3482 3484 ]
3483 3485 + formatteropts,
3484 3486 )
3485 3487 def perfbranchmapload(ui, repo, filter=b'', list=False, **opts):
3486 3488 """benchmark reading the branchmap"""
3487 3489 opts = _byteskwargs(opts)
3488 3490 clearrevlogs = opts[b'clear_revlogs']
3489 3491
3490 3492 if list:
3491 3493 for name, kind, st in repo.cachevfs.readdir(stat=True):
3492 3494 if name.startswith(b'branch2'):
3493 3495 filtername = name.partition(b'-')[2] or b'unfiltered'
3494 3496 ui.status(
3495 3497 b'%s - %s\n' % (filtername, util.bytecount(st.st_size))
3496 3498 )
3497 3499 return
3498 3500 if not filter:
3499 3501 filter = None
3500 3502 subsettable = getbranchmapsubsettable()
3501 3503 if filter is None:
3502 3504 repo = repo.unfiltered()
3503 3505 else:
3504 3506 repo = repoview.repoview(repo, filter)
3505 3507
3506 3508 repo.branchmap() # make sure we have a relevant, up to date branchmap
3507 3509
3508 3510 try:
3509 3511 fromfile = branchmap.branchcache.fromfile
3510 3512 except AttributeError:
3511 3513 # older versions
3512 3514 fromfile = branchmap.read
3513 3515
3514 3516 currentfilter = filter
3515 3517 # try once without timer, the filter may not be cached
3516 3518 while fromfile(repo) is None:
3517 3519 currentfilter = subsettable.get(currentfilter)
3518 3520 if currentfilter is None:
3519 3521 raise error.Abort(
3520 3522 b'No branchmap cached for %s repo' % (filter or b'unfiltered')
3521 3523 )
3522 3524 repo = repo.filtered(currentfilter)
3523 3525 timer, fm = gettimer(ui, opts)
3524 3526
3525 3527 def setup():
3526 3528 if clearrevlogs:
3527 3529 clearchangelog(repo)
3528 3530
3529 3531 def bench():
3530 3532 fromfile(repo)
3531 3533
3532 3534 timer(bench, setup=setup)
3533 3535 fm.end()
3534 3536
3535 3537
3536 3538 @command(b'perfloadmarkers')
3537 3539 def perfloadmarkers(ui, repo):
3538 3540 """benchmark the time to parse the on-disk markers for a repo
3539 3541
3540 3542 Result is the number of markers in the repo."""
3541 3543 timer, fm = gettimer(ui)
3542 3544 svfs = getsvfs(repo)
3543 3545 timer(lambda: len(obsolete.obsstore(svfs)))
3544 3546 fm.end()
3545 3547
3546 3548
3547 3549 @command(
3548 3550 b'perflrucachedict',
3549 3551 formatteropts
3550 3552 + [
3551 3553 (b'', b'costlimit', 0, b'maximum total cost of items in cache'),
3552 3554 (b'', b'mincost', 0, b'smallest cost of items in cache'),
3553 3555 (b'', b'maxcost', 100, b'maximum cost of items in cache'),
3554 3556 (b'', b'size', 4, b'size of cache'),
3555 3557 (b'', b'gets', 10000, b'number of key lookups'),
3556 3558 (b'', b'sets', 10000, b'number of key sets'),
3557 3559 (b'', b'mixed', 10000, b'number of mixed mode operations'),
3558 3560 (
3559 3561 b'',
3560 3562 b'mixedgetfreq',
3561 3563 50,
3562 3564 b'frequency of get vs set ops in mixed mode',
3563 3565 ),
3564 3566 ],
3565 3567 norepo=True,
3566 3568 )
3567 3569 def perflrucache(
3568 3570 ui,
3569 3571 mincost=0,
3570 3572 maxcost=100,
3571 3573 costlimit=0,
3572 3574 size=4,
3573 3575 gets=10000,
3574 3576 sets=10000,
3575 3577 mixed=10000,
3576 3578 mixedgetfreq=50,
3577 3579 **opts
3578 3580 ):
3579 3581 opts = _byteskwargs(opts)
3580 3582
3581 3583 def doinit():
3582 3584 for i in _xrange(10000):
3583 3585 util.lrucachedict(size)
3584 3586
3585 3587 costrange = list(range(mincost, maxcost + 1))
3586 3588
3587 3589 values = []
3588 3590 for i in _xrange(size):
3589 3591 values.append(random.randint(0, _maxint))
3590 3592
3591 3593 # Get mode fills the cache and tests raw lookup performance with no
3592 3594 # eviction.
3593 3595 getseq = []
3594 3596 for i in _xrange(gets):
3595 3597 getseq.append(random.choice(values))
3596 3598
3597 3599 def dogets():
3598 3600 d = util.lrucachedict(size)
3599 3601 for v in values:
3600 3602 d[v] = v
3601 3603 for key in getseq:
3602 3604 value = d[key]
3603 3605 value # silence pyflakes warning
3604 3606
3605 3607 def dogetscost():
3606 3608 d = util.lrucachedict(size, maxcost=costlimit)
3607 3609 for i, v in enumerate(values):
3608 3610 d.insert(v, v, cost=costs[i])
3609 3611 for key in getseq:
3610 3612 try:
3611 3613 value = d[key]
3612 3614 value # silence pyflakes warning
3613 3615 except KeyError:
3614 3616 pass
3615 3617
3616 3618 # Set mode tests insertion speed with cache eviction.
3617 3619 setseq = []
3618 3620 costs = []
3619 3621 for i in _xrange(sets):
3620 3622 setseq.append(random.randint(0, _maxint))
3621 3623 costs.append(random.choice(costrange))
3622 3624
3623 3625 def doinserts():
3624 3626 d = util.lrucachedict(size)
3625 3627 for v in setseq:
3626 3628 d.insert(v, v)
3627 3629
3628 3630 def doinsertscost():
3629 3631 d = util.lrucachedict(size, maxcost=costlimit)
3630 3632 for i, v in enumerate(setseq):
3631 3633 d.insert(v, v, cost=costs[i])
3632 3634
3633 3635 def dosets():
3634 3636 d = util.lrucachedict(size)
3635 3637 for v in setseq:
3636 3638 d[v] = v
3637 3639
3638 3640 # Mixed mode randomly performs gets and sets with eviction.
3639 3641 mixedops = []
3640 3642 for i in _xrange(mixed):
3641 3643 r = random.randint(0, 100)
3642 3644 if r < mixedgetfreq:
3643 3645 op = 0
3644 3646 else:
3645 3647 op = 1
3646 3648
3647 3649 mixedops.append(
3648 3650 (op, random.randint(0, size * 2), random.choice(costrange))
3649 3651 )
3650 3652
3651 3653 def domixed():
3652 3654 d = util.lrucachedict(size)
3653 3655
3654 3656 for op, v, cost in mixedops:
3655 3657 if op == 0:
3656 3658 try:
3657 3659 d[v]
3658 3660 except KeyError:
3659 3661 pass
3660 3662 else:
3661 3663 d[v] = v
3662 3664
3663 3665 def domixedcost():
3664 3666 d = util.lrucachedict(size, maxcost=costlimit)
3665 3667
3666 3668 for op, v, cost in mixedops:
3667 3669 if op == 0:
3668 3670 try:
3669 3671 d[v]
3670 3672 except KeyError:
3671 3673 pass
3672 3674 else:
3673 3675 d.insert(v, v, cost=cost)
3674 3676
3675 3677 benches = [
3676 3678 (doinit, b'init'),
3677 3679 ]
3678 3680
3679 3681 if costlimit:
3680 3682 benches.extend(
3681 3683 [
3682 3684 (dogetscost, b'gets w/ cost limit'),
3683 3685 (doinsertscost, b'inserts w/ cost limit'),
3684 3686 (domixedcost, b'mixed w/ cost limit'),
3685 3687 ]
3686 3688 )
3687 3689 else:
3688 3690 benches.extend(
3689 3691 [
3690 3692 (dogets, b'gets'),
3691 3693 (doinserts, b'inserts'),
3692 3694 (dosets, b'sets'),
3693 3695 (domixed, b'mixed'),
3694 3696 ]
3695 3697 )
3696 3698
3697 3699 for fn, title in benches:
3698 3700 timer, fm = gettimer(ui, opts)
3699 3701 timer(fn, title=title)
3700 3702 fm.end()
3701 3703
3702 3704
3703 3705 @command(b'perfwrite', formatteropts)
3704 3706 def perfwrite(ui, repo, **opts):
3705 3707 """microbenchmark ui.write
3706 3708 """
3707 3709 opts = _byteskwargs(opts)
3708 3710
3709 3711 timer, fm = gettimer(ui, opts)
3710 3712
3711 3713 def write():
3712 3714 for i in range(100000):
3713 3715 ui.writenoi18n(b'Testing write performance\n')
3714 3716
3715 3717 timer(write)
3716 3718 fm.end()
3717 3719
3718 3720
3719 3721 def uisetup(ui):
3720 3722 if util.safehasattr(cmdutil, b'openrevlog') and not util.safehasattr(
3721 3723 commands, b'debugrevlogopts'
3722 3724 ):
3723 3725 # for "historical portability":
3724 3726 # In this case, Mercurial should be 1.9 (or a79fea6b3e77) -
3725 3727 # 3.7 (or 5606f7d0d063). Therefore, '--dir' option for
3726 3728 # openrevlog() should cause failure, because it has been
3727 3729 # available since 3.5 (or 49c583ca48c4).
3728 3730 def openrevlog(orig, repo, cmd, file_, opts):
3729 3731 if opts.get(b'dir') and not util.safehasattr(repo, b'dirlog'):
3730 3732 raise error.Abort(
3731 3733 b"This version doesn't support --dir option",
3732 3734 hint=b"use 3.5 or later",
3733 3735 )
3734 3736 return orig(repo, cmd, file_, opts)
3735 3737
3736 3738 extensions.wrapfunction(cmdutil, b'openrevlog', openrevlog)
3737 3739
3738 3740
3739 3741 @command(
3740 3742 b'perfprogress',
3741 3743 formatteropts
3742 3744 + [
3743 3745 (b'', b'topic', b'topic', b'topic for progress messages'),
3744 3746 (b'c', b'total', 1000000, b'total value we are progressing to'),
3745 3747 ],
3746 3748 norepo=True,
3747 3749 )
3748 3750 def perfprogress(ui, topic=None, total=None, **opts):
3749 3751 """printing of progress bars"""
3750 3752 opts = _byteskwargs(opts)
3751 3753
3752 3754 timer, fm = gettimer(ui, opts)
3753 3755
3754 3756 def doprogress():
3755 3757 with ui.makeprogress(topic, total=total) as progress:
3756 3758 for i in _xrange(total):
3757 3759 progress.increment()
3758 3760
3759 3761 timer(doprogress)
3760 3762 fm.end()
General Comments 0
You need to be logged in to leave comments. Login now