Mercurial > hg
comparison contrib/perf.py @ 40977:21a9cace4bbf
perfrevflogwrite: clear revlog cache between each write
We want to measure write time from a cold cache (similar to commit). So we
need to clear the cache to prevent computation from rev N-1 to interfere with
rev N.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Mon, 17 Dec 2018 10:37:22 +0100 |
parents | 74ee5ff1e81c |
children | e88ced97151d |
comparison
equal
deleted
inserted
replaced
40976:ef7119cd4965 | 40977:21a9cace4bbf |
---|---|
1720 (b'', b'stoprev', -1, b'last revision to write'), | 1720 (b'', b'stoprev', -1, b'last revision to write'), |
1721 (b'', b'count', 3, b'last revision to write'), | 1721 (b'', b'count', 3, b'last revision to write'), |
1722 (b'', b'details', False, b'print timing for every revisions tested'), | 1722 (b'', b'details', False, b'print timing for every revisions tested'), |
1723 (b'', b'source', b'full', b'the kind of data feed in the revlog'), | 1723 (b'', b'source', b'full', b'the kind of data feed in the revlog'), |
1724 (b'', b'lazydeltabase', True, b'try the provided delta first'), | 1724 (b'', b'lazydeltabase', True, b'try the provided delta first'), |
1725 (b'', b'clear-caches', True, b'clear revlog cache between calls'), | |
1725 ], | 1726 ], |
1726 b'-c|-m|FILE') | 1727 b'-c|-m|FILE') |
1727 def perfrevlogwrite(ui, repo, file_=None, startrev=1000, stoprev=-1, **opts): | 1728 def perfrevlogwrite(ui, repo, file_=None, startrev=1000, stoprev=-1, **opts): |
1728 """Benchmark writing a series of revisions to a revlog. | 1729 """Benchmark writing a series of revisions to a revlog. |
1729 | 1730 |
1744 if stoprev < 0: | 1745 if stoprev < 0: |
1745 stoprev = rllen + stoprev | 1746 stoprev = rllen + stoprev |
1746 | 1747 |
1747 lazydeltabase = opts['lazydeltabase'] | 1748 lazydeltabase = opts['lazydeltabase'] |
1748 source = opts['source'] | 1749 source = opts['source'] |
1750 clearcaches = opts['clear_cache'] | |
1749 validsource = (b'full', b'parent-1', b'parent-2', b'parent-smallest', | 1751 validsource = (b'full', b'parent-1', b'parent-2', b'parent-smallest', |
1750 b'storage') | 1752 b'storage') |
1751 if source not in validsource: | 1753 if source not in validsource: |
1752 raise error.Abort('invalid source type: %s' % source) | 1754 raise error.Abort('invalid source type: %s' % source) |
1753 | 1755 |
1756 if count <= 0: | 1758 if count <= 0: |
1757 raise error.Abort('invalide run count: %d' % count) | 1759 raise error.Abort('invalide run count: %d' % count) |
1758 allresults = [] | 1760 allresults = [] |
1759 for c in range(count): | 1761 for c in range(count): |
1760 timing = _timeonewrite(ui, rl, source, startrev, stoprev, c + 1, | 1762 timing = _timeonewrite(ui, rl, source, startrev, stoprev, c + 1, |
1761 lazydeltabase=lazydeltabase) | 1763 lazydeltabase=lazydeltabase, |
1764 clearcaches=clearcaches) | |
1762 allresults.append(timing) | 1765 allresults.append(timing) |
1763 | 1766 |
1764 ### consolidate the results in a single list | 1767 ### consolidate the results in a single list |
1765 results = [] | 1768 results = [] |
1766 for idx, (rev, t) in enumerate(allresults[0]): | 1769 for idx, (rev, t) in enumerate(allresults[0]): |
1823 class _faketr(object): | 1826 class _faketr(object): |
1824 def add(s, x, y, z=None): | 1827 def add(s, x, y, z=None): |
1825 return None | 1828 return None |
1826 | 1829 |
1827 def _timeonewrite(ui, orig, source, startrev, stoprev, runidx=None, | 1830 def _timeonewrite(ui, orig, source, startrev, stoprev, runidx=None, |
1828 lazydeltabase=True): | 1831 lazydeltabase=True, clearcaches=True): |
1829 timings = [] | 1832 timings = [] |
1830 tr = _faketr() | 1833 tr = _faketr() |
1831 with _temprevlog(ui, orig, startrev) as dest: | 1834 with _temprevlog(ui, orig, startrev) as dest: |
1832 dest._lazydeltabase = lazydeltabase | 1835 dest._lazydeltabase = lazydeltabase |
1833 revs = list(orig.revs(startrev, stoprev)) | 1836 revs = list(orig.revs(startrev, stoprev)) |
1836 if runidx is not None: | 1839 if runidx is not None: |
1837 topic += ' (run #%d)' % runidx | 1840 topic += ' (run #%d)' % runidx |
1838 for idx, rev in enumerate(revs): | 1841 for idx, rev in enumerate(revs): |
1839 ui.progress(topic, idx, unit='revs', total=total) | 1842 ui.progress(topic, idx, unit='revs', total=total) |
1840 addargs, addkwargs = _getrevisionseed(orig, rev, tr, source) | 1843 addargs, addkwargs = _getrevisionseed(orig, rev, tr, source) |
1844 if clearcaches: | |
1845 dest.index.clearcaches() | |
1846 dest.clearcaches() | |
1841 with timeone() as r: | 1847 with timeone() as r: |
1842 dest.addrawrevision(*addargs, **addkwargs) | 1848 dest.addrawrevision(*addargs, **addkwargs) |
1843 timings.append((rev, r[0])) | 1849 timings.append((rev, r[0])) |
1844 ui.progress(topic, total, unit='revs', total=total) | 1850 ui.progress(topic, total, unit='revs', total=total) |
1845 ui.progress(topic, None, unit='revs', total=total) | 1851 ui.progress(topic, None, unit='revs', total=total) |