##// END OF EJS Templates
phases: large rewrite on retract boundary...
phases: large rewrite on retract boundary The new code is still pure Python, so we still have room to going significantly faster. However its complexity of the complex part is `O(|[min_new_draft, tip]|)` instead of `O(|[min_draft, tip]|` which should help tremendously one repository with old draft (like mercurial-devel or mozilla-try). This is especially useful as the most common "retract boundary" operation happens when we commit/rewrite new drafts or when we push new draft to a non-publishing server. In this case, the smallest new_revs is very close to the tip and there is very few work to do. A few smaller optimisation could be done for these cases and will be introduced in later changesets. We still have iterate over large sets of roots, but this is already a great improvement for a very small amount of work. We gather information on the affected changeset as we go as we can put it to use in the next changesets. This extra data collection might slowdown the `register_new` case a bit, however for register_new, it should not really matters. The set of new nodes is either small, so the impact is negligible, or the set of new nodes is large, and the amount of work to do to had them will dominate the overhead the collecting information in `changed_revs`. As this new code compute the changes on the fly, it unlock other interesting improvement to be done in later changeset.

File last commit:

r49801:642e31cb default
r52302:2f39c7ae default
Show More
lsprofcalltree.py
95 lines | 2.7 KiB | text/x-python | PythonLexer
Nicolas Dumazet
profiling: Adding support for kcachegrind output format, using lsprofcalltree
r8024 """
lsprofcalltree.py - lsprof output which is readable by kcachegrind
Authors:
* David Allouche <david <at> allouche.net>
* Jp Calderone & Itamar Shtull-Trauring
* Johan Dahlin
This software may be used and distributed according to the terms
of the GNU General Public License, incorporated herein by reference.
"""
Gregory Szorc
lsprofcalltree: use absolute_import
r27505
Augie Fackler
formatting: blacken the codebase...
r43346 from . import pycompat
Gregory Szorc
py3: use sysbytes for converting code attributes...
r40231
Nicolas Dumazet
profiling: Adding support for kcachegrind output format, using lsprofcalltree
r8024 def label(code):
if isinstance(code, str):
Gregory Szorc
py3: use sysbytes for converting code attributes...
r40231 # built-in functions ('~' sorts at the end)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'~' + pycompat.sysbytes(code)
Nicolas Dumazet
profiling: Adding support for kcachegrind output format, using lsprofcalltree
r8024 else:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 return b'%s %s:%d' % (
Augie Fackler
formatting: blacken the codebase...
r43346 pycompat.sysbytes(code.co_name),
pycompat.sysbytes(code.co_filename),
code.co_firstlineno,
)
Nicolas Dumazet
profiling: Adding support for kcachegrind output format, using lsprofcalltree
r8024
Gregory Szorc
py3: use class X: instead of class X(object):...
r49801 class KCacheGrind:
Nicolas Dumazet
profiling: Adding support for kcachegrind output format, using lsprofcalltree
r8024 def __init__(self, profiler):
self.data = profiler.getstats()
self.out_file = None
def output(self, out_file):
self.out_file = out_file
Gregory Szorc
py3: use write() instead of print()...
r40230 out_file.write(b'events: Ticks\n')
Nicolas Dumazet
profiling: Adding support for kcachegrind output format, using lsprofcalltree
r8024 self._print_summary()
for entry in self.data:
self._entry(entry)
def _print_summary(self):
max_cost = 0
for entry in self.data:
totaltime = int(entry.totaltime * 1000)
max_cost = max(max_cost, totaltime)
Gregory Szorc
py3: use write() instead of print()...
r40230 self.out_file.write(b'summary: %d\n' % max_cost)
Nicolas Dumazet
profiling: Adding support for kcachegrind output format, using lsprofcalltree
r8024
def _entry(self, entry):
out_file = self.out_file
code = entry.code
if isinstance(code, str):
Gregory Szorc
py3: use write() instead of print()...
r40230 out_file.write(b'fi=~\n')
Nicolas Dumazet
profiling: Adding support for kcachegrind output format, using lsprofcalltree
r8024 else:
Gregory Szorc
py3: use sysbytes for converting code attributes...
r40231 out_file.write(b'fi=%s\n' % pycompat.sysbytes(code.co_filename))
Gregory Szorc
py3: use write() instead of print()...
r40230
out_file.write(b'fn=%s\n' % label(code))
Nicolas Dumazet
profiling: Adding support for kcachegrind output format, using lsprofcalltree
r8024
inlinetime = int(entry.inlinetime * 1000)
if isinstance(code, str):
Gregory Szorc
py3: use write() instead of print()...
r40230 out_file.write(b'0 %d\n' % inlinetime)
Nicolas Dumazet
profiling: Adding support for kcachegrind output format, using lsprofcalltree
r8024 else:
Gregory Szorc
py3: use write() instead of print()...
r40230 out_file.write(b'%d %d\n' % (code.co_firstlineno, inlinetime))
Nicolas Dumazet
profiling: Adding support for kcachegrind output format, using lsprofcalltree
r8024
# recursive calls are counted in entry.calls
if entry.calls:
calls = entry.calls
else:
calls = []
if isinstance(code, str):
lineno = 0
else:
lineno = code.co_firstlineno
for subentry in calls:
self._subentry(lineno, subentry)
Gregory Szorc
py3: use write() instead of print()...
r40230
out_file.write(b'\n')
Nicolas Dumazet
profiling: Adding support for kcachegrind output format, using lsprofcalltree
r8024
def _subentry(self, lineno, subentry):
out_file = self.out_file
code = subentry.code
Gregory Szorc
py3: use write() instead of print()...
r40230 out_file.write(b'cfn=%s\n' % label(code))
Nicolas Dumazet
profiling: Adding support for kcachegrind output format, using lsprofcalltree
r8024 if isinstance(code, str):
Gregory Szorc
py3: use write() instead of print()...
r40230 out_file.write(b'cfi=~\n')
out_file.write(b'calls=%d 0\n' % subentry.callcount)
Nicolas Dumazet
profiling: Adding support for kcachegrind output format, using lsprofcalltree
r8024 else:
Gregory Szorc
py3: use sysbytes for converting code attributes...
r40231 out_file.write(b'cfi=%s\n' % pycompat.sysbytes(code.co_filename))
Augie Fackler
formatting: blacken the codebase...
r43346 out_file.write(
b'calls=%d %d\n' % (subentry.callcount, code.co_firstlineno)
)
Nicolas Dumazet
profiling: Adding support for kcachegrind output format, using lsprofcalltree
r8024
totaltime = int(subentry.totaltime * 1000)
Gregory Szorc
py3: use write() instead of print()...
r40230 out_file.write(b'%d %d\n' % (lineno, totaltime))